X
wikiHow is a “wiki,” similar to Wikipedia, which means that many of our articles are co-written by multiple authors. To create this article, volunteer authors worked to edit and improve it over time.
This article has been viewed 3,143 times.
Learn more...
This article will show you how to solve basic engineering problems using MATLABs built-in function known as fzero. This function is used to find the root of nonlinear functions.
Steps
-
1Open MATLAB on your computer.
-
2Know what function you want to solve. When using the fzero built in function you must have a function handle or function name and has an initial value that can be scalar or a 2-element vector.Advertisement
-
3Click inside the command window. This is where you can assign values to variables, assign functions to variables, and can plot functions etc.
-
4Name the function. The first thing you will need to type is the name of the function. It may be any name you would like as long as it starts with a letter and doesn’t contain special characters. It may contain numbers as long as it is behind a letter.
-
5Set up the independent variables. Once you have come up with a name for your function, you must put an equal sign = after the function name. This will put turn the function name into an output variable that can be called at any time. Then put a space and an @. Immediately after the @, add an open parenthesis (. Now you may list all the independent variables.
- For example: it should look like this if your independent variable is x, you would type @(x).
- If you have more than one independent variables, then put a comma after each variable, as such @(x, y).
-
6Type your function. This can be any mathematical function that is nonlinear. There are many types of functions that can be written, for example:
- The example function being used will be fun = @(x) x3 – 2x – 5.
-
7Press ↵ Enter. This saves the function into the workspace that can be seen to the side allowing you to call it at any time in the command window by typing its name.
-
8Get the Initial value. This is the value that will be plugged into the function. For example: x = 1.
-
9Use fzero. Now we will plug the function and the initial value to the function fzero to find what the root of the nonlinear equation will be. By calling fzero(fun, x) this will solve the polynomial.
Advertisement
About This Article
Advertisement