![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/960810/image.png)
How To Plot Directional Field of 2nd Order Differential Equation IVP
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jordan Stanley
el 11 de Abr. de 2022
Comentada: Jordan Stanley
el 11 de Abr. de 2022
Hello,
I have the second order differential equation initial value problem, y'' + 2y' + y = 0, y(-1) = 0, y'(0) = 0.
In MATLAB, I need to plot the directional field of the solution to the equation without the initial conditions.
I have used the meshgrid() command so far and know that I have to use the quiver() command but I don't know how to enter what I need as parameters to plot the solution.
Here is what I have so far...
% Finds solution to the DE
syms y(x)
Dy = diff(y);
D2y = diff(y,2);
ode = D2y + 2*Dy + y == 0;
ySol = dsolve(ode)
% Sets up directional field
[x,y]=meshgrid(-3:0.3:3,-2:0.3:2);
quiver() %Not sure what to include here.
Any help is appreciated!
0 comentarios
Respuesta aceptada
Sam Chak
el 11 de Abr. de 2022
Editada: Sam Chak
el 11 de Abr. de 2022
Basically, it should look something like this:
[X, Y] = meshgrid(-3:6/14:3, -3:6/14:3);
U = Y; % x1' = y'
V = - 2*Y - X; % x2' = y'' = - 2*y' - y
quiver(X, Y, U, V)
% quiver(X, Y, U, V, 1.5) % can adjust arrow size
xlabel('x')
ylabel('y')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/960810/image.png)
3 comentarios
Sam Chak
el 11 de Abr. de 2022
Editada: Sam Chak
el 11 de Abr. de 2022
Well, the ODE can be rewritten in the form of a state-space representation.
Begin by defining
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/960880/image.png)
Taking the time derivative yields
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/960885/image.png)
Rewritting the dynamics in system states
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/960890/image.png)
Back to quiver function, this quiver(X, Y, U, V) command plots arrows with directional components U and V at the Cartesian coordinates specified by the grid of X and Y values.
The directional components U and V mean the motion of the the point
that extends horizontally according to U vector, and extends vertically according to V vector. Naturally, these imply the first-order equations. So, if we assign
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/960895/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/960900/image.png)
then
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/960905/image.png)
Hope this explanation is helpful for you to plot the direction field of the desired ODEs.
Más respuestas (0)
Ver también
Categorías
Más información sobre Numerical Integration and Differential Equations en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!