Can anyone help with why my function is not working?
Show older comments
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
on 21 Sep 2020
Edited: James Tursa
on 21 Sep 2020
If you have discrete data, then you will need to interpolate it for ode45 to use. I.e., everywhere you would use this descrete data you should instead use an interpolated value ... maybe a cubic spline or some other type of fit.
Steven Trvalik
on 21 Sep 2020
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
on 22 Sep 2020
Answers (0)
Categories
Find more on Spline Postprocessing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!