matlab - 求解和绘制分段 ODE

标签 matlab plot ode piecewise periodicity

我有一个函数dφ/dt = γ - F(φ) (其中 F(φ) -- a 是 -周期函数)和函数图 F(φ) .
我需要创建一个输出 φ(t) 的 6 个图的程序对于 γ 的不同值(γ = 0.10.50.951.0525)和t∈[0,100] .
这是 F(φ) 的定义功能:

      -φ/a - π/a,    if φ ∈ [-π, -π + a]
      -1,            if φ ∈ [-π + a, - a] 
F(φ) = φ/a,          if φ ∈ [- a, a]
       1,            if φ ∈ [a, π - a]
      -φ/a + π/a,    if φ ∈ [π - a, π]
                 ^ F(φ)
                 |
                 |1   ______
                 |   /|     \
                 |  / |      \
                 | /  |       \      φ
__-π_______-a____|/___|________\π____>
   \        |   /|0    a
    \       |  / |
     \      | /  |
      \     |/   |
       ¯¯¯¯¯¯    |-1
我的问题是我不知道要给出什么输入 ode45就边界和初始条件而言。我所知道的是 φ(t) 的演变必须是连续的。
这是 γ = 0.1 案例的代码:
hold on;
df1dt = @(t,f1) 0.1 - f1 - 3.14;
df2dt = @(t,f2)- 1;
df3dt = @(t,f3) 0.1 + f3;
df4dt = @(t,f4)+1;
df5dt = @(t,f5) 0.1 - f5 + 3.14;
[T1,Y1] = ode45(df1dt, ...);
[T2,Y2] = ode45(df2dt, ...);
[T3,Y3] = ode45(df3dt, ...);
[T4,Y4] = ode45(df4dt, ...);
[T5,Y5] = ode45(df5dt, ...);
plot(T1,Y1);
plot(T2,Y2);
plot(T3,Y3);
plot(T4,Y4);
plot(T5,Y5);
hold off; 
title('\gamma = 0.1')

最佳答案

我们先定义F(φ,a) :

function out = F(p, a)
phi = mod(p,2*pi);
out = (0      <= phi & phi < a     ).*(phi/a) ...
    + (a      <= phi & phi < pi-a  ).*(1) ...
    + (pi-a   <= phi & phi < pi+a  ).*(-phi/a + pi/a) ...
    + (pi+a   <= phi & phi < 2*pi-a).*(-1) ...
    + (2*pi-a <= phi & phi < 2*pi  ).*(phi/a - 2*pi/a);
end
对于一些示例输入给出:
enter image description here
使用绘图代码:
x = linspace(-3*pi, 3*pi, 200);
a = pi/6;

figure(); plot(x,F(x, a));
xlim([-3*pi,3*pi]);
xticks(-3*pi:pi:3*pi);
xticklabels((-3:3)+ "\pi");
grid on; grid minor
ax = gca;
ax.XAxis.MinorTick = 'on';
ax.XAxis.MinorTickValues = ax.XAxis.Limits(1):pi/6:ax.XAxis.Limits(2);
从那里您无需再为范围而烦恼,只需调用 ode45 :
% Preparations:
a = pi/6;
g = [0.1, 0.5, 0.95, 1.05, 2, 5]; % γ
phi0 = 0; % you need to specify the correct initial condition (!)
tStart = 0;
tEnd = 100;
% Calling the solver:
[t, phi] = arrayfun(@(x)ode45(@(t,p)x-F(p,a), [tStart, tEnd], phi0), g, 'UniformOutput', false);
% Plotting:
plotData = [t; phi];
figure(); plot(plotData{:});
legend("γ=" + g, 'Location', 'northwest');
导致:
enter image description here

关于matlab - 求解和绘制分段 ODE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65377717/

相关文章:

matlab - 从二值图像中去除噪声

plot - 在图中指定 Axis 的步长

python - 求解具有 f (x) 数值但没有解析表达式的颂歌 y'=f (x)

python - 如何在 python 上解决 TISE 的简单边值问题

matlab - 在matlab中只获取第二个返回值?

python - 相当于python中Matlab的gaminv

Matlab:检查字符串是否具有正确的文件路径语法

javascript - 使用 Highcharts 的 XY 轨迹图

c# - Oxyplot 不在 WPF View 中显示绘图

matlab - 求解微分方程需要大量时间