MATLAB: Solve Nonlinear Equation with error empty sym

equationnonlinear

I'm working on an exercise where I've got "f=0.5938" and a function "fun(n)". How can I identify the n value so that the final result is fun(n)=f ? I tried with "solve" but it wouldn't work (it gave me "S = empty sym: 0-by-1").
f = 0.5938;
syms n;
fun(n) = (0.5 * ((1 + 4*n) – 5 * n^2 + 2 * (n + 2) * log(n)) / ((n^2 – 1) * log(n) – 2 * (n – 1)^2)) – f;
S = solve(fun,n)

Best Answer

This usually means that the Symbolic toolbox is not able to find an analytical solution. The solution is to use vpasolve() to find a numerical solution
f = 0.5938;
syms n;
fun(n) = (0.5 * ((1 + 4*n) - 5 * n^2 + 2 * (n + 2) * log(n)) / ((n^2 - 1) * log(n) - 2 * (n - 1)^2)) - f;
S = vpasolve(fun,n)
However, it seems that your equation does not have a solution for the given value of 'f'. I recommend rechecking if there is a mistake in the writing of the equation.
Related Question