function within nested for loop

so i got this code to find the solution for Th3 and Th4. then plot them versus Th2 . but, I couldn't run it because there are many errors. any suggetions to edit?
function F = Aamna_fun1(x)
Th3 = x(1);
Th4 = x(2);
global b c r Z
F(1) = real(b*exp(1i*Th3)-c*exp(1i*Th4)+r*Th4-Z);
F(2) = imag(b*exp(1i*Th3)-c*exp(1i*Th4)+r*Th4-Z)
Th2= 90 : (360+90);
for e= 2:length(Th2);
global b c r Z
a=2;
b=8;
c=2;
r=4;
d0=6.92;
ap=6;
Th1=0;
Th5=90;
Z = d0 +r*pi/2+r*1i-a*exp(1i*Th2);
x0 = [0 0];
Sol = fsolve(@Aamna_fun1,x0);
Th3s = rad2deg(Sol(1))
Th4s = rad2deg(Sol(2))
for x0 = [Th3s(e-1) Th4s(e-1)]
Th3s(:,e+1) = [rad2deg(Sol(1))]
Th4s(:,e+1) = [rad2deg(Sol(2))]
end;
end;
Th2 = 90:360+90;
figure(1)
plot (Th2,Th3(1,:));
xlabel ('TH2')
ylabel ('TH3')
figure(2)
plot (Th2,Th4(1,:));
xlabel ('TH2') ;
ylabel ('TH4') ;

3 件のコメント

Jos (10584)
Jos (10584) 2019 年 10 月 17 日
First add a lot of comments. Code without comments is useless ...
Then check if each line does what you expect it to do, using the excellent debug tools available in matlab. Take a close look at the error messages too.
Aamna Alshehhi
Aamna Alshehhi 2019 年 10 月 17 日
well, that's right but the problem is that i don't know how to write the right nested for loop. I just wanna find Th3 and Th4 values from the function that i l already wrote , then plot Th3s vs Th2 and Th43 vs Th2.
Fabio Freschi
Fabio Freschi 2019 年 10 月 17 日
As Jos said, have a look at this:
you will be able to check your code line by line. Without any insight on the program (and with no comments at all) it is difficult to help

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2019 年 10 月 17 日

コメント済み:

2019 年 10 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by