How to plot vectorfield in the phase portrait ..... How to modify the code....

17 visualizzazioni (ultimi 30 giorni)
clear
figure
hold on
epsilon=0.01;omega=0.112;theta=0.14;gamma=2.54;
sys = @(t,x) [-x(1)*(x(1)-theta)*(x(1)-1)-x(2)+omega;epsilon*(x(1)-gamma*x(2))];
[t,xs] = ode45(sys,[0 100],[1 .1]);
plot(xs(:,1),xs(:,2));
x=-0.4:0.01:1.2;
plot(x,x./gamma,'r',x,omega-x.*(x-theta).*(x-1),'m')
hold off
axis([-0.4 1.2 0 0.4])
fsize=15;
set(gca,'XTick',-0.4:0.2:1.2,'FontSize',fsize)
set(gca,'YTick',0:0.1:0.4,'FontSize',fsize)
xlabel('u(t)','FontSize',fsize)
ylabel('v(t)','FontSize',fsize)
hold off
How to plot vectorfield in the phase portrait ..... How to modify the code....

Risposte (1)

Jaswanth
Jaswanth il 10 Apr 2024
Hi,
To add vector field to the phase portrait in MATLAB, ‘meshgrid’ and ‘quiver’ functions can be used. Kindly go through the following step-by-step explanation of the modifications that needs to be done to add vector field:
Generating a Grid for the Vector Field: To display a vector field, we first need a grid of points at which the vectors representing the direction and magnitude of the system's state change will be plotted. This can be achieved using the ‘meshgrid’ function.
[x,y] = meshgrid(-0.4:0.05:1.2, 0:0.025:0.4);
Please refer to following MATLAB documentation to know more about the ‘meshgrid’ function: https://www.mathworks.com/help/matlab/ref/meshgrid.html
Calculating Vector Directions and Magnitudes: For each point on the grid, we calculate the direction and magnitude of the system's state change. This is done by evaluating the differential equations at each grid point. Here, variables ‘u’ and ‘v’ represent the components of the vector field. These components are derived from the system's differential equations, showing how the state variables change at each point in the phase space.
u = -x.*(x-theta).*(x-1)-y+omega;
v = epsilon.*(x-gamma.*y);
Plotting the Vector Field: The ‘quiver’ function is used to plot the vector field. This function takes the grid points (x, y) and the vector components (u, v) as inputs and plots vectors at each grid point. The vectors' direction and length visually represent the direction and magnitude of the system's state change. The 'k' argument specifies the color of the vectors (black).
quiver(x, y, u, v, 'k');
Please refer to following MATLAB documentation to know more about the ‘quiver’ function: https://www.mathworks.com/help/matlab/ref/quiver.html
Please refer to the image below, which shows the results of the modified code.
I hope that the information provided above is helpful in accomplishing your task.
Regards,
Jaswanth Buddha

Categorie

Scopri di più su Vector Fields in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by