0
votes

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);

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:

Error using fzero (line 118)
The input should be either a structure with valid fields or at least two arguments to
FZERO.

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

Could someone help me with this?

EDIT: WHen I specify the check point as 0, it returns me 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); 
2
Hey, you changed your question! It looks like you are having trouble understanding the way sym works. You should spend some time, and if you can't figure it out ask another question. - Mikhail
@Mikhail No, I just edited the question and added the later part. It still gives me an error when I specify the check-point. - India Slaver
Note that you can also solve symbolic equations with Matlab. Make sure to check doc solve - Dennis Jaheruddin
@DennisJaheruddin Matlab hangs when I use this function. My original equation is too lengthy. :( - India Slaver

2 Answers

0
votes

There are several mistakes in your code. For a start, fzero is for finding numerical roots of a non-linear equation, it is not for symbolic computations (check the documentation), so get rid of syms x. The correct way to call fzero in your case is a as follows:

A = 5;
B = 6;
C = 10;
eq = @(x) A*x^2 + B*x + C*(asinh(x));
x0 = 0; % or whatever starting point you want to specify
x = fzero(eq,x0)
0
votes

You need to specify a guess, x0 point

fun = @sin; % function
x0 = 3; % initial point
x = fzero(fun,x0)