length = 31 ;
while length < 0
length = input('enter a value greater than 0:')
end
pounds = 26905;
elasticity = 45941267 ;
width = 4.3
while width < 0
width = input('enter a value greater than 0:')
end
height = 1.2
while height < 0
height = input('enter a value greater than 0:');
end
I = (width*height^3)/12;
a = linspace(1,200)';
b = length - a ;
if a >= 0
maximum = (-pounds*b(length.^2-(b.^2))^(3/2))/(9*sqrt(3)*elasticity*I*length)'
elseif b >= 0
maximum = (-pounds*a(length.^2-(a.^2))^(3/2))/(9*sqrt(3)*elasticity*I*length)'
end 它发生在下面这一行:
maximum = (-pounds*b(length.^2-(b.^2))^(3/2))/(9*sqrt(3)*elasticity*I*length)'我需要我的代码来输出这些数字,这样我就可以在表格中打印它们,并完成我的代码。
发布于 2015-10-22 10:24:20
正如@rayryeng所说的,你所遇到的问题是你正在索引到b。
如果你检查一下length^2 - (b.^2),你会得到:
61 120 177 232 285 336 385 432 477 520
561 600 637 672 705 736 765 792 817 840
861 880 897 912 925 936 945 952 957 960
961 960 957 952 945 936 925 912 897 880
861 840 817 792 765 736 705 672 637 600
561 520 477 432 385 336 285 232 177 120
61 0 -63 -128 -195 -264 -335 -408 -483 -560
... snipped第四个值是:232,它大于b的长度(本例中为200)。这会触发第一个错误,但即使您能够继续,您最终也会得到负值(对于索引!另一个错误)
https://stackoverflow.com/questions/33272154
复制相似问题