fzero MATLAB Function: Everything You Need to Know

274

Table of Contents (click for easy navigation)

  1. What is ‘fzero’ command in MATLAB?
  2. Solving a Non-Linear Equation in MATLAB Using ‘fzero’ Function
  3. Conclusion
  4. References 

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.

Description

Take an example of a non-linear equation having only one variable.

F(x)=Cosx-x=0

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.

MATLAB Code:

% 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.

Ezplot(f,[0,1])

Grid

% As we have to see the result from 0 to 1 because it is a trigonometric function.

Fzero(f,0)

% 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.

Conclusion

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.

References

MATLAB Software