Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Simple non-linear equation solving question

Subject: Simple non-linear equation solving question

From: Patrick

Date: 13 Feb, 2012 04:42:09

Message: 1 of 8

Hi,

I'm trying to solve the following non-linear equation: 0=-x^3 + (sin(x))^2

EDU>> solve(-x^3+sin(x)^2)
 
ans =
 
matrix([[0]])

By graphing this equation, it appears that there are solutions at 0 and 0.803. What am I doing wrong?

Thanks...

Subject: Simple non-linear equation solving question

From: Nasser M. Abbasi

Date: 13 Feb, 2012 05:12:49

Message: 2 of 8

On 2/12/2012 10:42 PM, Patrick wrote:
> Hi,
>
> I'm trying to solve the following non-linear equation: 0=-x^3 + (sin(x))^2
>
> EDU>> solve(-x^3+sin(x)^2)
>
> ans =
>
> matrix([[0]])
>
> By graphing this equation, it appears that there are solutions at 0 and 0.803. What am I doing wrong?
>
> Thanks...

Which verssion do you have?

on mine:

MATLAB Version 7.12.0.635 (R2011a)

I get

--------------------
EDU>> syms x
solve(-x^3+sin(x)^2)
  
ans =
  
0
----------------------

matrix([[0]]) means zero solution also? i..e a vector, which one
entry, and that entry is zero. so same answer I have.

So, I do not know how you got 0.803 there. What command you used
to plot? Please show complete code you did, not one line.

--Nasser

Subject: Simple non-linear equation solving question

From: Patrick

Date: 13 Feb, 2012 05:32:10

Message: 3 of 8

Thanks for the response. My Matlab version is 7.10.0 (R2010a).

The full code:

clear all
clc
close all

x=[-.5:.01:1];

m=-x.^3 + (sin(x)).^2;

plot(x,m)

clear x
x = sym('x');
solve(-x.^3 + (sin(x)).^2)

Which provides a plot, and:

ans =
 
matrix([[0]])

From the plot, I can see that there is also a solution at about 0.803.

Thanks again...



"Nasser M. Abbasi" <nma@12000.org> wrote in message <jha64h$kls$1@speranza.aioe.org>...
> On 2/12/2012 10:42 PM, Patrick wrote:
> > Hi,
> >
> > I'm trying to solve the following non-linear equation: 0=-x^3 + (sin(x))^2
> >
> > EDU>> solve(-x^3+sin(x)^2)
> >
> > ans =
> >
> > matrix([[0]])
> >
> > By graphing this equation, it appears that there are solutions at 0 and 0.803. What am I doing wrong?
> >
> > Thanks...
>
> Which verssion do you have?
>
> on mine:
>
> MATLAB Version 7.12.0.635 (R2011a)
>
> I get
>
> --------------------
> EDU>> syms x
> solve(-x^3+sin(x)^2)
>
> ans =
>
> 0
> ----------------------
>
> matrix([[0]]) means zero solution also? i..e a vector, which one
> entry, and that entry is zero. so same answer I have.
>
> So, I do not know how you got 0.803 there. What command you used
> to plot? Please show complete code you did, not one line.
>
> --Nasser

Subject: Simple non-linear equation solving question

From: Roger Stafford

Date: 13 Feb, 2012 05:39:10

Message: 4 of 8

"Patrick" wrote in message <jha4b1$os6$1@newscl01ah.mathworks.com>...
> I'm trying to solve the following non-linear equation: 0=-x^3 + (sin(x))^2
> ........
> By graphing this equation, it appears that there are solutions at 0 and 0.803. What am I doing wrong?
- - - - - - - - - -
  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.

  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.

Roger Stafford

Subject: Simple non-linear equation solving question

From: Nasser M. Abbasi

Date: 13 Feb, 2012 06:47:33

Message: 5 of 8

On 2/12/2012 11:39 PM, Roger Stafford wrote:
> "Patrick" wrote in message<jha4b1$os6$1@newscl01ah.mathworks.com>...
>> I'm trying to solve the following non-linear equation: 0=-x^3 + (sin(x))^2
>> ........
>> By graphing this equation, it appears that there are solutions at 0 and 0.803. What am I doing wrong?
> - - - - - - - - - -

