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 xa 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?
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 .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.