Storing values in a matrix from 2 for loops
Afficher commentaires plus anciens
First I'll post my code then explain
P=100;
E=1.5*10^6;
b=3.375;
d=1.5;
I=(1/12)*b*d^3;
L=20;
a=10;
for x1=0:.2:a
y1=((-P*x1)/6*E*I)*(1-(a/L))*((2*a*L)-(a^2)-(x1^2));
end
for x2=a+.2:.2:L
y2=((-P*a)/(6*E*I))*(1-(x2/L))*((2*x2*L)-(a^2)-(x2^2));
end
Now with this code i get 51 values from y1 and 50 values from y2. I need these to be stored in a 1 x 101 matrix. How can this be done?
Réponses (2)
Paulo Silva
le 14 Avr 2011
P=100;
E=1.5*10^6;
b=3.375;
d=1.5;
I=(1/12)*b*d^3;
L=20;
a=10;
y11=[];
y21=[];
for x1=0:.2:a
y1=((-P*x1)/6*E*I)*(1-(a/L))*((2*a*L)-(a^2)-(x1^2));
y11=[y11 y1];
end
for x2=a+.2:.2:L
y2=((-P*a)/(6*E*I))*(1-(x2/L))*((2*x2*L)-(a^2)-(x2^2));
y21=[y21 y2];
end
yf=[y11 y21]
%yf is your response, 1x101 it's a vector not a matrix
1 commentaire
Brian
le 14 Avr 2011
Andrei Bobrov
le 14 Avr 2011
variant
P=100;
E=1.5*10^6;
b=3.375;
d=1.5;
I=(1/12)*b*d^3;
L=20;
a=10;
x1=0:.2:a;
x2=a+.2:.2:L;
f=@(X,Y,Z)((-P*X)/(6*E*I)).*(1-(Y/L)).*((2*Y*L)-(a^2)-(Z.^2));
count = [f([x1,a,x1), f(a,x2,x2)]
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!