fsolve matlab中的多项式不起作用

fsolve a polynomial in matlab not working

(5/(r^2*9))- ((2)/(9*(6-r)^2)) - r = 0

想在matlab中求解上述多项式:

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

无效! 错误:'function_handle'.

类型的输入参数未定义运算符“.^”

只需创建 function handle and properly vectorize 函数,它应该可以工作:

fun= @(r) (5./(r.^2*9))- ((2)./(9*(6-r).^2))-r;
x0 = 1; % some initial point (10 is not a good initial estimate)
x = fsolve(fun,x0)