Timespan within Ode45

11 ビュー (過去 30 日間)
Dylan Lawley
Dylan Lawley 2021 年 2 月 18 日
コメント済み: Dylan Lawley 2021 年 2 月 18 日
Hi there,
I'm writing code to try solve some differential equations.
function Output = example_3(m0,mEnd) % m0 = range of 1000 to 1500 and mEnd = range of 100 to 500 as an example
g0 = 9.81;
Isp = 390;
mdot = 5;
c = Isp.*g0;
mf = m0 - mEnd;
T = mdot .* Isp * g0;
tbo = mf./mdot;
T_Range =[0,tbo];
Y_01 = [0;0];
[tSol_1,YSol_1] = ode45(@deri_Y,T_Range,Y_01);
v_1 = YSol_1(:,1);
h_1 = YSol_1(:,2);
Output = [max(v_1), max(h_1)];
function dYdt = deri_Y(t,Y)
v = Y(1);
h = Y(2);
dvdt = c.*mdot./(m0 - mdot.*t) - g0;
dhdt = v;
dYdt = zeros(size(Y));
dYdt(1) = dvdt;
dYdt(2) = dhdt;
end
end
the function works for single inputs of m0 and mEnd but I would like the function to run for a range of m0 and mEnd values and because of this the value of tbo changes each time and I get an error saying:
"Unable to perform assignment because the left and right sides have a different number of elements.
Error in example_3/deri_Y (line 53)
dYdt(1) = dvdt;
Any help is greatly appreciated.
  2 件のコメント
darova
darova 2021 年 2 月 18 日
Did you try for loop to get several solutions?
Dylan Lawley
Dylan Lawley 2021 年 2 月 18 日
I thought that might be how to solve it but dont know how to implament it properly.

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

採用された回答

darova
darova 2021 年 2 月 18 日
  • change heade of a function
function dYdt = deri_Y(t,Y,m0)
  • call the function
for m0 = [0.4 0.5 1]
[tSol_1,YSol_1] = ode45(@(t,y) deri_Y(t,y,m0),T_Range,Y_01);
line(tSol_1,YSol_1(:,1))
end
  1 件のコメント
Dylan Lawley
Dylan Lawley 2021 年 2 月 18 日
thank you that helps a lot

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

その他の回答 (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