How can I adjust the slope field for my DE?

조회 수: 2 (최근 30일)
Anthony Aquino
Anthony Aquino 2023년 3월 14일
답변: Abhijeet 2023년 4월 6일
I am currently learning about differential equations and their slope fields. I have a program that allows me to plot this, however, I am having difficulties adjusting the arrows since I am using an unusual equation. How should I adjust the program to work for my DE? I am new to MATLAB so I would appreciate if someone could explain my errors and how to fix them. This is what I have:
[x,y]=meshgrid(-0.1:0.05:1136.15, -0.1:0.05:7);
dy = -((0.1)^2/sqrt(10)^2)*sqrt(2*9.8*y); %Plug in equation
norm=sqrt(dy.^2+1^2);
quiver(x,y,ones(size(x))./norm,dy./norm,1);
xline(0), yline(0)
hold on
f=@(x,y) -((0.1)^2/sqrt(10)^2)*sqrt(2*9.8*y); %Plug in equation
[x,y]=ode45(f,[0 1136.15], 2*sqrt(10));
y(y<0)=nan;
plot(x,y,'lineWidth',1)
xline(0), yline(0)
title('Directional Graph of DE')
xlabel('Time (min)'), ylabel('Water Level (m)')

답변 (1개)

Abhijeet
Abhijeet 2023년 4월 6일
Hi,
The "quiver" function allows you to plot vector fields, which can be useful when graphing solutions to differential equations. If you're having difficulty adjusting the arrows, you may want to try adjusting the scaling factor in the "quiver" function, which determines the length of the arrows. You can also try changing the step size in the "meshgrid" function to make the arrows closer together or further apart.
% Changing the scaling factor to 0.5 and changing the colors in quiver function
quiver(x,y,1./norm,dy./norm,0.5,'Color',[0 0.5 1]);
Another thing to keep in mind is that the direction of the arrows in the vector field should match the direction of the solutions to the differential equation. In your code, the differential equation is dy = -((0.1)^2/sqrt(10)^2)*sqrt(2*9.8*y), which means that the slope of the solutions is negative. This should be reflected in the direction of the arrows in the vector field.
Hope this will help you resolve your query.
Thanks

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by