Sttopping the iteration at a certain value

HI!
I have a vector length of 0:0.1:1 and ineed iteration according to this vector length. I have done this part now i need to stop these iteration when valuee of r becomes positive but it doesnt work what should i do.Hve a look on this code.I need the loop to break when real part of poles that is r (any of three values in vectoor) becomes +ive but it doesn;t work.The condition work perfectly for r<0 condition but not for this.plzz help
for k= 0:0.1:1
n=conv(k,[0.5 1.3]);
d=[1 1.2 1.6 0];
sys1=tf(num1,den);
P=pole(F);
r=real(P)
if r>0
break
end
end

 채택된 답변

Star Strider
Star Strider 2020년 5월 16일

0 개 추천

The ‘F’ variable is apparently defined before the loop and does not appear to be changed within the loop. Therefore, ‘r’ never changes and the if condition is never satisfied.

댓글 수: 8

But if i do that then the systen won't know what r is .
and it works for following condition
if r<0
break
end
Star Strider
Star Strider 2020년 5월 16일
The point is that ‘F’ is not calculated within the loop and so by definition never changes within the loop, and so ‘r’ never changes within the loop. If before the loop, it will remain so within the loop.
Tina
Tina 2020년 5월 16일
편집: Tina 2020년 5월 16일
for k=1:0.1:2
n=conv(k,[0.5 1.3]);
d=[1 1.2 1.6 0];
sys1=tf(num1,den)
if r>0
F=feedback( sys1,1); P=pole(F);
r=real(P)
break
end
end
if this is what you are talking about,then the matlab doesnt respond and code doesn.t work
Star Strider
Star Strider 2020년 5월 16일
That is significantly different from the code you originally posted!
There is not enough information provided to run this code as well.
The order of the statements appears to test ‘r’ before it is calculated. Assuming ‘r’ is defined somewhere prior to the loop, it would test on the preceeding value of ‘F’ and output the subsequent value of ‘F’.
It could very easily be that your system is causal and stable and all the poles remain in the left-half plane, so the test will always fail.
Tina
Tina 2020년 5월 16일
편집: Tina 2020년 5월 16일
for k=2:0.1:3
n=conv(k,[0.5 1.3]);
d=[1 1.2 1.6 0];
sys1=tf(1,d)
F=feedback( sys1,1)
P=pole(F);
r=real(P)
if r<0
else
break
end
So this is the code to find the stability of transfer function with the increase of k values.So when I use the code ,it works but it still dispay the values when the system become unstable and then breaks.Like now it's only displaying the value at which it become unstable .is it possible that it doesn't even show that one value too?
The earlier if block made more sense.
It should show all the ‘F’ systems until it breaks. (It isn’t configured to store any of them, however.)
If you want to save them to use later, try this:
k=2:0.1:3;
for kk = 1:numel(k)
n=conv(k(kk),[0.5 1.3]);
d=[1 1.2 1.6 0];
sys1=tf(1,d)
F=feedback( sys1,1)
Fsave{kk} = F;
P=pole(F);
r=real(P)
if r>0
break
end
end
I’m still not certain what the problem is.
Tina
Tina 2020년 5월 16일
OK THANKS
Star Strider
Star Strider 2020년 5월 16일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

제품

릴리스

R2014a

태그

질문:

2020년 5월 16일

댓글:

2020년 5월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by