Mathematica Introducing new populations in mathematica graphs

AI Thread Summary
The discussion centers on how to introduce different populations at specific times in Mathematica, particularly when using NDSolve for differential equations. The user seeks a method to set initial populations to zero and then introduce them at later times without resorting to imprecise small values. A solution involves using InterpolatingFunction objects from NDSolve, allowing for the creation of a truncation function that only returns values for the populations when their respective times are reached. This approach enables the visualization of population changes over time accurately. The conversation also touches on the limitations of using ListPlot for this purpose, emphasizing the need for a more precise plotting method suitable for differential equation solutions.
pemb09
Messages
2
Reaction score
0
hi i was wondering if anyone knew how to introduce different populations at diffrent times on the same plot on mathematica?
Say i wanted population 1 have n = 10 at t=0, population 2 to have n=4 at t=0 and then introduce a new population at t=25 so that population 3 would have n= 0 initally but then n= 1 at t = 25.
Any ideas? the only way I've been gettting around it is to give population 3 really small values initially (e.g. 0.000000000001) but its not very precise.
 
Physics news on Phys.org
What kind of plot are you using? If you are using list plot then you can specify both x and y coordinates in your list. e.g.

a = Transpose[{Range[10], 2 Range[10]}];
b = Table[{x, 13}, {x, 3, 10}];
ListPlot[{a, b}]
 
I'm using Plot [ndsolve] of a set of differential equations. Listplot won't seem to make a list of solutions. I want one populations to have initial conditions of 0 but then at a further time stage to have a vlaue of 1 and see how that changes.
 
If popa and popb are the InterpolatingFunction objects that return from NDSolve then you can do the following:


truncate[f_InterpolatingFunction, t_] := If[f[[1, 1, 1]] <= t <= f[[1, 1, 2]], f[t]];
Plot[{truncate[popa, t], truncate[popb, t]}, {t, -1, 6}]
 

Similar threads

Replies
8
Views
3K
Replies
2
Views
2K
Replies
3
Views
2K
Replies
5
Views
2K
Replies
12
Views
5K
Replies
1
Views
2K
Replies
1
Views
2K
Replies
4
Views
3K
Back
Top