Making a Phase Portrait of an Equation

  • MATLAB
  • Thread starter grrrp
  • Start date
  • Tags
    Phase
In summary, the conversation discussed solving differential equations in Matlab and creating a phase portrait and animation of a point moving in the phase plane. The code provided shows how to solve the equations and create the animation using the ode45 function and plotting techniques.
  • #1
grrrp
1
0
Hello,
before a while I've started studying differential equations in Matlab. I'm solving some problems and I hope that someone could help me.
Firstly I've got to make a phase portrait of this equation:

|x' = y - x^3
|y' = x - y

Here is what I made:

C:
%---File - func.m---
function res = func(t,x)
res = [x(2) - x(1)^3,
    x(1) - x(2)];

C:
%---File - solve.m---
plot([-7,7],[0,0])
hold on
plot([0,0],[-4,4])
axis([-7,7,-4,4]);
x0 = -14.5;
y0 = -14.5;

while x0 <= 15
    [t,x] = ode45(@func, [0,8],[x0,y0]);
    plot(x(:,1),x(:,2),'k')
    [t,x] = ode45(@func, [0,1],[x0,y0]);
    plot(x(:,1),x(:,2),'r')
    if y0 >= 15
        x0 = x0 + 3;
        y0 = -14.5;
    end
    y0 = y0 + 3;
end

Am I correct?

I've got to make an animation of the movement of a point (x(t),y(t)) in the phase area, if
x(0) = 4 and y(0) = -3 and the time - t, 0 <= t <= 3.
For the second part I don't have an idea.
Could you help me, please?
 
Last edited by a moderator:
Physics news on Phys.org
  • #2
Yes, your code looks correct. To create the animation, you can use the ode45 function to solve the system of differential equations and then plot the trajectory of the point (x(t),y(t)) in the phase plane. You can use the hold on and plot functions to plot the trajectory as it moves over time. Finally, you can use the pause command to create a short delay between each frame of the animation. Here is an example of code that can be used to create the animation:%---File - func.m---function res = func(t,x)res = [x(2) - x(1)^3, x(1) - x(2)];%---File - solve.m---plot([-7,7],[0,0])hold onplot([0,0],[-4,4])axis([-7,7,-4,4]);x0 = 4;y0 = -3;[t,x] = ode45(@func, [0,3],[x0,y0]);for i = 1:length(t) plot(x(i,1),x(i,2),'o') pause(0.05);end
 

1. What is a phase portrait?

A phase portrait is a graphical representation of the behavior of a dynamical system over time. It shows how the variables in the system change and interact with each other.

2. How do you make a phase portrait?

To make a phase portrait, you first need to have an equation that describes the system. Then, you plot the variables of the system on a graph, with one variable on the x-axis and the other on the y-axis. You then use arrows or color-coding to represent the direction and magnitude of change in the system.

3. What information can be gained from a phase portrait?

A phase portrait can provide insights into the behavior of a system, such as whether it is stable or unstable, if it has any fixed points or limit cycles, and how it responds to changes in initial conditions.

4. What are the benefits of creating a phase portrait?

Creating a phase portrait allows for a visual and intuitive understanding of a system's behavior. It can also help in identifying patterns and making predictions about the behavior of the system.

5. Can a phase portrait be used for any type of equation?

No, a phase portrait is typically used for systems of differential equations. It may also be used for other types of equations that describe the behavior of a system over time, such as difference equations.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
952
  • MATLAB, Maple, Mathematica, LaTeX
Replies
18
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
Replies
1
Views
514
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
Back
Top