Extract Value from ODE45

4 views (last 30 days)
BINAY NAYAK
BINAY NAYAK on 16 Mar 2022
Commented: BINAY NAYAK on 17 Mar 2022
I am Using below code to plot 2 graphs using ODE45. However I want to know a particular value of "t" at y(2) = 0.1
Is it possible?
%For plots
[t,y] = ode45(@odefun3,[0:0.1:50],[300; 2]);
plot(t,y(:,1))
plot(t,y(:,2))
function dydt = odefun3(t,y)
dydt = zeros(2,1);
dydt(1) = 125*0.01725*exp(-2660*(1/y(1)-1/300))*y(2)^2;
dydt(2) = -0.01725*exp(-2660*(1/y(1)-1/300))*y(2)^2;
end

Answers (1)

Walter Roberson
Walter Roberson on 16 Mar 2022
No, you can only interpolate the position, as there is no t value at which y(:,2) is exactly 0.1.
%For plots
[t,y] = ode45(@odefun3,[0:0.1:50],[300; 2]);
plot(t,y(:,1))
plot(t,y(:,2))
format long g
t01 = interp1(y(:,2), t, 0.1, 'spline')
t01 =
19.8851354380905
function dydt = odefun3(t,y)
dydt = zeros(2,1);
dydt(1) = 125*0.01725*exp(-2660*(1/y(1)-1/300))*y(2)^2;
dydt(2) = -0.01725*exp(-2660*(1/y(1)-1/300))*y(2)^2;
end

Tags

Community Treasure Hunt

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

Start Hunting!