solving a nonlinear equation faster

4 ビュー (過去 30 日間)
ektor
ektor 2017 年 11 月 8 日
コメント済み: Walter Roberson 2017 年 11 月 8 日
Dear all,
I want to solve this equation
-0.5+ 0.5*a*exp(-x-b*c) -(x-d)/e=0
where a,b,c,d are known quantities that change in each iteration of the algorithm.
So, I use the following code
x0=1;
Myfun = @(x, a, b, c,d,e) -0.5+ 0.5*a*exp(-x-b*c) -(x-d)/e;
A=fzero(@(x)Myfun(x, a, b, c,d,e),x0);
However, I noticed that this code is slow. So I tried something like
ff=0;
while abs(ff) > 0.0001
ff= -0.5+ 0.5*a*exp(-x-b*c) -(x-d)/e;
g=-0.5*a*exp(-x-b*c) -1/e ;
x = x - ff/g;
end
where g is the first derivative of the main function ff.
But I do not get similar solutions. Do you thing that the second piece of code is wrong?

採用された回答

Walter Roberson
Walter Roberson 2017 年 11 月 8 日
It has an exact solution:
lambertw((1/2)*a*e*exp(-b*c-d+(1/2)*e))+d-(1/2)*e
You will need the Symbolic Toolbox for lambertw
  2 件のコメント
ektor
ektor 2017 年 11 月 8 日
It is extremely slow in my code
Walter Roberson
Walter Roberson 2017 年 11 月 8 日
On my system, with numeric a, b, c, d, e, it takes about 6E-5 seconds each, which is very reasonable.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumeric Solvers についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by