How can I obtain the derivative of a vector?

조회 수: 39 (최근 30일)
student
student 2015년 2월 17일
댓글: Star Strider 2015년 2월 18일
Hi, I have solved a system of ODEs with the solver ODE45 , obtaining the vector T and Y, which is a matrix of Nx6; N time points (length of vector of time points T) and 6 vectors, x1,x2,x3,dx1,dx2,dx3, displacements and velocities of three masses. I would like to obtain the vector of accelerations of x1,x2,x3. Could somebody please help me? Thank you very much!

답변 (3개)

Star Strider
Star Strider 2015년 2월 17일
Plug your ‘t’ vector and ‘y’ values matrix back into your ODE function. It will give you all the derivatives because that’s what you wrote it to provide.
  댓글 수: 4
student
student 2015년 2월 18일
Hi Roger,
thank you for your answer. How can I plug the vectors into my function to obtain the answer? Sorry, but I´m new in Matlab...
Star Strider
Star Strider 2015년 2월 18일
I don’t know if you’re addressing me or Roger. Assuming me, because you’re Commenting on my Answer, you just plug the integrated values of ‘t’ and ‘y’ (returned by ode45) into your ODE function. So if ‘odefun’ is the name of your ODE function and it is written as:
function dy = odefun(t,y)
to get the derivative matrix, simply call it as:
dy = odefun(t,y);
where ‘t’ is the vector of times that ode45 returns, and ‘y’ is the matrix of solutions ode45 returns. The ‘dy’ matrix is the matrix of derivatives you want, at times corresponding to ‘t’.

댓글을 달려면 로그인하십시오.


Roger Stafford
Roger Stafford 2015년 2월 17일
You can get an approximation to the derivative of dx1, dx2, and dx3 using matlab's 'gradient' function. If you would prefer a higher order approximation, you can find the code I wrote for a parabolic approximations at:
http://www.mathworks.com/matlabcentral/answers/175172

Torsten
Torsten 2015년 2월 18일
I guess you defined the ODEs as acceleration = f(displacement,velocity). So just repeat the calculations of acceleration (y'') for the solution variables you got from ODE45.
Best wishes
Torsten.
  댓글 수: 7
Stephen23
Stephen23 2015년 2월 18일
Because function already has a special meaning in MATLAB, you should avoid naming your function Function. Use a more descriptive name instead.
student
student 2015년 2월 18일
thank you!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Numeric Solvers에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by