how to create (for) loop for a matrix

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 Comments

What is n, c, & e in your hand drawn equation? What is the last term in the Q equations that looks like a 9 in strikeout text with a numerical subscript? Why is M not included in your computation of the Q? Do you just want a manual way of doing a matrix multiplication instead of the usual
Q = M * P
pejhan stiff
pejhan stiff on 3 Jan 2021
Edited: pejhan stiff on 3 Jan 2021
n is the time step that should be 360
i think you read (c+e) instead of cte
i have a variable named cte :D
and Q1=-(cte )* P1(i)-q(1)
...
Q8=-(cte )* P1(i)-q(1)
P1(1)=P2(1)=...=P9(1)=5000
and yes i want to do a matrix instead of the usual
Note: if you want help, then you need to make it easy to be helped.

Sign in to comment.

Answers (0)

Categories

Asked:

on 2 Jan 2021

Commented:

on 3 Jan 2021

Community Treasure Hunt

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

Start Hunting!