Need help plotting a set of differential equations.

1 回表示 (過去 30 日間)
Adriel Martinez-Alvarez
Adriel Martinez-Alvarez 2017 年 4 月 24 日
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:
  1 件のコメント
John Chilleri
John Chilleri 2017 年 4 月 24 日
You need initial conditions, but I'll attach a version with arbitrary initial conditions in a minute.

サインインしてコメントする。

採用された回答

John Chilleri
John Chilleri 2017 年 4 月 24 日
Hello,
You can use the built-in ode45 function to solve this:
clear all
close all
clc
%
% 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
figure(1)
hold on
plot(tout,hout(:,1),'r')
plot(tout,hout(:,2),'b')
title('Differential Equations Example')
xlabel('t')
ylabel('h')
legend('h_{tor}','h_{prop}')
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;
end
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!
  1 件のコメント
Adriel Martinez-Alvarez
Adriel Martinez-Alvarez 2017 年 4 月 24 日
Wow, that helps a lot! Thank you so much!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by