How can I correctly use consecutive numbers in a iteration?

1 回表示 (過去 30 日間)
gblmtc
gblmtc 2018 年 4 月 4 日
コメント済み: gblmtc 2018 年 4 月 5 日
Hi there!
I have this formula : Ek = mk + e*sin(ek). I know 'mk' and I know 'e'.
To find out the value of Ek I have to use iteration, that's what my teacher told me.
He said :
#1 ek = mk that means e1 = mk + e*sin(ek)
#2 e2 = mk + e*sin(e1)
#3 e3 = mk +e*sin(e2)
It must stop when ei+1-ei>tolerance (tolerance = 10^-12).
That,s what I did but it is not working :(.
ia=10^-11;
tol=10^-12;
ek=mk;
while ia>tol
ei+1-ei>tol;
e1=mk+e*sin(mk);
e2=mk+e*sin(e1);
ei+1=mk+e*sin(ei); %The expression to the left of the equals sign is not a valid target for an assignment
That's the error I get at the end.
Thanking you!

採用された回答

CARLOS RIASCOS
CARLOS RIASCOS 2018 年 4 月 4 日
Hello friend, I did this for you, I hope it helps you.
Note: Change the values of the variables mk and e to the values that you say already have.
clear all
mk=0.01;
e=0.5;
i=1;
ek(i) = mk;
tol=10e-12;
ia = 10e-11;
while abs(ia) > tol
ek(i+1) = mk + e*sin(ek(i));
ia= ek(i+1) - ek(i);
i=i+1;
end
disp('End value of ek:')
disp(ek(end))
  1 件のコメント
gblmtc
gblmtc 2018 年 4 月 5 日
Hei!
Thank you very much, Carlos!!
It works perfectly!!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTwo y-axis についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by