http://www.mathworks.com/matlabcentral/newsreader/view_thread/316857
MATLAB Central Newsreader  Simple nonlinear equation solving question
Feed for thread: Simple nonlinear equation solving question
enus
©19942014 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Mon, 13 Feb 2012 04:42:09 +0000
Simple nonlinear equation solving question
http://www.mathworks.com/matlabcentral/newsreader/view_thread/316857#866517
Patrick
Hi,<br>
<br>
I'm trying to solve the following nonlinear equation: 0=x^3 + (sin(x))^2<br>
<br>
EDU>> solve(x^3+sin(x)^2)<br>
<br>
ans =<br>
<br>
matrix([[0]])<br>
<br>
By graphing this equation, it appears that there are solutions at 0 and 0.803. What am I doing wrong?<br>
<br>
Thanks...

Mon, 13 Feb 2012 05:12:49 +0000
Re: Simple nonlinear equation solving question
http://www.mathworks.com/matlabcentral/newsreader/view_thread/316857#866518
Nasser M. Abbasi
On 2/12/2012 10:42 PM, Patrick wrote:<br>
> Hi,<br>
><br>
> I'm trying to solve the following nonlinear equation: 0=x^3 + (sin(x))^2<br>
><br>
> EDU>> solve(x^3+sin(x)^2)<br>
><br>
> ans =<br>
><br>
> matrix([[0]])<br>
><br>
> By graphing this equation, it appears that there are solutions at 0 and 0.803. What am I doing wrong?<br>
><br>
> Thanks...<br>
<br>
Which verssion do you have?<br>
<br>
on mine:<br>
<br>
MATLAB Version 7.12.0.635 (R2011a)<br>
<br>
I get<br>
<br>
<br>
EDU>> syms x<br>
solve(x^3+sin(x)^2)<br>
<br>
ans =<br>
<br>
0<br>
<br>
<br>
matrix([[0]]) means zero solution also? i..e a vector, which one<br>
entry, and that entry is zero. so same answer I have.<br>
<br>
So, I do not know how you got 0.803 there. What command you used<br>
to plot? Please show complete code you did, not one line.<br>
<br>
Nasser

Mon, 13 Feb 2012 05:32:10 +0000
Re: Simple nonlinear equation solving question
http://www.mathworks.com/matlabcentral/newsreader/view_thread/316857#866520
Patrick
Thanks for the response. My Matlab version is 7.10.0 (R2010a).<br>
<br>
The full code:<br>
<br>
clear all<br>
clc<br>
close all<br>
<br>
x=[.5:.01:1];<br>
<br>
m=x.^3 + (sin(x)).^2;<br>
<br>
plot(x,m)<br>
<br>
clear x<br>
x = sym('x');<br>
solve(x.^3 + (sin(x)).^2)<br>
<br>
Which provides a plot, and:<br>
<br>
ans =<br>
<br>
matrix([[0]])<br>
<br>
From the plot, I can see that there is also a solution at about 0.803.<br>
<br>
Thanks again...<br>
<br>
<br>
<br>
"Nasser M. Abbasi" <nma@12000.org> wrote in message <jha64h$kls$1@speranza.aioe.org>...<br>
> On 2/12/2012 10:42 PM, Patrick wrote:<br>
> > Hi,<br>
> ><br>
> > I'm trying to solve the following nonlinear equation: 0=x^3 + (sin(x))^2<br>
> ><br>
> > EDU>> solve(x^3+sin(x)^2)<br>
> ><br>
> > ans =<br>
> ><br>
> > matrix([[0]])<br>
> ><br>
> > By graphing this equation, it appears that there are solutions at 0 and 0.803. What am I doing wrong?<br>
> ><br>
> > Thanks...<br>
> <br>
> Which verssion do you have?<br>
> <br>
> on mine:<br>
> <br>
> MATLAB Version 7.12.0.635 (R2011a)<br>
> <br>
> I get<br>
> <br>
> <br>
> EDU>> syms x<br>
> solve(x^3+sin(x)^2)<br>
> <br>
> ans =<br>
> <br>
> 0<br>
> <br>
> <br>
> matrix([[0]]) means zero solution also? i..e a vector, which one<br>
> entry, and that entry is zero. so same answer I have.<br>
> <br>
> So, I do not know how you got 0.803 there. What command you used<br>
> to plot? Please show complete code you did, not one line.<br>
> <br>
> Nasser

