Can anyone help with why my function is not working?
1 view (last 30 days)
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
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.
Answers (0)
See Also
Categories
Find more on Ordinary Differential Equations 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!