Extract Value from ODE45

3 次查看(过去 30 天)
BINAY NAYAK
BINAY NAYAK 2022-3-16
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

回答(1 个)

Walter Roberson
Walter Roberson 2022-3-16
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

类别

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