- #1
musicgirl
- 12
- 0
I'm having a recurring problem in mathematica when I try and introduce a simple for loop.
For instance, I have the code shown below. It should increment my var value, and calculate a value of 'initial' for each 'var' value. These should then be recorded under the name RMPvalue[var] so I can combine them into a table.
For[var = 1, var <= 3, var = var + 0.1,
A = 3;
α = 3;
γ = var* 0.05;
v0 = var*0.4;
w0 = var*0.4;
ε = 0.2;
initial =
Solve[wi == A*vi*(vi - α)*(1 - vi) - w0 && wi == (vi - v0)/γ, {vi, wi},
Reals];
RMPvalue[var] = initial[[1, 1, 2]]]
Table[RMPvalue, {i, 1, 3, 0.1}]
If I ran the code with each individual var value, I have no problem. However, once I introduce a for loop (I have also tried a while loop...) some values do not get computed and I get a table output such as:
{0.295541, 0.319624, 0.343382, 0.36693, 0.39038, 0.413848, 0.437453,
RMPvalue[1.7], 0.48562, RMPvalue[1.9], 0.536181, RMPvalue[2.1], 0.591052,
RMPvalue[2.3], 0.653529, 0.689508, 0.730596, RMPvalue[2.7], 0.843924,
RMPvalue[2.9], 1.7899}
where the entries listed as RMPvalue[x] have no value assigned to them. My instinct is that there's a problem in the loop increments but I have no idea how to fix it. I've encountered this problem with several different codes, but I've never found a solution, just reworked the code so I don't get in this situation. Does anyone have any ideas?
Thanks,
Rachel
For instance, I have the code shown below. It should increment my var value, and calculate a value of 'initial' for each 'var' value. These should then be recorded under the name RMPvalue[var] so I can combine them into a table.
For[var = 1, var <= 3, var = var + 0.1,
A = 3;
α = 3;
γ = var* 0.05;
v0 = var*0.4;
w0 = var*0.4;
ε = 0.2;
initial =
Solve[wi == A*vi*(vi - α)*(1 - vi) - w0 && wi == (vi - v0)/γ, {vi, wi},
Reals];
RMPvalue[var] = initial[[1, 1, 2]]]
Table[RMPvalue, {i, 1, 3, 0.1}]
If I ran the code with each individual var value, I have no problem. However, once I introduce a for loop (I have also tried a while loop...) some values do not get computed and I get a table output such as:
{0.295541, 0.319624, 0.343382, 0.36693, 0.39038, 0.413848, 0.437453,
RMPvalue[1.7], 0.48562, RMPvalue[1.9], 0.536181, RMPvalue[2.1], 0.591052,
RMPvalue[2.3], 0.653529, 0.689508, 0.730596, RMPvalue[2.7], 0.843924,
RMPvalue[2.9], 1.7899}
where the entries listed as RMPvalue[x] have no value assigned to them. My instinct is that there's a problem in the loop increments but I have no idea how to fix it. I've encountered this problem with several different codes, but I've never found a solution, just reworked the code so I don't get in this situation. Does anyone have any ideas?
Thanks,
Rachel