second order differential equation with variable coefficients

I have to solve this differential equation: m*d^2x/dt^2 +k*x= F(x) where F(x) is known for points

 채택된 답변

Torsten
Torsten 2017년 8월 8일
Write your equation as a first-order system
y1'=y2
y2'=(-k*y1+F(y1))/m
use "interp1" to interpolate F(y1) from your known values and call "ode45" to solve.
Best wishes
Torsten.

추가 답변 (2개)

Thank you for your answer, I have written the algorithm in this way but it doesn't work
clc; close all; clear all;
xx=[0,2,4,6,8,10,12];
F=[0.65,0.75,0.80,0.81,0.80,0.50];
tspan=[0,0.1];
x0=[0,0];
Fc=@(x) interp1(xx,F,x);
m=15E-3;
k=50;
function dxdt=myfun(t,x,m,k,Fc);
dxdt(1)=x(2);
dxdt(2)=(-k*x(1)+Fc(x(1)))/m;
end
[t,x]=ode45(@(t,x) myfun(t,x,m,k,Fc),tspan,x0);
Giuseppe Esposito
Giuseppe Esposito 2017년 8월 8일

0 개 추천

I've solved, xx and F hadn't the same length.
Thank you.

댓글 수: 1

... and dxdt has to be a column vector:
function dxdt=myfun(t,x,m,k,Fc);
dxdt=zeros(2,1);
dxdt(1)=x(2);
dxdt(2)=(-k*x(1)+Fc(x(1)))/m;
end
Best wishes
Torsten.

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

카테고리

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

질문:

2017년 8월 8일

댓글:

2017년 8월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by