How to use fzero() to solve polynomial equation in MATLAB?

635 Views Asked by At

I would like to solve the following polynomial numerically for r:

I am trying to use fzero() as follows:

r = (5/(r^2*9))- ((2)/(9*(6-r)^2))
x0 = 10; % some initial point
x = fzero(r,x0)

How can this be done with fzero()?

2

There are 2 best solutions below

1
On BEST ANSWER
  • Input variable and function name should be different
  • Just change the function name to pol
  • To use fzero the function pol have to be a function handle defined via @
pol =@(r) (5/(r^2*9))- ((2)/(9*(6-r)^2))
x0 = 10; % some initial point
x = fzero(pol,x0)

solution

x =  3.6754
1
On

It should be noted that, the first argument in fzero() should be "a function handle, inline function, or string containing the name of the function to evaluate", but yours is just an expression, which is not valid.

Besides the approach by @Adam (using function handle), another way is to use anonymous function, i.e.,

 x = fzero(@(r) (5/(r^2*9))- ((2)/(9*(6-r)^2)) ,x0)

where

@(r) (5/(r^2*9))- ((2)/(9*(6-r)^2))

is the anonymous function with respect to argument r.

You will get the same result that x = 3.6754.