Info

This question is closed. Reopen it to edit or answer.

problem in if loop

1 view (last 30 days)
Jeevan Patil
Jeevan Patil on 6 Mar 2012
Closed: MATLAB Answer Bot on 20 Aug 2021
Dear friends, I want to program following equation. when x1>a1 & x2>a2 F1 = -P21*Apb+Pa*Apt - Fpi - Ff1;
F2 = -P21*Apvt + P11*Apvb - Fpvi - Ff2;
F3 = P13*Ast - P22*Asb - Fsi - Ff3;
F4 = -P12*Asvb+P22*Asvt-Fsvi-Ff4;
when x1>a1 & x2<=a2
F1 = -P21*Apb+Pa*Apt - Fpi - Ff1;
F2 = -P21*Apvt + P11*Apvb - Fpvi - Ff2;
F3 = P13*Ast - P22*Asb - Fsi - Ff3;
F4 = -P12*Asvb+P22*Asvt-Fsvi; % when x1<=a1 x2<=0
F1 = -P21*Apb+Pa*Apt - Fpi - Ff1;
F2 = -P21*Apvt + P11*Apvb - Fpvi;
F3 = P13*Ast - P22*Asb - Fsi;
F4 = -P12*Asvb+P22*Asvt-Fsvi;
Below given is my matlab script. in this i am not able to figure out why the out put of this program is contact when t is varying from 0 to 10.
t = 0:0.01:10; x1 = 13*sin(t); x2 = 13*sin(t);
for i = 1:length(t);
if x1<=a1 & x2<=0
F1(i) = -P21*Apb+Pa*Apt - Fpi - Ff1;
F2(i) = -P21*Apvt + P11*Apvb - Fpvi;
F3(i) = P13*Ast - P22*Asb - Fsi;
F4(i) = -P12*Asvb+P22*Asvt-Fsvi;
elseif x1>a1 & x2<=a2
F1(i) = -P21*Apb+Pa*Apt - Fpi - Ff1;
F2(i) = -P21*Apvt + P11*Apvb - Fpvi - Ff2;
F3(i) = P13*Ast - P22*Asb - Fsi - Ff3;
F4(i) = -P12*Asvb+P22*Asvt-Fsvi; elseif x1>a1 & x2>a2
F1(i) = -P21*Apb+Pa*Apt - Fpi - Ff1;
F2(i) = -P21*Apvt + P11*Apvb - Fpvi - Ff2;
F3(i) = P13*Ast - P22*Asb - Fsi - Ff3;
F4(i) = -P12*Asvb+P22*Asvt-Fsvi-Ff4; end end
  1 Comment
Walter Roberson
Walter Roberson on 6 Mar 2012
There is no such thing as an "if loop". "if" is a sequential control statement, and the body of an "if" is executed only once, not in a loop.

Answers (0)

This question is closed.

Tags

Community Treasure Hunt

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

Start Hunting!