8 views (last 30 days)

What is the process for finding roots for this equation?

f(x)=sin[sin(x)]+e^x=0

Ameer Hamza
on 8 Oct 2020

Edited: Ameer Hamza
on 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

John D'Errico
on 8 Oct 2020

Ameer Hamza
on 8 Oct 2020

John D'Errico
on 8 Oct 2020

Edited: John D'Errico
on 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,fval] = fzero(f,-1.9)

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])

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)

[x,fval] = fzero(f,[-1000,2])

Lastly, when a bracket contains an even number of roots, we see how fzero fails:

[x,fval] = fzero(f,[-6,2])

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.

Opportunities for recent engineering grads.

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

Start Hunting!
## 0 Comments

Sign in to comment.