How do I plot a direction field for x'=y and y'=-sinx?

3 次查看(过去 30 天)
I have tried:
[x,y] = meshgrid(-5,5:-5,5);
x=-5:.1:5;
y=-sin(x);
u=x;
v=y;
quiver(x,y,u,v)
  2 个评论
Dyuman Joshi
Dyuman Joshi 2023-11-8
"x'=y and y'=-sinx"
What does this mean? Are those differential equations?
Also, you initialize x and y using meshgrid, but you over-write them in the next lines. Which values are the correct ones?
Sophie
Sophie 2023-11-8
I need to plot a direction field for the given planar autonomous system, and those are the equations for the system. I do not really know how to use matlab so I'm not sure which values are the correct one? I think what I was supposed to do is create a new variable when inputting the actual equation part?

请先登录,再进行评论。

采纳的回答

Taylor
Taylor 2023-11-8
编辑:Taylor 2023-11-8
% Define the range of x and y values
x = linspace(-pi, pi, 20);
y = linspace(-2, 2, 20);
% Create a grid of x and y values
[X, Y] = meshgrid(x, y);
% Calculate the derivatives dx/dt and dy/dt
dXdt = Y;
dYdt = -sin(X);
% Plot the direction field
quiver(X, Y, dXdt, dYdt);
xlabel('x');
ylabel('y');
title('Direction Field');
% Adjust the aspect ratio and grid
axis tight;
grid on;
If you're not feeling comfortable with MATLAB I recommend the free MATLAB Onramp courseto get started!

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by