How to find all solutions to a function?

48 views (last 30 days)
wioqiiowqqiow
wioqiiowqqiow on 20 Oct 2018
Commented: Walter Roberson on 21 Oct 2018
I am trying to find all solutions to
f(y) = 1.1^2+y.^2-1-4.5*(sin(1.1.*y)).^2
However, I only get one of the solutions, which is
-1.845486306009674675960636485178.
It's suppose to have four solutions, according to Wolframalpha.
y = -1.84
y = -0.21
y = 0.21
y = 1.84
I have tried using the command vpasolve, like below,
sol = vpasolve(f,y).
But it does not work for some reason.
What other command can I use to find all four of the solutions to the function above?

Answers (3)

John D'Errico
John D'Errico on 20 Oct 2018
Edited: John D'Errico on 20 Oct 2018
This could be a deflating experience. ;-)
x(1) = vpasolve(f)
x =
-1.8454863060096746759606364851789
>> x(2) = vpasolve(f./(y - x(1)))
x =
[ -1.8454863060096746759606364851789, 1.8454863060096746759606364851789]
x(2) = vpasolve(f./prod(y - x))
x =
[ -1.8454863060096746759606364851789, -0.21998207940626722662355300718635]
x(3) = vpasolve(f./prod(y - x))
x =
[ -1.8454863060096746759606364851789, -0.21998207940626722662355300718635, 0.21998207940626722662355300718635]
x(4) = vpasolve(f./prod(y - x))
x =
[ -1.8454863060096746759606364851789, -0.21998207940626722662355300718635, 0.21998207940626722662355300718635, 1.8454863060096746759606364851789]
Well, deflating, because the approach I used is often called deflation, where at each turn I kill off all of the other roots I found so far. So, if you plot f(x), we get this:
ezplot(f)
hold on
ezplot(f./(y - x(1)))
And now plot the deflated functions in turn. As you see, each one has one root "removed" from the previous curve.
ezplot(f./prod(y - x(1:2)))
ezplot(f./prod(y - x(1:3)))
h = refline(0,0);
h.Color = 'k';
legend('f(y)','1 root deflated','2 roots deflated','3 roots deflated','Zero')
axis([-6,6,-3,3])
At the very end, what would we see?
ezplot(f./prod(y - x))
refline(0,0)
Thus, a curve that has been thoroughly uprooted.
  3 Comments
John D'Errico
John D'Errico on 20 Oct 2018
Edited: John D'Errico on 20 Oct 2018
I showed how to find all 4 roots. It required only 4 calls to VPASOLVE. The graphics were merely to show you that it did indeed work.
vpa(x,5)
ans =
[ -1.8455, -0.21998, 0.21998, 1.8455]
Provably finding ALL roots of a completely general arbitrary function is impossible, since there may be infinitely many roots, and some may be very difficult to find.
However, I have no idea what you mean by "100 different points, finding the y values for each point." Sorry, but if you want more help than I have given you, you need to explain what you need more clearly than that.
wioqiiowqqiow
wioqiiowqqiow on 20 Oct 2018
Edited: Walter Roberson on 21 Oct 2018
So, like I told madhan, I am trying to sketch an implicit function x.^2+y.^2=1+4.5.*(sin(x.*y).^2. If you want to see it, it looks like this , https://www.desmos.com/calculator/z0q9oodqtl.
And I am not allowed to use functions such as fimplicit,ezplot, contour etc. I cannot parameterize the implicit function either. Therefore, I am forced to use a numerical method, and put each x value in separately and get an output value, y, to then plot after those points.
And if I want to sketch the whole figure then there will be lots of points. Hence, the asking for a more simple method to get the root of a function.

Sign in to comment.


madhan ravi
madhan ravi on 20 Oct 2018
Edited: madhan ravi on 20 Oct 2018
syms y
f = 1.1^2+y.^2-1-4.5*(sin(1.1.*y)).^2
fplot(f)
hold on
fplot(subs(y,0))
root1 = vpasolve(f,[-2 -1.5]) %see the graph and determine the interval of first root and the to the other roots
root2 = vpasolve(f,[-0.5 0])
root3 = vpasolve(f,[1.5 2])
root4 = vpasolve(f,[0 0.5])
  7 Comments
wioqiiowqqiow
wioqiiowqqiow on 20 Oct 2018
I dont think you are suppose to use any of matlabs commands to plot it for you. I think you are suppose to use a numerical method to solve for every x and y value and then plot it. Thats why I am trying to use vpasolve with a for-statement.
Walter Roberson
Walter Roberson on 21 Oct 2018
implicit solutions become possible if you convert to polar coordinates and solve for theta.

Sign in to comment.


Walter Roberson
Walter Roberson on 20 Oct 2018
There is no method to find all roots of an arbitrary nonlinear function, even if it is not a "black box", and even if there are a finite number of roots . If there were such a method then solving for global minimum would just be a matter of solving for all roots of the derivative and choosing the one that gave the minimum.
If there were a general method to solve for all roots then there are a number of hard mathematical problems that would become easy by reexpressing them. For example it is not known if there is even one odd "perfect number" (a number equal to the sum of its factors including 1 but excluding itself, like 6 = 1+2+3). Create a function that runs over the odd integer and calculates number minus the sum of its factors, apply the hypothetical root finder, and out pops the complete list of them. Therefore such a hypothetical root finder would have to be a robust generalized existence prover for all kinds of mathematical problems. Gödel had something to say about that.
For functions for which there is a single y for each x, and which are not too strange, the technique of the following contribution can help.
https://www.mathworks.com/matlabcentral/fileexchange/55206-findroots

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!