MATLAB Answers


Problems with ODE system using ode45

Asked by Dennis
on 13 Nov 2019 at 13:14
Latest activity Edited by Dennis
on 13 Nov 2019 at 13:36
I would like to solve (and then plot the solution of) the Ordinary Differential Equation system
with initial conditions
Note that one needs to choose in order to make sense of the equations for . My first attempt is to choose them constantly such that
I tried to implement this system in Matlab.
First, I wrote the function myODE for the right hand side of the system; then I tried to used ode45. The code can be seen below.
Unfortunately, there seems to be a mistake because the plot only shows the initial conditions and, moreover, the time range is from -1 to 1 (see the following image) which is not what I would like to plot.
Where is the mistake in my code?
Can you help me, please?
function dxdt = myODE(t,x,lambda,mu,y0,y4) %
% y0 = leftmost outer neighbour (constant)
% y4 = rightmost outer neighbour (constant)
dxdt = [exp(lambda*(x(2)-x(1)))+exp(mu*(x(1)-y0)); ...
exp(lambda*(x(3)-x(2)))+exp(mu*(x(2)-x(1))); ...
%%%%% Next: Try to use ode45:
%%% arbitrary choice of lambda, mu, y0 and y4 just for testing the code
% initial conditions: y_1=5, y_2=10, y_3=15
% consider 100 time steps
[t,X] = ode45(@(t,x) myODE(t,x,lambda,mu,y0,y4),[0 100], [5; 10; 15]);
% plot x_1=X(1), x(2)=X(2), x(3)=X(3) against t
xlabel('Time t');
ylabel('Solution x');


Sign in to comment.

0 Answers