如何将两个值归因于一个参数,以使时间依赖于时间

2 views (last 30 days)
在此我的附件代码中,我想改变伽马的值,以使其取决于驱动程序中的TSPAN。
当tspan < = 7γequal to 0.001 as show in the attached code
but when tspan is >7 gamma should be equal to 1.
find attach the code and the driver used for runing the code.
谢谢

答案(2)

Fabio Freschi
Fabio Freschi on 2 Sep 2021
You can pass an extra parameter to RiceG1 function using an anonmymous function. In your driver function add
% extra anonimous function to pass tspan
myfun = @(t,y)RiceG1(t,y,tspan);
% call to ode45
[b,v] = ode45(myfun,tspan,y0);
Then modify RiceG1 to accept the extra parameter and make the choice. I write below an extract of the function
功能dy = riceg1(〜,y,tspan)
%...
iftspan(2) <= 7
gamma = 0.001;
else
γ= 1;
end
我认为必须在TSPAN(2)上进行检查。修改后的文件已连接。

Walter Roberson
Walter Roberson on 2 Sep 2021
不幸的是,法比奥的建议将行不通。当您在计算过程中更改伽马时,您会在集成的函数的导数中引入不连续性,并且当您患有这样的不连续性时,ODE45的数学变得无效。您需要停止集成并重新开始,但要以不同的伽马价值开始。
You should, however, use the technique of passing in an additional parameter -- but it should be gamma directly, not tspan.
Y0 = [1200 400 60 30 30 30 30 30 20 10 3000 30000];
tspan1 = [0 7];
tspan2 = [7 15];
γ1= 0.001;
gamma2 = 1;
funs = {@RiceG1, @RiceG2, @RiceG3, @RiceG4, @RiceG5};
forK = 1 : length(funs)
[t_out1,y_out1] = ode45(@(t,y)有趣{k}(t,y,gamma1),tspan1,y0);
[t_out2, y_out2] = ode45(@(t,y)funs{K}(t,y,gamma2), tspan2, y_out1(end,:));
t_out {k} = [t_out1;t_out2];
y_out {k} = [y_out1;y__out2];
end
[B, C, D, E, F] = deal(t_out{:});
[V, W, X, Y, Z] = deal(y_out{:});
3 Comments

Sign in to comment.

Tags

s manbetx 845


发布

R2018A

Community Treasure Hunt

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

开始狩猎!