Effacer les filtres
Effacer les filtres

I have problem to make code of deflection of beam

2 vues (au cours des 30 derniers jours)
minji park
minji park le 20 Mai 2015
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

Réponses (1)

Joseph Cheng
Joseph Cheng le 20 Mai 2015
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.

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by