如何生成所需的振荡图?[MATLAB]

如何生成所需的振荡图?[MATLAB],matlab,Matlab,我有一个数学方程,它把一个动力系统描述为 参数定义如下 k1=1; S=1; Kd=1; p=2; tau=10; k2=1; ET=1; Km=1; 我将系统编码为 y(1) = 1; % based on the y-axes starting point in the last figure y(2) = y(1) + k1*S*Kd^p/(Kd^p + y(1)^p) - k2*ET*y(1)/(Km + y(1)); % to avoid errors for t=1:100

我有一个数学方程,它把一个动力系统描述为

参数定义如下

k1=1; S=1; Kd=1; p=2; tau=10; k2=1; ET=1; Km=1;
我将系统编码为

y(1) = 1; % based on the y-axes starting point in the last figure
y(2) = y(1) + k1*S*Kd^p/(Kd^p + y(1)^p) - k2*ET*y(1)/(Km + y(1)); % to avoid errors

for t=1:100
     y(t+1) = y(t+1) + (k1*S*Kd^p/(Kd^p + y(t)^p) - k2*ET*y(t+1)/(Km + y(t+1)));
end
plot(y);
注意,为了简单起见,我没有使用tau=10,而是使用了延迟版本1而不是10(因为我不知道如何插入延迟10)

并得到如下结果

但是,我需要获得这个

有人能帮我纠正代码中的错误吗


提前感谢您。

如果我们假设t<0的Y(t)=0,那么您的代码可以修改以生成类似的图。但是,看起来要生成的绘图使用了不同的初始条件。如果您只是想测量
Tc
,那么信号似乎随着您所寻找的周期而稳定

k1=1; S=1; Kd=1; p=2; tau=10; k2=1; ET=1; Km=1;

% time step size (tau MUST be divisible by dt to ensure proper array indexing)
dt = 0.01;

% time series
t = -10:dt:100;

% initialize y to all zeros so that y(t)=0 for all t<0 (initial condition)
y = zeros(size(t));

% Find starting and ending indexes to iterate from t=0 to t=100-dt
idx0 = find(t == 0);
idx1 = numel(t)-1;

% initial condition y(0) = 1
y(idx0) = 1;
for n = idx0:idx1
    % The indexing used here ensures the following equivalences.
    % y(n+1) = y(t+dt)
    % y(n) = y(t)
    % y(n - round(tau/dt)) = y(t-tau)
    %
    % Note that (y(t+dt)-y(t))/dt is approximately y'(t) 
    % Solving for y(t+dt) we get the following formula
    y(n+1) = y(n) + dt*((k1*S*Kd^p/(Kd^p + y(n - round(tau/dt))^p) - k2*ET*y(n)/(Km + y(n))));
end

% plot y(t) for t > 0
plot(t(t>0),y(t>0));
然后,我更改了脚本以使用此数组作为初始条件,并将初始y值更改为

y = zeros(size(t));
y(1:1001) = init_cond;
然后再次运行修改后的脚本


编辑2:内置功能似乎适用于您的问题。要查看示例,请在命令窗口中运行命令
edit ddex1

对于初学者
y(t+1)=y(t+1)+…
实际上应该是
y(t+1)=y(t)+…
很抱歉,我无法理解这部分内容
鉴于情况稳定,我们可以取其中一个周期中的值,并将其用于初始条件,然后得到。
您能详细说明一下吗?非常感谢您的帮助。
y = zeros(size(t));
y(1:1001) = init_cond;