Returning several dataset using ode45
1 次查看(过去 30 天)
显示 更早的评论
Hi. I have a problem where I want an ode45 function to return 5 dataset using the code
clc; clear; close all;
% Defining parameters and initial conditions
f = 0.35;
r = [0.3:0.3:1.5];
zeta = 0.25;
Theta0 = [0.30, 0];
tspan = [0 10];
% Solver options
opts = odeset('RelTol',1e-6,'AbsTol',[1e-9 1e-9]);
% Solver
[t,theta] = ode45(@(t,theta) odefcn(t,theta,f,r,zeta), tspan, Theta0);
plot(theta(:,1),theta(:,2));
As you can see, r is a parameter in the function and I want to create a plot for each of the values for r. The code is running fine when using a single value for r but breaks when using a vector.
0 个评论
采纳的回答
VBBV
2021-12-7
for i = 1:length(r)
[t,theta] = ode45(@(t,theta) odefcn(t,theta,f,r,zeta), tspan,Theta0);
plot(theta(:,1),theta(:,2));hold on;
end
Use a for loop and try it
3 个评论
更多回答(0 个)
另请参阅
类别
在 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!