Search code examples
matlabcalculus

Matlab fzero command usage


I am trying to approximate a solution for the equation x+sin(x) = -e^x around the point x=-2. I used the line:

fzero('x+sin(x) == -exp(x)', -2);

However, this gave me the wrong answer. I believe my mistake was using a == in the expression and it should be:

fzero('x+sin(x)+exp(x)', -2);

Could anyone explain the reasoning behind this?


Solution

  • To quote the MATLAB documentation:

    x = fzero(fun,x0) tries to find a point x where fun(x) = 0.

    fzero doesn't reorder your equations for you, it can only calculate the root or zero of a given function.