1

I have the following code:

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

Where NRK=NRK(function , numeric scalar) This was the symbolic implementation, with f=symbolic function, and x a symbolic array of unknowns.

The thing is that working with symbolic expressions can solve the issue, but this goes inside a loop, and symbolic tools slow down suprisingly the performance in a ratio of 100 times! However, anonymous functions do a perfect job.

My try was the following:

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));

How can I write these arguments? Is it possible?

p.s.w.g
  • 146,324
  • 30
  • 291
  • 331

1 Answers1

0

You can specify them in the parenthesis:

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

Then call

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

Some remarks:
- You do not need to write an extra @ when providing h to NRK, since h is already defined as a function handle.
- It is best not to use i as a variable name in Matlab.

Community
  • 1
  • 1
Shai
  • 111,146
  • 38
  • 238
  • 371