Got Questions? Get Answers.
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:
fzero or fsolve to solve equation with symbols defined

Subject: fzero or fsolve to solve equation with symbols defined

From: Shweta

Date: 14 Nov, 2010 00:34:05

Message: 1 of 3

Hi,

In my code I define a few symbols and later on I obtain a non linear equation in one of those symbols for which I need to calculate the root.
example:
syms x;
g = x^3 + x^2 + x + 1;

% to solve for the roots of the above equation, I tried using
h = fzero(g,1);

 It gave me the following error:

If FUN is a MATLAB object, it must have an feval method.

Error in ==> fsolve at 184
    funfcn = lsqfcnchk(FUN,'fsolve',length(varargin),funValCheck,gradflag);

How do I solve this?

Thanks

Subject: fzero or fsolve to solve equation with symbols defined

From: Misael

Date: 14 Nov, 2010 01:24:04

Message: 2 of 3


Hi,

You could find a solution without using the symbolic toolbox.

x0 = 1; % your initial guess of the solution

fzero( @(x) x^ 3 + x^2 + x + 1, x0 )

This will only find a root to the polynomial closest to the
provided initial guess.

Another alternative is the following:

syms x;

solve( ' x ^ 3 + x ^ 2 + 1 ' ) % solves for all roots

Hope this helps. I think you cannot use fzero or fsolve for symbolic
variables.

Misael

"Shweta " <shwetasharma_16@yahoo.com> wrote in message <ibnapt$s0p$1@fred.mathworks.com>...
> Hi,
>
> In my code I define a few symbols and later on I obtain a non linear equation in one of those symbols for which I need to calculate the root.
> example:
> syms x;
> g = x^3 + x^2 + x + 1;
>
> % to solve for the roots of the above equation, I tried using
> h = fzero(g,1);
>
> It gave me the following error:
>
> If FUN is a MATLAB object, it must have an feval method.
>
> Error in ==> fsolve at 184
> funfcn = lsqfcnchk(FUN,'fsolve',length(varargin),funValCheck,gradflag);
>
> How do I solve this?
>
> Thanks

Subject: fzero or fsolve to solve equation with symbols defined

From: Roger Stafford

Date: 14 Nov, 2010 04:41:03

Message: 3 of 3

"Shweta " <shwetasharma_16@yahoo.com> wrote in message <ibnapt$s0p$1@fred.mathworks.com>...
> ......
> g = x^3 + x^2 + x + 1;
> ......
> How do I solve this?
- - - - - - - - -
  If you are trying to find the real root to x^3+x^2+x+1 = g for an arbitrary value for g, there is an explicit solution for the root (courtesy of Scipione del Ferro.) It is:

 a = 10/27 - g/2;
 b = (8/729+a^2)^(1/2);
 x = (b-a)^(1/3) - (b+a)^(1/3) - 1/3;

You could combine these formulas into a single expression involving just g but it would be rather cumbersome. The other two roots are complex-valued for all values of g.

  On the other hand if you only want the real root to x^3+x^2+x+1 = 0, that is trivial. It is x = -1. The other two are +i and -i. It wasn't clear from your request which of these equations you wanted to solve.

Roger Stafford

Tags for this Thread

No tags are associated with 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