How to solve complex equation

7 views (last 30 days)
Brahma
Brahma on 19 Jan 2018
Edited: David Goodmanson on 21 Jan 2018
Hello, I'm completely new to Matlab and was wondering if there is a simple way to solve the following equation:
x^2 - 100*x + 120 = 400*sin(x)
It can't really be solved symbolically for all solutions, so it should be solved numerically? How can Matlab solve and show all solutions in a simple way for me to understand?

Answers (3)

Brahma
Brahma on 19 Jan 2018
@Birdman
That only returns 1 solution. But it has 5 solutions:

Star Strider
Star Strider on 19 Jan 2018
Use fzero, a loop, and uniquetol:
f = @(x) x^2 - 100*x + 120 - 400*sin(x);
for k1 = 1:100
s(k1) = fzero(f, (k1-1)*pi);
end
s = uniquetol(s, 1E-3)
s =
0.2420 3.8037 5.1258 97.6633 102.4703
It is not efficient, though has the virtue of finding all the solutions.
  5 Comments
Star Strider
Star Strider on 19 Jan 2018
  1. Not that I am aware of
  2. Correct. They all do require some knowledge of MATLAB and programming in general. That is the essence of this forum!
Wolfram Alpha (link) will give you a list of the roots.
David Goodmanson
David Goodmanson on 20 Jan 2018
It found all the solutions except for the one that it missed:
x0 = 101.16908798537
x0.^2 - 100*x0 + 120 -400*sin(x0)
ans = 5.9433e-10

Sign in to comment.


Matt J
Matt J on 20 Jan 2018
Edited: Matt J on 20 Jan 2018
It can't really be solved symbolically for all solutions, so it should be solved numerically? How can Matlab solve and show all solutions in a simple way for me to understand?
There is no general way to numerically determine either the number of roots or their locations for an arbitrary function. How do you even know that the function in your example has 5 roots? From a plot? You can't rely on that. As a different example, a plot of sin(1/x) will show some of the roots, but never all of them, no matter how finely you plot nor how much you zoom in.
  6 Comments
Walter Roberson
Walter Roberson on 20 Jan 2018
I am not convinced that all of the roots are real-valued.
David Goodmanson
David Goodmanson on 20 Jan 2018
Edited: David Goodmanson on 21 Jan 2018
Hi Matt & Walter,
Clearly one can't rely uncritically on either plots or solvers. I should have stated it better initially, that plots are valuable but, as you point out, only when combined with a healthy dose of analysis plus common sense or whatever you want to call it.
In one of the other answers to this question it's claimed that the function has just five (real) roots. In this case a plot was invaluable (and I believe the quickest and easiest way) at showing that there are exactly six real roots. **
As to Walter's comment, no doubt there are a lot of complex roots, quite possibly an infinite number. For example
z = 17.181087010965761 + i*1.857398520646881
and its complex conjugate. It's true that the title of the question does include 'complex', but I think that finding the real roots was the intent.
** There is also the topological evidence that if you think that it's highly unlikely that the parabola is going to be tangent to the sine wave at any single point, then since the parabola goes to +oo as x goes to +-oo, and the sine wave stays basically along a horizontal line, those two curves have to cross an even number of times. So five roots is suspicious on that basis, and the plot confirms it.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!