Can anyone help with why my function is not working?

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 件のコメント

James Tursa
James Tursa 2020 年 9 月 21 日
編集済み: James Tursa 2020 年 9 月 21 日
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
Steven Trvalik 2020 年 9 月 21 日
Hmm, this is basically what I was trying to accomplish. I used the round function to take the value from my vector with the time closest to what was called for. Will I instead have to fit an actual function?
Thanks.
James Tursa
James Tursa 2020 年 9 月 21 日
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 2020 年 9 月 22 日
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

サインインしてコメントする。

回答 (0 件)

カテゴリ

質問済み:

2020 年 9 月 21 日

コメント済み:

2020 年 9 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by