Help using fzero function in matlab

In summary, the conversation is about finding approximate values for all the equilibria of a nonlinear equation using the direction field and the fzero function. There are three equilibrium points at y=0.5, y=1.3, and y=4. The speaker suggests using the help function in Matlab or treating the right-hand side of the equation as an algebraic equation to solve for the roots.
  • #1
Pepsi24chevy
65
0
Hey guys i have nonlinear equation: dy/dt = 3siny + y - 2. I got the direction field with this

>> [T,Y] = meshgrid(-5:00.2:5, -5:0.2:5);
>> S = (3*sin(Y))+Y-2;
>> L = sqrt(1 + S.^2);
>> quiver(T, Y, 1./L, S./L, 0.5), axis tight
>> xlabel 't', ylabel 'y'
>> title 'Direction Field for dy/dt = (3*sin(Y))+Y-2'

NOw i need to use fzero function to find approximate values for all the equilibria of teh system. I just dont' know how to use fzero with a dif equation like this. ANy help is appreciated. thanks Also, i know the values are around 0.5 and 4.
 
Physics news on Phys.org
  • #2
Pepsi24chevy said:
Hey guys i have nonlinear equation: dy/dt = 3siny + y - 2. I got the direction field with this

>> [T,Y] = meshgrid(-5:00.2:5, -5:0.2:5);
>> S = (3*sin(Y))+Y-2;
>> L = sqrt(1 + S.^2);
>> quiver(T, Y, 1./L, S./L, 0.5), axis tight
>> xlabel 't', ylabel 'y'
>> title 'Direction Field for dy/dt = (3*sin(Y))+Y-2'

NOw i need to use fzero function to find approximate values for all the equilibria of teh system. I just dont' know how to use fzero with a dif equation like this. ANy help is appreciated. thanks Also, i know the values are around 0.5 and 4.

The equilibrium points for an autonomous DE are the values of y such that the RHS=0. If I plot the RHS as a function of y, I get 3 zeros. I use Mathematica so can't help with matlab. Doesn't it have a help function? You know, place the cursor on the function then press the F1 key. Surely you can just treat it (RHS) as an algebraic equation in y and solve for the roots right?
 
  • #3


Hi there,

To use the fzero function in MATLAB, you will need to define a function handle for your nonlinear equation. In this case, your equation is dy/dt = 3siny + y - 2, so you can define a function handle like this:

f = @(y) 3*sin(y) + y - 2;

Next, you will need to choose an initial guess for the root of your equation. This is where the equilibrium values will be located. Since you already have a direction field, you can use that to estimate the equilibrium values. For example, from your direction field, it looks like there is an equilibrium value at around y = 0.5 and another one at y = 4. So, you can use these as initial guesses for your fzero function.

To find the first equilibrium value, you can use the following code:

x1 = fzero(f, 0.5);

This will give you the value of x (or y in this case) where the function f is equal to 0. In other words, it will give you the first equilibrium value.

To find the second equilibrium value, you can use the same code but change the initial guess to 4:

x2 = fzero(f, 4);

You can repeat this process for any other equilibrium values that you see in your direction field. Just make sure to change the initial guess to the approximate location of the equilibrium value.

I hope this helps. Let me know if you have any other questions. Good luck!
 

Related to Help using fzero function in matlab

What is the fzero function in Matlab?

The fzero function in Matlab is used to find the roots of a given function. It is a numerical method that uses a combination of bisection, secant, and inverse quadratic interpolation methods to approximate the root.

How do I use the fzero function in Matlab?

To use the fzero function in Matlab, you need to define a function handle for the function you want to find the root of. Then, you can call the fzero function, passing in the function handle and an initial guess for the root. The function will return the approximate root.

What is the syntax for the fzero function in Matlab?

The syntax for the fzero function in Matlab is:
fzero(fun, x0)
where 'fun' is the function handle for the function you want to find the root of, and 'x0' is the initial guess for the root.

Can the fzero function find multiple roots?

No, the fzero function in Matlab can only find one root at a time. If a function has multiple roots, you will need to call the fzero function multiple times with different initial guesses.

What are some common errors when using the fzero function in Matlab?

Some common errors when using the fzero function in Matlab include: providing an incorrect function handle, using an initial guess that is not close enough to the root, or having a function with multiple roots but only calling the fzero function once. It is important to carefully check the function and initial guess when using the fzero function to avoid these errors.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
507
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
Back
Top