Problems with ODE system using ode45

2 次查看(过去 30 天)
Dennis
Dennis 2019-11-13
编辑: Dennis 2019-11-13
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.
odesystem.jpg
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))); ...
exp(lambda*(y4-x(3))+exp(x(3)-x(2)))];
%%%%% Next: Try to use ode45:
%%% arbitrary choice of lambda, mu, y0 and y4 just for testing the code
lambda=1;
mu=1;
y0=0;
y4=50;
% 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
plot(t,X(:,1),'-o',t,X(:,2),'-o',t,X(:,3),'-o')
xlabel('Time t');
ylabel('Solution x');
legend('x_1','x_2','x_3')

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by