How to find the roots of the equraion f(x)=sin[sin(x)]+e^x=0

35 vues (au cours des 30 derniers jours)
A
A le 8 Oct 2020
Commenté : Ameer Hamza le 8 Oct 2020
What is the process for finding roots for this equation?
f(x)=sin[sin(x)]+e^x=0

Réponses (2)

Ameer Hamza
Ameer Hamza le 8 Oct 2020
Modifié(e) : Ameer Hamza le 8 Oct 2020
f = @(x) sin(sin(x))+exp(x);
x0 = 0; % initial guess
x_sol = fzero(f, x0);
Result
>> x_sol
x_sol =
-0.6111
  4 commentaires
John D'Errico
John D'Errico le 8 Oct 2020
Note that my answer is purely an aside to what Ameer has already explained. (I should have made it a comment, but I am too lazy to change that now.) I suggest you accept his answer here, as it was correct and helped you.
Ameer Hamza
Ameer Hamza le 8 Oct 2020
Thanks, John! The OP later posted a question explicitly asking about multiple solutions. The information in your answer is also appropriate for that question.

Connectez-vous pour commenter.


John D'Errico
John D'Errico le 8 Oct 2020
Modifié(e) : John D'Errico le 8 Oct 2020
The simple answer is to know MATLAB syntax, and understand how to use a tool like fzero. So sin[sin(x)] may look better to you, but it is invalid syntax in MATLAB. And e^x is now how we write the exponential function in MATLAB. @Ameer has ably shown those facts, as well as how to use fzero.
But there is more to this question than may meet the eye. (Often true.)
f = @(x) sin(sin(x))+exp(x);
fplot(f,[-20,2])
yline(0,'r');
Do you see anything of interest? It appears as if there are many roots. Infinitely many of them, in fact. I expect we would not be able to describe them analytically, but we need to expect multiple solutions. I stopped it at the top end at x==2, since for positive x, the exponential takes off to infinity, and we can have no roots out there. For negative values of x, it is ths sin(sin(x)) term tha dominates the problem, and it is expectedly periodic.
In order to find a root, fzero does best when you provide a bracket, since fzero can find a different root unexpectedly.
format long g
[x,fval] = fzero(f,-1.8)
x =
-0.611061327929124
fval =
0
[x,fval] = fzero(f,-1.9)
x =
-3.09634776547485
fval =
-6.24500451351651e-17
Two different roots found, bsed on a slightly different choice in the start point.
You can make fzero a little more stable, if you provide a bracket instead of a single start point. But you need to insure the bracket contains an odd number of roots.
[x,fval] = fzero(f,[-3,2])
x =
-0.611061327929124
fval =
0
As you can see in the second example, the bracket contains 2 roots. So if I verify that some function value at some far distant negtive value is negative, compared to the known positive value at the upper end of the bracket, I can insure a root can be found, but which root was found will be somewhat arbitrary.
f(-1000)
ans =
-0.735821859357793
[x,fval] = fzero(f,[-1000,2])
x =
-936.194610769758
fval =
2.93890472569901e-14
Lastly, when a bracket contains an even number of roots, we see how fzero fails:
[x,fval] = fzero(f,[-6,2])
Error using fzero (line 274)
Function values at the interval endpoints must differ in sign.
The point is to know your function, and to know what root you are interested in finding. Plotting anything you do not know the behavior of is a HUGELY important thing to remember.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by