Can anyone help with why my function is not working?

1 view (last 30 days)
I am trying to solve this ODE. The problem is that one of the inputs is discrete data that I am generating from a matlab toolbox. I took this discrete data (2000x2) and turned it into a vector. I tried making a function which will output the right value from the vector depending on the time t (derivheight.m). However, when I use this function with ode45 (SolveDiff.m), I get this error code:
Array indices must be positive integers or logical values.
Error in derivheight (line 10)
hw = e(t);
Error in SolveDiff>WaveHeight (line 33)
dxdt = [x(2);
(-p*ap*Len*H2(t)-(p/2)*ap*(derivheight(t,2000,0.1,2,6)+x(2))^2-p*gc*ap*H(t)-(((p*ap)/2)*(K+ff*Len/dt)*((ap/dt)*x(2))*abs((ap/dt)*x(2)))-gamma*x(2)-sign(x(2))*frict-k*x(1)-mp*gc)/(mp+p*ap*(Len*ap/dt))];
Does anyone know if there is a proper way to do what I am trying to do? I think I essentially want to transform discrete data into a function or continuous data which ode45 can use.
Thank you in advance,
  4 Comments
James Tursa
James Tursa on 21 Sep 2020
Sorry, I was not explicit enough. You should supply a continuous interpolated value, not a value that has discrete jumps. I.e., fit a curve through that discrete data and then use that fitted curve in ode45 instead of your discrete data ... if this makes sense for your problem, that is. If you really need your inputs to take discrete jumps, then you will need to effectively break up your integration into multiple phases.
Steven Trvalik
Steven Trvalik on 22 Sep 2020
Okay, thank you for your help. I tried this with the spline() and csapi() functions but neither of them work. They both supply discrete data once again. Do you know if there is an easy way to fit a curve to data in matlab which will work for this purpose? My data is time-series wave height data which roughly takes the form of a sine wave.
Thanks again

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!