Table of Contents (click for easy navigation)
- What is ‘fzero’ command in MATLAB?
- Solving a Non-Linear Equation in MATLAB Using ‘fzero’ Function
What is the ‘fzero’ Function in MATLAB
The ‘fzero’ function in MATLAB is a function that finds the roots of a non-linear equation of a single variable unlike ‘fsolve’ which solves two or more than two variables.
Take an example of a non-linear equation having only one variable.
By using calculator, we can solve it and the answer is:
X = 0.7391
We have to find the roots of variable ‘x’ in the above equation. Root is the value of ‘x’ where function f(x) is equal to zero that’s why it is also called ‘finding a zero’ or ‘fzero’.
In MATLAB. We have to define the function to be solved and then we have to call ‘fzero’ command to solve it. We are also going to plot the signal.
Solving a Non-Linear Equation with ‘fzero’ Function
For non-linear equations which we can not solve with pencil, we use the ‘fzero’ command in MATLAB. Note that this command is only used to find the roots of a single variable non-linear equation. Let’s take above example and solve it in MATLAB.
% Go to command window and define an anonymous function ‘f’:
f = @(x) cos(x) – x = 0
% ‘f’ function is now saved in workspace.
% Plot it in MATLAB using ‘ezplot’ command.
% As we have to see the result from 0 to 1 because it is a trigonometric function.
% Here 0 is the initial guess and ‘f’ is the function.
Plotted signal is shown:
See where the zero line is cutting the graph. It is 0.7391 which we have calculated with pencil and calculator.
We have learned how to use the ‘fzero’ command in MATLAB. Remember that unlike the ‘fsolve’ command, ‘fzero’ command will only find the roots of a non-linear equation with single variable only.