Not able to use fzero function in Matlab

598 Views Asked by At

I am new to Matlab. I am trying to solve a non-linear equation using this inbuilt Matlab function called fzero() but it's not giving me the results.

The main file goes like

A = 5;
B = 6;
C = 10;

eq = equation (A, B, C);

fzero(@(x)eq, 0);

The other function file is:

function eq = equation (A, B, C)

syms x;
eq = A*x.^2 + B*x + C*(asinh(x)) ;

When I run this code, I get the following error:

Undefined function 'isfinite' for input arguments of type 'sym'.

Error in fzero (line 308)
    elseif ~isfinite(fx) || ~isreal(fx)

Error in main (line 7)
fzero(@(x)eq, 0); 

Could someone help me with this?

1

There are 1 best solutions below

0
On

If you are trying to solve the equation numerically, which is what fzero() does, you should do this:

A=5;
B=6;
C=10;
eq=@(x)A*x.^2+B*x+C*asinh(x);
fzero(eq,0);

The key difference is that you don't use symbols. fzero() can't handle them, I believe. You are right about the use of the anonymous function handle. :)