Are there two conditions at once when using the if condition?
1 view (last 30 days)
Show older comments
Hello. I have a question and am posting.
I solved it as below, but the value I want is not found, so I ask. Q_1 is entered only when tact is 1 and k is 1, and I am trying to calculate the rest by putting the rest in the expression.
So, when tact is 1 and k is 1, can't we just put the value of Q_1?? For the rest, I try to use the formula below.
Q_1 = 30;
Q_D = 11.3;
Q_E = 8.3;
Q_R = 7.5;
Q_F = 4.5;
connection_D = [1,0,0,0; 0,1,0,0; 0,0,1,0; 0,0,0,1];
connection_E = [0,1,0,0; 0,0,1,0; 0,0,0,1; 1,0,0,0];
connection_F = [0,0,1,0; 0,0,0,1; 1,0,0,0; 0,1,0,0];
connection_R = [0,0,0,1; 1,0,0,0; 0,1,0,0; 0,0,1,0];
for tact = 1:4
for k=1:4
if k==1
Q_column(1)=Q_1
else
Q_column(k) = Q_column(k-1) + Q_D*connection_D(tact,k) - Q_E*connection_E(tact,k) + Q_F*connection_F(tact,k) - Q_R*connection_R(tact,k)
end
end
end
1 Comment
Answers (1)
Prince Kumar
on 25 Jan 2022
Hi,
Q_1 = 30;
Q_D = 11.3;
Q_E = 8.3;
Q_R = 7.5;
Q_F = 4.5;
connection_D = [1,0,0,0; 0,1,0,0; 0,0,1,0; 0,0,0,1];
connection_E = [0,1,0,0; 0,0,1,0; 0,0,0,1; 1,0,0,0];
connection_F = [0,0,1,0; 0,0,0,1; 1,0,0,0; 0,1,0,0];
connection_R = [0,0,0,1; 1,0,0,0; 0,1,0,0; 0,0,1,0];
for tact = 1:4
for k=1:4
if k==1 & tact == 1
Q_column(1)=Q_1
else
Q_column(k) = Q_column(k-1) + Q_D*connection_D(tact,k) - Q_E*connection_E(tact,k) + Q_F*connection_F(tact,k) - Q_R*connection_R(tact,k)
end
end
end
You can use any combination of operators as per your need.
Hope this helps.
0 Comments
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!