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()
?
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()
?
pol
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
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
.