MATLAB Answers

How to find my ode45 equation in specific h

1 view (last 30 days)
esat gulhan
esat gulhan on 20 Aug 2020
Edited: Alan Stevens on 21 Aug 2020
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.

Accepted Answer

Alan Stevens
Alan Stevens on 21 Aug 2020
Edited: Alan Stevens on 21 Aug 2020
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 Comments
Alan Stevens
Alan Stevens on 21 Aug 2020
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;

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!