March 13

fzero MATLAB Function: Everything You Need to Know

fzero MATLAB Function: Everything You Need to Know

Abdul Mannan

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

Loved this? Spread the word


About the Author

Abdul Mannan is an Electrical Power Engineer with specialization in High Voltage. He's the founder and former president at Youth Entrepreneurship Society (YES), University of Engineering & Technology Taxila Campus. He is the leading contributor at "Right to Write". Connect with him about Entrepreneurship, startup ideas, creative writing, business strategies via linked in.

Abdul Mannan

Related posts

We Review Text to Image Artificial Intelligence (AI) Technology, Generators, and Uses

​Read More

10+ Best Construction Takeoff Software & Tools for Contractors in 2022

​Read More

How to Use Bill of Materials (BOM) in SolidWorks: Review Beginner’s Guide

​Read More

Compare Autodesk Inventor vs Fusion 360: Review Which One to Buy

​Read More
{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Subscribe to our newsletter now!