0

I have written three simultaneous equations in a loop which goes for 260 years one step each year and now I need to add another value into one of the equations in the loop. I have these values inported as a list and they change every year. I am not sure what code I need to write to add in the values of the list when it is a different value for each step.

t:1751$
Ma:590$
Ms:900$
Md:37100$
Kas:0.078111$
Ksa:0.119153$
Ksd:0.002577$
Kds:0.106222$
dt:1$
tmax:2010$
Mapts:[[t,Ma]]$
Mspts:[[t,Ms]]$
Mdpts:[[t,Md]]$
while t<tmax-dt/2 do
(
t: t+dt,
Ma: Ma +(Kas*Ms-Ksa*Ma)*dt,
Ms: Ms + ((Ksd*Md-Kds*Ms)+(Ksa*Ma-Kas*Ms))*dt,
Md: Md + (Kds*Ms-Ksd*Md)*dt,
Mapts: append(Mapts, [[t,Ma]]),
Mspts: append (Mspts, [[t,Ms]]),
Mdpts: append (Mdpts, [[t,Md]])  
    )$
Mapts;

I have a list of values (F) from 1751 to 2010 and need to add that in to the equation Ma so Ma: Ma + ( (Kas*Ms-Ksa*Ma)*dt) + F but the addition of changing F is updated within the loop.

The output should show an increasing value for Ma each year between 1751 and 2010

Robert Dodier
  • 16,905
  • 2
  • 31
  • 48
Dani
  • 9
  • 2

1 Answers1

1

I see that Mapts turns out to be something like [[1751, ...], [1752, ...], ..., [2010, ...]]. You say you have a list of values of F from 1751 to 2010. Given that, you can add F to Mapts something like this:

map (lambda ([pt, x], [pt[1], pt[2] + x]), Mapts, F);
Robert Dodier
  • 16,905
  • 2
  • 31
  • 48