Can anyone help with why my function is not working?
Mostrar comentarios más antiguos
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 comentarios
James Tursa
el 21 de Sept. de 2020
Editada: James Tursa
el 21 de Sept. de 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
el 21 de Sept. de 2020
James Tursa
el 21 de Sept. de 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
el 22 de Sept. de 2020
Respuestas (0)
Categorías
Más información sobre Ordinary Differential Equations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!