Home Issue with plotting in MATLAB (using ode45)

# Issue with plotting in MATLAB (using ode45)

JordanSW
1#
JordanSW Published in 2018-01-12 15:53:08Z
 Alright so i want to plot the right side as a function of N using this equation: dN/dt=-0.5N+100  I'm using MATLAB and my problem is that the plot stops at an x value of 200. I'm using the following code: T = 1000; eq = @(t,N)(-0.5*N+100); [t,N] = ode45(eq,[0 500],-5); plot(N,-0.5*N+100) axis([0 1000 -500 500])  Is there any way I can get my graph to continue to an x value of 1000?
am304
2#
 That's because you're only solving the ode on the interval [0 500] (see the second argument you pass to the ode45 function). To plot it on a different interval, you first need to solve it on a different interval: T = 1000; eq = @(t,N)(-0.5*N+100); [t,N] = ode45(eq,[0 1000],-5); % second argument changed to solve on different interval plot(N,-0.5*N+100) axis([0 1000 -500 500]) 
 That's because N converges to 200 after some time, as you can see the plot below: So there will be no value more than 200 and when you want to plot dN/dt vs. N your x axis will be from 0 to 200.