Function Matlab中带控制器的四阶Runge-Kutta函数

Function Matlab中带控制器的四阶Runge-Kutta函数,function,matlab,controller,runge-kutta,Function,Matlab,Controller,Runge Kutta,我试图用四阶龙格-库塔方法求解函数('f')中定义的方程组,同时考虑变量('c')上的PD控制器 到目前为止,我的代码是这样的: t_f = 100; % simulation end time h = 0.1; % sample time K = 1; % controller gain Td = 10; % controller derivative time x = [...]; % initial conditions N = round(t_f/h); %

我试图用四阶龙格-库塔方法求解函数('f')中定义的方程组,同时考虑变量('c')上的PD控制器

到目前为止,我的代码是这样的:

 t_f = 100; % simulation end time
 h = 0.1;   % sample time
 K = 1;     % controller gain
 Td = 10;   % controller derivative time
 x = [...]; % initial conditions
 N = round(t_f/h); % number of samples
 xout = zeros(N+1,length(x)+2); % memory allocation

 for i=1:N+1
     time = (i-1)*h; % simulation time
     a = x(1);
     if (a<10)
        a_ref = 1; % desired 'a' value
        c = K*((a-a_ref)+Td); % controller

 [x v] = RK4('f',x,[c 0],h,i);
 xout(i,:) = [time,x',v]
运行主脚本时,将在for循环中以“s1=…”开头的行返回错误:

Subscript indices must either be real positive integers or logicals.
另外,我不确定控制器输入是否需要包含在这个函数中

对不起,如果这是直截了当的,但我正在努力让我的头围绕它

谢谢

编辑2:

可以找到该代码的最新版本。 主循环在Tacking.m(调用其他函数)中,龙格-库塔积分在RK4.m中

我尝试过几种公式,但正如你所看到的,我不确定在这种情况下如何正确地编写

注意:所有其他函数以前都使用过,我需要排序的是“解算器”


欢迎任何帮助。谢谢

看一看,谢谢杰伦。考虑到你的链接,我编辑了我的帖子。正如您所看到的,我正在努力正确地编写函数。干杯。你有没有用一个简单的测试示例来测试你的集成例程,比如f(x,y)=x,f(x,y)=y或类似的?显示你的函数f,因为这可能是问题所在。谢谢@LutzL。代码是。主循环在Tacking.m中,Runge-Kutta函数在RK4.m中。我知道这段代码在过去曾被使用过,但我正在努力正确编写RK4函数。谢谢
Subscript indices must either be real positive integers or logicals.