I have problem to make code of deflection of beam

2 次查看(过去 30 天)
I got this error, 'The variable 'y' appears to change size on every loop iteration. Consider preallocating for speed. please help me ...
function beam()
E = 210* 10^9;
L = 1;
W0= 4000;
I = (0.05 * 0.12^3) / 12;
x=linspace(0,1,101);
for i=1:101
if x(i) < 0.5
y(i) = ((W0* L)/(4 * E * I)) * x(i)^2 - (W0/( 6 * E* I))* x(i)^3;
else
y(i) = ((W0*L)/(4 * E * I)) * x(i)^2 - (W0 / (6 * E * I)) * x(i)^3 + (W0 / (6 *E * I))*(x(i)- L/2)^3;
end
end
plot(x,y);
grid off;
end
Thanks

回答(1 个)

Joseph Cheng
Joseph Cheng 2015-5-20
That is not an error. It is a warning. which based on the size of your function and number of iterations should not be an issue. It is saying if y will grow significantly large it may take some time to add additional data to it unless you pre-allocate the array.

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

尚未输入任何标签。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by