Modelling a system of differential equations with recurrences in matlab
56 views (last 30 days)
Show older comments
Trying to model a system in the form
a*u_n(t)'' + b*u_n(t) = k( v_n+1(t) + v_n-1(t) - 2u_n(t) )
c*v_n(t)'' + d*v_n(t) = k( u_n+1(t) + u_n-1(t) - 2v_n(t) )
a,b,c,d,k are all constants
Pretty sure this can only be done numerically
5 Comments
Torsten
ungefär 15 timmar ago
Edited: Torsten
ungefär 15 timmar ago
Since the boundary conditions are defined by second-order differential equations for u_0, v_0, u_n and v_n, we need u_i(0), u_i'(0), v_i(0), v_i'(0) for i = 0,...,n.
You said we may assume u_i(0) = v_i(0) = 0 for i=1,...,n-1. So u_0(0),v_0(0),u_n(0),v_n(0) and all derivatives u_i'(0) and v_i'(0) at t = 0 ( (i = 0,...,n) are to be added to the problem description to make the system solvable.
Accepted Answer
Torsten
ungefär 14 timmar ago
Edited: Torsten
ungefär 14 timmar ago
N = 20;
k = 1;
a = 1;
b = 1;
c = 1;
d = 1;
u0 = zeros(N,1);
udot0 = 0.5*ones(N,1);
v0 = zeros(N,1);
vdot0 = 0.3*ones(N,1);
y0 = [u0;udot0;v0;vdot0];
tspan = linspace(0,10,20);
[T,Y] = ode15s(@(t,y)fun(t,y,N,k,a,b,c,d),tspan,y0);
u = Y(:,1:N);
udot = Y(:,N+1:2*N);
v = Y(:,2*N+1:3*N);
vdot = Y(:,3*N+1:4*N);
function dydt = fun(t,y,N,k,a,b,c,d)
u = y(1:N);
udot = y(N+1:2*N);
v = y(2*N+1:3*N);
vdot = y(3*N+1:4*N);
dudt = zeros(N,1);
d2udt2 = zeros(N,1);
dvdt = zeros(N,1);
d2vdt2 = zeros(N,1);
dudt = udot;
dvdt = vdot;
%a*u_1(t)'' + b*u_1(t) = k( v_2(t) - u_1(t) )
%a*u_i(t)'' + b*u_i(t) = k( v_i+1(t) + v_i-1(t) - 2u_i(t) ) (2 <= i <= N-1)
%a*u_N(t)'' + b*u_N(t) = k( v_N-1(t) - u_N(t) )
d2udt2(1) = (-b*u(1)+k*(v(2)-u(1)))/a;
d2udt2(2:N-1) = (-b*u(2:N-1)+k*(v(3:N)+v(1:N-2)-2*u(2:N-1)))/a;
d2udt2(N) = (-b*u(N)+k*(v(N-1)-u(N)))/a;
%c*v_1(t)'' + d*v_1(t) = k( u_2(t) - v_1(t) )
%c*v_i(t)'' + d*v_i(t) = k( u_i+1(t) + u_i-1(t) - 2v_i(t) ) (2 <= i <= N-1)
%c*v_N(t)'' + d*v_N(t) = k( u_N-1(t) - v_N(t) )
d2vdt2(1) = (-d*v(1)+k*(u(2)-v(1)))/c;
d2vdt2(2:N-1) = (-d*v(2:N-1)+k*(u(3:N)+u(1:N-2)-2*v(2:N-1)))/c;
d2vdt2(N) = (-d*v(N)+k*(u(N-1)-v(N)))/c;
dydt = [dudt;d2udt2;dvdt;d2vdt2];
end
More Answers (1)
John D'Errico
ungefär 17 timmar ago
Edited: John D'Errico
ungefär 16 timmar ago
This is known as a delay differential equation. You will find any solvers for them starting with the letters dde.
help dde23
You will convert the second order DDEs each into a pair of first order DDEs using the standard trick, so you will have a system of 4 DDEs. Standard trick:
If you have a second order equation of the form:
y''(x) = stuff
you convert it into a pair of first order equations by creating a new unknown function, I'll call it z, where z is just the currently unknown first derivative of y.
y'(x) = z(x)
z'(x) = stuff
The same will apply in your case, even with a DDE.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!