【问题标题】:Writing the input arguments in an anonymous function in Matlab在 Matlab 的匿名函数中编写输入参数
【发布时间】:2014-04-17 15:32:51
【问题描述】:

我有以下代码:

s(i+1)=NRK(Dt*f(tv(i+1),x)+s(i)-x,s(i));

NRK=NRK(function , numeric scalar) 这是符号实现,f=symbolic 函数,x 是未知数的符号数组。

问题是使用符号表达式可以解决问题,但这会在循环中进行,并且符号工具会以 100 倍的比率惊人地降低性能!但是,匿名函数做得很好。

我的尝试如下:

h=@([arguments (i.e. a, b, c, ...])Dt*f(t(i+1),[arguments (i.e. a, b, c,...])+s(i)-[a b c ...];
s(i+1)=NRK(@h,s(i));

我怎样才能写出这些论点?是否可以?

【问题讨论】:

    标签: matlab input anonymous-function


    【解决方案1】:

    您可以在括号中指定它们:

    h = @( a, b, c ) Dt*f( t(ii+1), a, b, c ) + s(ii);
    

    然后调用

    s(ii+1) = NRK( h, s(ii) );
    

    一些备注:
    - 将h 提供给NRK 时,您无需额外编写@,因为h 已定义为函数句柄。
    - 最好not to use i as a variable name in Matlab

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-08
      相关资源
      最近更新 更多