need help finding convergence

1 回表示 (過去 30 日間)
Tony Montgomery
Tony Montgomery 2014 年 9 月 19 日
回答済み: Tony Montgomery 2014 年 9 月 20 日
I have the following equation in matlab g1=@(x) tan(exp(x/20)) now I need to run this until I get two consecutive approximations to the root are close enough or divergence is determined. here is how i'm in iterating n=0; a=1; n=n+1; x1(n)=g1(a); a=x1(n); now this does work and I can run it, but i can't make the loop until i know how to find the error between xold and xnew. So my question is how to i make this so the equation is in the form xnew=g(xold)?

採用された回答

Mischa Kim
Mischa Kim 2014 年 9 月 20 日
編集済み: Mischa Kim 2014 年 9 月 20 日
Tony, this should get you started:
g = @(x) tan(exp(x/20));
my_tol = 1e-5;
x = 1;
dx = x;
x_iter = x;
while dx > my_tol
x_new = g(x);
dx = abs(x - x_new)
x = x_new;
x_iter = [x_iter x];
end

その他の回答 (1 件)

Tony Montgomery
Tony Montgomery 2014 年 9 月 20 日
Thank you. THANK you. THANK YOU!! I'm not very good at this stuff yet. Thanks for the help I will dry it!!

カテゴリ

Help Center および File ExchangeMathematics and Optimization についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by