首页 > 解决方案 > 为什么使用 ODE 系统在八度音阶中给出语法错误

问题描述

这似乎是我的 ODE 系统特别是 xdot(2) 的解析/语法错误。但我无法弄清楚

我在 StackOverflow 中检查了类似的问题,但我没有找到我的解决方案

function xdot = f3(x, t)
      xdot =zeros(2, 1);
      x=zeros(1, 2);

      r_1=4;
      R_1=1;
      p_1=8;
      l_1=0.2;
      r_2=10;
      p_2=10;
      R_2=2;
      l_2=50;
      rM= 0.01;
      d=2;

      xdot(1)= ((r_1*p_1*x(3))/(1+p_1*x(3)))*x(1)-r_1*x(1)^2-(R-1*x(1))/(1+r_1*x(3)-x(1)*x(2)
      xdot(2)= rM + ((r_2*p_2*x(3))/(1+p_2*x(3)))*x(2)-r_2*x(2)^2-(R_2*x(2))/(1+p_2*x(3))
      xdot(3)= d - (l_1*r_1*x(1))/(1+p_1*x(2))-(l_2*r_2*x(2)/(1+r_2*x(3))
endfunction

x0 = [1; 0; -1];
t = linspace(0, 2, 201);
x = lsode (@f3, x0, t);

figure(1);
plot(t, x(:,1));
xlabel('t');
ylabel('X');
title('X - component');


figure(2);
plot(t, x(:,2));
xlabel('t');
ylabel('Y');
title('Y - component');

应该解决系统颂歌但给我

f3

parse error near line 18 of file C:/Users/Admin/Desktop\f3.m

syntax error

>>>   xdot(2)= rM + ((r_2*p_2*x(3))/(1+p_2*x(3)))*x(2)-r_2*x(2)^2- 
(R_2*x(2))/(1+p_2*x(3))

     ^

标签: syntaxsystemoctaveode

解决方案


那里似乎有几个问题。

  1. 您正在创建大小为 2 的 xdot 和 x 值,但在索引 3 处访问/设置。

  2. 为了xdot(1)= ((r_1*p_1*x(3))/(1+p_1*x(3)))*x(1)-r_1*x(1)^2-(R-1*x(1))/(1+r_1*x(3)-x(1)*x(2)

    a)您缺少导致语法错误的“)”。

    b)这R-1是不正确的 - 你没有'R'所以它可能意味着R_1

  3. xdot(3)= d - (l_1*r_1*x(1))/(1+p_1*x(2))-(l_2*r_2*x(2)/(1+r_2*x(3))中,您缺少一个 ')'


推荐阅读