Timespan within Ode45

4 Ansichten (letzte 30 Tage)
Dylan Lawley
Dylan Lawley am 18 Feb. 2021
Kommentiert: Dylan Lawley am 18 Feb. 2021
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 Kommentare
darova
darova am 18 Feb. 2021
Did you try for loop to get several solutions?
Dylan Lawley
Dylan Lawley am 18 Feb. 2021
I thought that might be how to solve it but dont know how to implament it properly.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

darova
darova am 18 Feb. 2021
  • 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 Kommentar
Dylan Lawley
Dylan Lawley am 18 Feb. 2021
thank you that helps a lot

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by