0

I am trying to solve an ODE using ode45 as

[eta_ode_i, fg_ode_i] = ode45(@UVWTI,eta,FI,options); 

My function however depends parametrically on a precalculated array as follows

function [dfi]=UVWTI(t,fi)

dfi=zeros(7,1);

dfi(1)=A11(t)*fi(1)+A12(t)*fi(2)+A13(t)*fi(3)+A14(t)*fi(4)+A15(t)*fi(5)+A16(t)*fi(6)+A17(t)*fi(7);
...
dfi(7)=similar

end

A11, A12, etc are arrays with a length say K. However, since I don't know in advance what t is ode45 going to take internally, it's impossible for me to know what element of A11 I should use. Shall I interpolate? Should work but I wonder if there is a simpler method.

Hans
  • 361
  • 1
  • 3
  • 9
  • You should definitely consider using a simpler method, as what you are doing now with your `A11`, `A12` etc variables is called "dynamic variable naming", [which is considered bad for a plethora of reasons](https://stackoverflow.com/a/32467170/5211833). Also, we need more info on what everything looks like, i.e. produce a [mcve] which we can actually copy and run ourselves. – Adriaan Feb 10 '20 at 15:50
  • Do you know how to do the interpolation? There is likely no simpler method. The most efficient would be if all the A values are interpolated at once, that the interpolation function is vector-valued. – Lutz Lehmann Feb 10 '20 at 15:52

0 Answers0