Solving non-homogeneous differential equation

조회 수: 18 (최근 30일)
JVM
JVM 2018년 10월 6일
댓글: Talari Nageswari 2022년 1월 20일
I have a second order differential equation: M*x''(t) + D*x'(t) + K*x(t) = F(t) which I have rewritten into a system of first order differential equation.
fun = @(t,q) [q(2) ; -K/M*q(1) - D/M*q(2)] + [0 ; F/M]
Now, I have an array of F-values for different t-values going from 0 to 300 seconds with a step size of 0.1s. K, D and M are just constants which are all known. I want to find the corresponding x-values for the same t-values using the ode45 but I keep getting an error. The initial condition is x(0) = 0 and x'(0) = 0. This is how I use it:
[t y] = ode45(fun,(0:0.1:300),[0 0])
Can anyone tell me what I am doing wrong?
  댓글 수: 1
Talari Nageswari
Talari Nageswari 2022년 1월 20일
i did the same thing
can i get the value of x'(t) and x(t) by using the above van der pol function

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

답변 (2개)

Torsten
Torsten 2018년 10월 8일
Take a look at the example
"ODE with Time-Dependent Terms"
under
https://de.mathworks.com/help/matlab/ref/ode45.html
Best wishes
Torsten.

Eric Robbins
Eric Robbins 2019년 11월 26일
If you're getting a concatenation error try [0*y(2);F/M] so that the first row is consistently sized with the other vectors.

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by