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 日

0 投票

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 件)

Giuseppe Esposito
Giuseppe Esposito 2017 年 8 月 8 日

0 投票

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 件のコメント

Torsten
Torsten 2017 年 8 月 9 日
... 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 ExchangeNumerical 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