Extract Value from ODE45
5 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
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')
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 Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!