Solving a system of N ODEs with ode45
Show older comments
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!
Answers (1)
Walter Roberson
on 9 Dec 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)
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!