second order differential equation with variable coefficients

 Respuesta aceptada

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.

Más respuestas (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 el 8 de Ag. de 2017
I've solved, xx and F hadn't the same length.
Thank you.

1 comentario

... 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Numerical Integration and Differential Equations en Centro de ayuda y File Exchange.

Preguntada:

el 8 de Ag. de 2017

Comentada:

el 9 de Ag. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by