Matlab 求解应用于状态空间系统的 ODE,输入与时间相关

发布于 2024-12-29 11:02:08 字数 1230 浏览 1 评论 0原文

我在状态系统中,在边界上有“强制”输入。我的SS方程是:zp = A*z * B。(A是方阵,B列)

如果B是一个步骤(沿着经验的时间),没有问题,因为我可以使用

  tevent = 2;
  tmax= 5*tevent;

  n =100;
  dT = n/tmax;
  t = linspace(0,tmax,n);
  u0 = 1 * ones(size(z'));
  B = zeros(nz,n);
  B(1,1)= utop(1)';
  A = eye(nz,nz);

  [tt,u]=ode23('SS',t,u0);

,SS是:

  function zp = SS(t,z)
          global A B
          zp = A*z + B;
  end

我的问题是当我应用斜坡时,所以 B 将取决于时间。

  utop_init= 20;
  utop_final = 50;
  utop(1)=utop_init;
  utop(tevent * dT)=utop_final;

  for k = 2: tevent*dT -1
      utop(k) = utop(k-1) +(( utop(tevent * dT) - utop(1))/(tevent * dT));
  end

  for k = (tevent * dT) +1 :(tmax*dT)
      utop(k) = utop(k-1);
  end

  global A B
  B = zeros(nz,1);
  B(1,1:n) = utop(:)';
  A = eye(nz,nz);

我写了一个新的方程(试图解决),这个问题,但我无法调整“时间步长”,并且我没有得到 22x100 的 au (这是目标)。

  for k = 2 : n
  u=solveSS(t,k,u0);
  end

SolveSS有代码:

function [ u ] = solveSS( t,k,u0)

  tspan = [t(k-1) t(k)];

  [t,u] = ode15s(@SS,tspan,u0);

      function zp = SS(t,z)
          global A B
          zp = A*z + B(:,k-1);
      end

  end

希望对你有帮助!

I've got at State System, with "forced" inputs at bounds. My SS equation is: zp = A*z * B. (A is a square matrix, and B colunm)

If B is a step (along the time of experience), there is no problem, because I can use

  tevent = 2;
  tmax= 5*tevent;

  n =100;
  dT = n/tmax;
  t = linspace(0,tmax,n);
  u0 = 1 * ones(size(z'));
  B = zeros(nz,n);
  B(1,1)= utop(1)';
  A = eye(nz,nz);

  [tt,u]=ode23('SS',t,u0);

and SS is:

  function zp = SS(t,z)
          global A B
          zp = A*z + B;
  end

My problem is when I applied a slop, So B will be time dependent.

  utop_init= 20;
  utop_final = 50;
  utop(1)=utop_init;
  utop(tevent * dT)=utop_final;

  for k = 2: tevent*dT -1
      utop(k) = utop(k-1) +(( utop(tevent * dT) - utop(1))/(tevent * dT));
  end

  for k = (tevent * dT) +1 :(tmax*dT)
      utop(k) = utop(k-1);
  end

  global A B
  B = zeros(nz,1);
  B(1,1:n) = utop(:)';
  A = eye(nz,nz);

I wrote a new equation (to trying to solve), the problem, but I can't adjust "time step", and I don't get a u with 22x100 (which is the objective).

  for k = 2 : n
  u=solveSS(t,k,u0);
  end

SolveSS has the code:

function [ u ] = solveSS( t,k,u0)

  tspan = [t(k-1) t(k)];

  [t,u] = ode15s(@SS,tspan,u0);

      function zp = SS(t,z)
          global A B
          zp = A*z + B(:,k-1);
      end

  end

I hope that you can help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

屌丝范 2025-01-05 11:02:08

您应该定义一个随 t 不断变化的函数 B 并将其作为函数句柄传递。这样,您将允许 ODE 求解器有效地调整时间步长(您使用 ode15s,一个僵硬的 ODE 求解器,表明可变时间步长更为重要)

代码的形式将类似于这:

function [ u ] = solveSS( t,k,u0)

    tspan = [t(k-1) t(k)];

    [t,u] = ode15s(@SS,tspan,u0,@B);

        function y = B(x)
            %% insert B calculation
        end

        function zp = SS(t,z,B)
            global A
            zp = A*z + B(t);
        end

    end

You should define a function B that is continuously varying with t and pass it as a function handle. This way you will allow the ODE solver to adjust time steps efficiently (your use of ode15s, a stiff ODE solver, suggests that variable time stepping is even more crucial)

The form of your code will be something like this:

function [ u ] = solveSS( t,k,u0)

    tspan = [t(k-1) t(k)];

    [t,u] = ode15s(@SS,tspan,u0,@B);

        function y = B(x)
            %% insert B calculation
        end

        function zp = SS(t,z,B)
            global A
            zp = A*z + B(t);
        end

    end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文