> 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.

Also, a good 'solve' function will warn or tell the user that it
can't solve the equation instead of just doing part of the job.

In Mathematica 8:
-------------------
Solve[-x^3 + (Sin[x])^2 == 0, x]
gives
Solve::nsmet: This system cannot be solved with the methods available to Solve. >>
---------------------

in Maple 14:
---------------------------
> solve(-x^3+(sin(x))^2=0,x);
                                      3 2
                             RootOf(_Z - sin(_Z) )
----------------------------

So, both systems do not do anything with it.

--Nasser

Subject: Simple non-linear equation solving question

From: Alan Weiss

Date: 13 Feb, 2012 13:59:11

Message: 6 of 8

On 2/13/2012 1:47 AM, Nasser M. Abbasi wrote:
> On 2/12/2012 11:39 PM, Roger Stafford wrote:
>> "Patrick" wrote in message<jha4b1$os6$1@newscl01ah.mathworks.com>...
>>> I'm trying to solve the following non-linear equation: 0=-x^3 +
>>> (sin(x))^2
>>> ........
>>> By graphing this equation, it appears that there are solutions at 0
>>> and 0.803. What am I doing wrong?
>> - - - - - - - - - -
>
>> 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.
>
> Also, a good 'solve' function will warn or tell the user that it
> can't solve the equation instead of just doing part of the job.
>
> In Mathematica 8:
> -------------------
> Solve[-x^3 + (Sin[x])^2 == 0, x]
> gives
> Solve::nsmet: This system cannot be solved with the methods available to
> Solve. >>
> ---------------------
>
> in Maple 14:
> ---------------------------
>> solve(-x^3+(sin(x))^2=0,x);
> 3 2
> RootOf(_Z - sin(_Z) )
> ----------------------------
>
> So, both systems do not do anything with it.
>
> --Nasser
>

This may be too obvious to talk about, but for a numerical solution you
can use fzero:
fun = @(x)-x^3+(sin(x))^2;
z = fzero(fun,.1,2)

z =

     0.8028

Alan Weiss
MATLAB mathematical toolbox documentation

Subject: Simple non-linear equation solving question

From: Alan Weiss

Date: 13 Feb, 2012 14:04:14

Message: 7 of 8

On 2/13/2012 8:59 AM, Alan Weiss wrote:
> On 2/13/2012 1:47 AM, Nasser M. Abbasi wrote:
>> On 2/12/2012 11:39 PM, Roger Stafford wrote:
>>> "Patrick" wrote in message<jha4b1$os6$1@newscl01ah.mathworks.com>...
>>>> I'm trying to solve the following non-linear equation: 0=-x^3 +
>>>> (sin(x))^2
>>>> ........
>>>> By graphing this equation, it appears that there are solutions at 0
>>>> and 0.803. What am I doing wrong?
>>> - - - - - - - - - -
>>
>>> 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.
>>
>> Also, a good 'solve' function will warn or tell the user that it
>> can't solve the equation instead of just doing part of the job.
>>
>> In Mathematica 8:
>> -------------------
>> Solve[-x^3 + (Sin[x])^2 == 0, x]
>> gives
>> Solve::nsmet: This system cannot be solved with the methods available to
>> Solve. >>
>> ---------------------
>>
>> in Maple 14:
>> ---------------------------
>>> solve(-x^3+(sin(x))^2=0,x);
>> 3 2
>> RootOf(_Z - sin(_Z) )
>> ----------------------------
>>
>> So, both systems do not do anything with it.
>>
>> --Nasser
>>
>
> This may be too obvious to talk about, but for a numerical solution you
> can use fzero:
> fun = @(x)-x^3+(sin(x))^2;
> z = fzero(fun,.1,2)
>
> z =
>
> 0.8028
>
> Alan Weiss
> MATLAB mathematical toolbox documentation

Sorry, that should have been
z = fzero(fun,[.1,2])

Alan Weiss
MATLAB mathematical toolbox documentation

Subject: Simple non-linear equation solving question

From: Patrick

Date: 13 Feb, 2012 17:31:11

Message: 8 of 8

Thanks everyone, for all your help. It's much appreciated.

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.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us