how to create (for) loop for a matrix
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
hi every body im a beginner in matlab
i have create a matrix name (M) and my question is in the attachments:
i want to find out 360 values for each p1,...,p8
but i dont know how to create the loop for this question
here is my code :
dt=1 ;V=1000*1000*100 ; pro=0.15 ; Co=10^-6 ; alpha =5.615; Bo=1.35;
beta =1.127 ;Ax=1000*100 ; mio=1 ;Dx=1000;Kx=20*10^-3;
cte=(V*pro*Co)/(alpha*Bo*dt);
%%wi=T(i-(1/2))
T=(beta * Ax* Kx)/(mio *Bo*Dx);
W(1)=0;
for i=2:1:8;
W(i)=T;
end
C(8)=-(T+cte);
for j=1:1:7;
C(j)=-(2*T+cte);
end
%%Ei=Txi+1/2
for k=1:1:7;
E(k)=T;
end
M = [C(1), E(1), 0, 0, 0, 0, 0, 0;
W(2), C(2), E(2), 0, 0, 0, 0, 0;
0, W(3), C(3), E(3), 0, 0, 0, 0;
0, 0, W(4), C(4), E(4), 0, 0, 0;
0, 0, 0, W(5), C(5), E(5), 0, 0;
0, 0, 0, 0, W(6), C(6), E(6), 0;
0, 0, 0, 0, 0, W(7), C(7), E(7);
0, 0, 0, 0, 0, 0, W(8), C(8)];
%Qi=-(cte)Pi(i)-q(i)
p1(1) = 5000;p3(1) = 5000;p5(1)= 5000;p7(1) = 5000;
p2(1) = 5000;p4(1) = 5000;p6(1) = 5000;p8(1) = 5000;
q(1)=0;q(2)=0;q(3)=-250;q(4)=0;
q(5)=0;q(6)=0;q(7)=-250;q(8)=0;
for I=1:1:360;
Q=[-(cte)*p1(I)-q(1) ;-(cte)*p2(I)-q(2) ;-(cte)*p3(I)-q(3);-(cte)*p4(I)-q(4);
-(cte)*p5(I)-q(5) ;-(cte)*p6(I)-q(6) ;-(cte)*p1(I)-q(7);-(cte)*p8(I)-q(8)];
mat=[inv(M) * Q];
p1(I+1)=mat(1,I);p3(I+1)=mat(3,I);p5(I+1)=mat(5,I);p7(I+1)=mat(7,I);
p2(I+1)=mat(2,I);p4(I+1)=mat(4,I);p6(I+1)=mat(6,I);p8(I+1)=mat(8,I);
end
4 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!