我有一个参数化 ODE 系统,我想使用 MATLAB 及其ode45求解器来求解,并且想知道是否可以并行执行这样的任务。例如,我有一个火箭在重力下坠落的简单模型,我想尝试不同的参数值tburnstart和tburnend,它告诉程序何时打开和关闭火箭的引擎:
function xdot = equations_of_motion_1D_landing(t, x, G, g, M, Isp, T, tburnstart, tburnend)
if t < tburnstart
xdot = [
x(3); %xdot1: x-velocity
x(4); %xdot2: y-velocity
-(G*M*x(1))/((x(1)^2+x(2)^2)^(3/2)); %xdot3: x-acceleration
-(G*M*x(2))/((x(1)^2+x(2)^2)^(3/2)); %xdot4: y-acceleration
0 %xdot5: engine mass flow rate
];
else if t >= tburnstart && t <= tburnend
xdot = [
x(3); %xdot1: x-velocity
x(4); %xdot2: y-velocity
-(G*M*x(1))/((x(1)^2+x(2)^2)^(3/2)); %xdot3: x-acceleration
-(G*M*x(2))/((x(1)^2+x(2)^2)^(3/2))+(T/x(5)); %xdot4: y-acceleration
-T/(g*Isp) %xdot5: engine mass flow rate
];
else
xdot = [
x(3); %xdot1: x-velocity
x(4); %xdot2: y-velocity
-(G*M*x(1))/((x(1)^2+x(2)^2)^(3/2)); %xdot3: x-acceleration
-(G*M*x(2))/((x(1)^2+x(2)^2)^(3/2)); %xdot4: y-acceleration
0 %xdot5: engine mass flow rate
];
end
end
tburnstart目前,我在主文件中测试并tburnend使用以下代码的不同值:
%Setting up burn start and end times
tmin = 0;
tmax = 200;
tburnstart = (tmax-tmin).*rand(pop_size,1)+tmin; %burn start times
tburnend = (tmax-tburnstart).*rand(pop_size,1) + tburnstart + 10; %burn end times (must be larger than start times) (+10 makes sure tspan has more than 1 element)
pop_init = [tburnstart, tburnend]; %creating intial population
for i = 1:length(pop_init)
tburnstart = pop_init(i,1);
tburnend = pop_init(i,2);
%tspan = [0:tburnend];
tspan = 0:0.1:tburnend;
[t,x] = ode45(@(t,x) equations_of_motion_1D_landing(t, x, G, g, M, Isp, T, tburnstart, tburnend), tspan, xinit);
end
但是,使用 for 循环进行评估ode45非常慢,我想知道是否有一种方法可以同时评估所有参数以节省计算时间。