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 CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by