Solving a system of N ODEs with ode45

Hi! I have to solve a system of n ODEs in which every
dpdt (i) = -(a*p(i) + b*p(i).^3 + k*(2*p(i) - p(i-1) - p(i+1)))
for i from 2 to n-1 , where a,b,k are constants and
dpdt(1)= dpdt(n) = 0
I am having trouble defining the dpdt vector that will go into ode45 as the first argument. Any suggestions? Thanks!

Réponses (1)

Walter Roberson
Walter Roberson le 9 Déc 2017
a = ...
b = ...
k = ...
N = ...
fun = @(t, y) [0; -(a*p(2:end-1) + b*p(2:end-1).^3 + k*(2*p(2:end-1) - p(1:end-2) - p(3:end))); 0]
x0 = boundary condition of length N
ode45(fun, tspan, x0)

Community Treasure Hunt

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

Start Hunting!

Translated by