Mon, 13 Feb 2012 05:39:10 +0000
Re: Simple nonlinear equation solving question
http://www.mathworks.com/matlabcentral/newsreader/view_thread/316857#866521
Roger Stafford
"Patrick" wrote in message <jha4b1$os6$1@newscl01ah.mathworks.com>...<br>
> I'm trying to solve the following nonlinear equation: 0=x^3 + (sin(x))^2<br>
> ........<br>
> By graphing this equation, it appears that there are solutions at 0 and 0.803. What am I doing wrong?<br>
         <br>
I would say your only mistake is placing too much reliance on the 'solve' function. It did find one of the roots, but the other two are apparently beyond its capability. You should understand that 'solve' is designed to produce expressions which represent solutions with an infinite precision in some sense, and it was unable to do that. It can only solve problems of a kind that human beings know how to solve, though it has more patience than most people. You need to use a numerical procedure to solve your problem using, say, the 'fzero' function.<br>
<br>
Long ago when I was a student of calculus I learned from "hard knocks" (so to speak) that most reasonably complicated equations or integrals that we students could dream up had no known analytic solution in the mathematical world and could only be solved numerically. I once wasted a whole day naively trying to integrate x^x.<br>
<br>
Roger Stafford

Mon, 13 Feb 2012 06:47:33 +0000
Re: Simple nonlinear equation solving question
http://www.mathworks.com/matlabcentral/newsreader/view_thread/316857#866525
Nasser M. Abbasi
On 2/12/2012 11:39 PM, Roger Stafford wrote:<br>
> "Patrick" wrote in message<jha4b1$os6$1@newscl01ah.mathworks.com>...<br>
>> I'm trying to solve the following nonlinear equation: 0=x^3 + (sin(x))^2<br>
>> ........<br>
>> By graphing this equation, it appears that there are solutions at 0 and 0.803. What am I doing wrong?<br>
>          <br>
<br>
> I would say your only mistake is placing too much reliance on the 'solve' function.<br>
> It did find one of the roots, but the other two are apparently beyond its capability.<br>
<br>
Also, a good 'solve' function will warn or tell the user that it<br>
can't solve the equation instead of just doing part of the job.<br>
<br>
In Mathematica 8:<br>
<br>
Solve[x^3 + (Sin[x])^2 == 0, x]<br>
gives<br>
Solve::nsmet: This system cannot be solved with the methods available to Solve. >><br>
<br>
<br>
in Maple 14:<br>
<br>
> solve(x^3+(sin(x))^2=0,x);<br>
3 2<br>
RootOf(_Z  sin(_Z) )<br>
<br>
<br>
So, both systems do not do anything with it.<br>
<br>
Nasser

