How to find my ode45 equation in specific h

조회 수: 3 (최근 30일)
esat gulhan
esat gulhan 2020년 8월 20일
편집: Alan Stevens 2020년 8월 21일
syms D g H Do
tspan = [0 120];
mgiren=0
Do=3;
D=2/10;
h0=h;
g=9.81;
y0 = 2;
ySol= ode45(@(t,h)(mgiren-(pi()*D^2/4*(2*g*h)^0.5)/(pi()*Do^2/4)), tspan, y0)
for t=linspace(0,100,11)
fprintf('%15.5f',t,deval(ySol,t)),;fprintf('\n')
end
My differantial code is here, dt/dh=(mgiren-(pi()*D^2/4*(2*g*h)^0.5)/(pi()*Do^2/4)),h(0)=2, h(tx)=1, how can i find tx, is there anyway to find tx, i can find it with interpolate but is there any easier way.

채택된 답변

Alan Stevens
Alan Stevens 2020년 8월 21일
편집: Alan Stevens 2020년 8월 21일
Something like this perhaps:
tspan = 0:120;
h0=2;
[t, h] = ode45(@rate, tspan, h0);
tx = interp1(h,t,1);
plot(t,h,tx,1,'o'), grid
text(tx+5,1,['tx = ' num2str(tx)])
xlabel('t'),ylabel('h')
function dhdt = rate(~, h)
mgiren=0;
Do=3;
D=2/10;
g=9.81;
dhdt = (mgiren-(pi*D^2/4*(2*g*h)^0.5)/(pi*Do^2/4));
end
Ok, I guess this still uses interpolation!
You could use fzero to find it, but, for this curve I think interpolation is far simpler.
  댓글 수: 3
Alan Stevens
Alan Stevens 2020년 8월 21일
Tht's because you can't get to zero with the data specified. There is an analytical solution to your equation, which is most easily expressed with t as a function of h - see below. You'll notice there is a logarithmic term, which tries to calculate log(0) when both mgiren and h are zero.
tspan = 0:120;
h0=2;
mgiren=0;
Do=3;
D=2/10;
g=9.81;
a = mgiren/(pi*Do^2/4);
b = (D/Do)^2*sqrt(2*g);
T = @(h) -2*(b*sqrt(h) + a*log(a-b*sqrt(h)))/b^2 ...
+ 2*(b*sqrt(h0) + a*log(a-b*sqrt(h0)))/b^2;
h = h0:-0.01:0.01;
t = T(h);
plot(t,h), grid
xlabel('t'), ylabel('h')
Alan Stevens
Alan Stevens 2020년 8월 21일
편집: Alan Stevens 2020년 8월 21일
Hmm. Thinking further, the log term is zeroed all the way through because it's multiplied by a (which is zero)., so, basically, you just have a square root relationship (when a is zero).
You get NaN if you try T(0).
T(h = 0) can be found from 2*sqrt(h0)/b;

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by