Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Simple non-linear equation solving question

0 views
Skip to first unread message

Patrick

unread,
Feb 12, 2012, 11:42:09 PM2/12/12
to
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...

Nasser M. Abbasi

unread,
Feb 13, 2012, 12:12:49 AM2/13/12
to
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

Patrick

unread,
Feb 13, 2012, 12:32:10 AM2/13/12
to
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" <n...@12000.org> wrote in message <jha64h$kls$1...@speranza.aioe.org>...

Roger Stafford

unread,
Feb 13, 2012, 12:39:10 AM2/13/12
to
"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

Nasser M. Abbasi

unread,
Feb 13, 2012, 1:47:33 AM2/13/12
to
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

Alan Weiss

unread,
Feb 13, 2012, 8:59:11 AM2/13/12
to
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

Alan Weiss

unread,
Feb 13, 2012, 9:04:14 AM2/13/12
to
Sorry, that should have been
z = fzero(fun,[.1,2])

Patrick

unread,
Feb 13, 2012, 12:31:11 PM2/13/12
to
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.
0 new messages