Mon, 13 Feb 2012 13:59:11 +0000
Re: Simple nonlinear equation solving question
http://www.mathworks.com/matlabcentral/newsreader/view_thread/316857#866546
Alan Weiss
On 2/13/2012 1:47 AM, Nasser M. Abbasi wrote:<br>
> On 2/12/2012 11:39 PM, Roger Stafford wrote:<br>
>> "Patrick" wrote in message<jha4b1$os6$1@newscl01ah.mathworks.com>...<br>
>>> I'm trying to solve the following nonlinear equation: 0=x^3 +<br>
>>> (sin(x))^2<br>
>>> ........<br>
>>> By graphing this equation, it appears that there are solutions at 0<br>
>>> and 0.803. What am I doing wrong?<br>
>>          <br>
><br>
>> I would say your only mistake is placing too much reliance on the<br>
>> 'solve' function.<br>
>> It did find one of the roots, but the other two are apparently beyond<br>
>> its capability.<br>
><br>
> Also, a good 'solve' function will warn or tell the user that it<br>
> can't solve the equation instead of just doing part of the job.<br>
><br>
> In Mathematica 8:<br>
> <br>
> Solve[x^3 + (Sin[x])^2 == 0, x]<br>
> gives<br>
> Solve::nsmet: This system cannot be solved with the methods available to<br>
> Solve. >><br>
> <br>
><br>
> in Maple 14:<br>
> <br>
>> solve(x^3+(sin(x))^2=0,x);<br>
> 3 2<br>
> RootOf(_Z  sin(_Z) )<br>
> <br>
><br>
> So, both systems do not do anything with it.<br>
><br>
> Nasser<br>
><br>
<br>
This may be too obvious to talk about, but for a numerical solution you <br>
can use fzero:<br>
fun = @(x)x^3+(sin(x))^2;<br>
z = fzero(fun,.1,2)<br>
<br>
z =<br>
<br>
0.8028<br>
<br>
Alan Weiss<br>
MATLAB mathematical toolbox documentation

Mon, 13 Feb 2012 14:04:14 +0000
Re: Simple nonlinear equation solving question
http://www.mathworks.com/matlabcentral/newsreader/view_thread/316857#866548
Alan Weiss
On 2/13/2012 8:59 AM, Alan Weiss wrote:<br>
> On 2/13/2012 1:47 AM, Nasser M. Abbasi wrote:<br>
>> On 2/12/2012 11:39 PM, Roger Stafford wrote:<br>
>>> "Patrick" wrote in message<jha4b1$os6$1@newscl01ah.mathworks.com>...<br>
>>>> I'm trying to solve the following nonlinear equation: 0=x^3 +<br>
>>>> (sin(x))^2<br>
>>>> ........<br>
>>>> By graphing this equation, it appears that there are solutions at 0<br>
>>>> and 0.803. What am I doing wrong?<br>
>>>          <br>
>><br>
>>> I would say your only mistake is placing too much reliance on the<br>
>>> 'solve' function.<br>
>>> It did find one of the roots, but the other two are apparently beyond<br>
>>> its capability.<br>
>><br>
>> Also, a good 'solve' function will warn or tell the user that it<br>
>> can't solve the equation instead of just doing part of the job.<br>
>><br>
>> In Mathematica 8:<br>
>> <br>
>> Solve[x^3 + (Sin[x])^2 == 0, x]<br>
>> gives<br>
>> Solve::nsmet: This system cannot be solved with the methods available to<br>
>> Solve. >><br>
>> <br>
>><br>
>> in Maple 14:<br>
>> <br>
>>> solve(x^3+(sin(x))^2=0,x);<br>
>> 3 2<br>
>> RootOf(_Z  sin(_Z) )<br>
>> <br>
>><br>
>> So, both systems do not do anything with it.<br>
>><br>
>> Nasser<br>
>><br>
><br>
> This may be too obvious to talk about, but for a numerical solution you<br>
> can use fzero:<br>
> fun = @(x)x^3+(sin(x))^2;<br>
> z = fzero(fun,.1,2)<br>
><br>
> z =<br>
><br>
> 0.8028<br>
><br>
> Alan Weiss<br>
> MATLAB mathematical toolbox documentation<br>
<br>
Sorry, that should have been<br>
z = fzero(fun,[.1,2])<br>
<br>
Alan Weiss<br>
MATLAB mathematical toolbox documentation

Mon, 13 Feb 2012 17:31:11 +0000
Re: Simple nonlinear equation solving question
http://www.mathworks.com/matlabcentral/newsreader/view_thread/316857#866585
Patrick
Thanks everyone, for all your help. It's much appreciated. <br>
<br>
It looks like it's best to graph the equation to verify that there are no other solutions. Checking the solution with another solve function looks like it's important as well.