How to solve complex equation

조회 수: 7 (최근 30일)
Brahma
Brahma 2018년 1월 19일
편집: David Goodmanson 2018년 1월 21일
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?

답변 (3개)

Brahma
Brahma 2018년 1월 19일
@Birdman
That only returns 1 solution. But it has 5 solutions:

Star Strider
Star Strider 2018년 1월 19일
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
Star Strider
Star Strider 2018년 1월 19일
  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 2018년 1월 20일
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

댓글을 달려면 로그인하십시오.


Matt J
Matt J 2018년 1월 20일
편집: Matt J 2018년 1월 20일
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
Walter Roberson
Walter Roberson 2018년 1월 20일
I am not convinced that all of the roots are real-valued.
David Goodmanson
David Goodmanson 2018년 1월 20일
편집: David Goodmanson 2018년 1월 21일
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.

댓글을 달려면 로그인하십시오.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by