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
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?
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!