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

 采纳的回答

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);
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 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by