Timespan within Ode45
이전 댓글 표시
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
2021년 2월 18일
Did you try for loop to get several solutions?
Dylan Lawley
2021년 2월 18일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!