Need help plotting a set of differential equations.
1 view (last 30 days)
Show older comments
Commented: Adriel Martinez-Alvarez on 24 Apr 2017
I would like to know how to plot 2 differential equations for the height for t= 120 seconds where A = 30 in and K = 1.4. The equations are as follows:
You need initial conditions, but I'll attach a version with arbitrary initial conditions in a minute.
You can use the built-in ode45 function to solve this:
% Initialize time span
tspan = [0 120];
% Set initial conditions
init = [1; 1];
% Initialize constants
A = 30;
K = 1.4;
% Call ode45 to solve differential equations
[tout, hout] = ode45(@hfunctions, tspan, init);
% Plot results
title('Differential Equations Example')
where you also have a function in your directory named hfunctions:
function hdot = hfunctions(~,h)
hdot = 1.4*sqrt(h(1))/30;
hdot(2,1) = 1.4*h(2)/30;
hfunctions solves for the derivative, that is, htor' and hprop'.
The resulting plot (with my arbitrary initial conditions 1 and 1) is,
Hope this helps!
More Answers (0)
Find more on Mathematics 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!