Solving Second Order Differential Equation !

Hi, Im trying to solve and plot the solution for a second order differential equation. After some study, I made the following code:
%--------------------------------------------------
function xp = myfunc(t,x)
% x''+2*ep*w*x'+w^2*x+d*x'*abs(x')=0
w = (2*pi)/10.8814;
ep = 0.196;
d = -0.271;
xp = zeros(2,1);
xp(1)= x(2);
xp(2)= -((2*ep*w)*x(2)+(w^2*x(1))+d*abs(x(2))*x(2));
end
%---------------------------------------------------
And
%-----------------------------------
clc;
tr=0:0.1:393;
initialvalues=[17.66 0];
[t,x]=ode45('myfunc',tr,initialvalues);
plot(t,x(:,1));
%----------------------------------
The expected plot is a damped sine wave. Im not able to get it.
Any advise on what Im missing here will be great.
Thanks and Regards SLS

 채택된 답변

Youssef  Khmou
Youssef Khmou 2013년 5월 17일

0 개 추천

hi,
The damped oscillation can be obtained by changing the sign of the constant d :
d=0.271;

추가 답변 (1개)

SmartEngineer
SmartEngineer 2013년 5월 18일

0 개 추천

Thanks.
Its a typo I didnt notice. Should have checked it.
Anyway Thank you.

카테고리

도움말 센터File Exchange에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by