How can I adjust the slope field for my DE?
2 views (last 30 days)
Show older comments
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)')
0 Comments
Answers (1)
Abhijeet
on 6 Apr 2023
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
0 Comments
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!