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
Open MATLAB on your computer.
Know 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.
Click inside the command window.
This is where you can assign values to variables, assign functions to variables, and can plot functions etc.
Name 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.
Set 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).
Type 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.
Press ↵ 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.
Get the Initial value.
This is the value that will be plugged into the function. For example: x = 1.
Use 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.