# How to plot point by point in a for loop?

I first apologize for my english which is still approximative and for the spelling, I hope all will be clear.

My problem is the following:

• I need to first solve a non-linear implicit 2-dimensional equation. I did that by using FindRoot and the results I obtained seem to be good. I have to solve this equation with respect to different parameters, here wee and wii, hence I did a loop over those two.

• Then I compute a matrix that I can now calculate using the solutions I got from FindRoot. What interests me in this matrix is the sign of its trace and its determinant, I want to find the area in the parameter space (wee,wii) where I have a negative trace and a positive determinant. So what I would like to do (and obviously what I didn't succeed in implementing so far...) is to plot a point of coordinates (wee,wii) if these two inequalities are verified.

Here my actual code :

For[wee = 0, wee <= 1, wee = wee + 1,
For[wii = 0, wii <= 2, wii = wii + 1,

hcurrente[x_, y_] := wee*x - wei*y;
hcurrenti[x_, y_] := wie*x - wii*y;

sol = FindRoot[{-alphae*x + (1 - x)*F[hcurrente[x, y]] ==
0, -alphai*y + (1 - y)*F[hcurrenti[x, y]] == 0}, {{x, 0.7}, {y,
0.7}}, MaxIterations -> 100];

xp = x /. sol;
yp = y /. sol;

matA0 = {{(1 - xp)*wee*F'[hcurrente[xp, yp]] - alphae -
F[hcurrente[xp, yp]], (1 - yp)*F'[hcurrenti[xp, yp]]*
wie}, {-(1 - xp)*F'[hcurrente[xp, yp]]*
wei, -(1 - yp)*F'[hcurrenti[xp, yp]]*wii - alphai -
F[hcurrenti[xp, yp]]}};

Tm = Tr[matA0];
Dm = Det[matA0];

ineq = Tm < 0 && Dm > 0;

If[ineq, Graphics[Point[{wee, wii}], Axes -> True]]
]]


I think this question has been already treated therefore I have been many times in the forum to find a way but in vain. For example, I already tried to use, Reap, Sow, etc.. but I always had a problem (compilation error, no plot, ...). I am now a bit out of time.

-
Your code is incomplete and can't be executed, so it is impossible for anyone to experiment with it and find out what is wrong and make corrections. Please provide complete code. – m_goldberg Dec 3 '15 at 14:34
A For-loop always returns Null and therefore makes no visible output. If you want to plot the points you are computing, you must gather them up into a list within your For-loops and make the plot from the list outside of the For-loop. – m_goldberg Dec 3 '15 at 14:37
You have parameters wei and wie that are not defined. – Alexei Boulbitch Dec 3 '15 at 14:56
Not "the MMA way", but start simple and work up from there: goodpoints={}; For[wee=0, wee<=1, wee=wee+1, For[wii=0, wii<=2, wii=wii+1, ineq=True; If[ineq, goodpoints = Append[goodpoints, Point[{wee, wii}]] ]]]; Show[Graphics[goodpoints]] – Bill Dec 3 '15 at 17:12
The top of my code is just the variables declaration and of the function F. – Hyppolite Dec 4 '15 at 18:01

This started out as a comment but got a bit long...

You're not approaching this in the "Mathematica way". I suggest defining a function of wee and wii which uses FindRoot to give your matrix, e.g.

myMatrix[wee_, wii_] := Module[{hcurrente, hcurrenti, sol, xp, yp},
hcurrente[x_, y_] := wee*x - wei*y;
hcurrenti[x_, y_] := wie*x - wii*y;

sol = FindRoot[{-alphae*x + (1 - x)*F[hcurrente[x, y]] ==
0, -alphai*y + (1 - y)*F[hcurrenti[x, y]] == 0}, {{x, 0.7}, {y,
0.7}}, MaxIterations -> 100];

xp = x /. sol;
yp = y /. sol;

{{(1 - xp)*wee*F'[hcurrente[xp, yp]] - alphae -
F[hcurrente[xp, yp]], (1 - yp)*F'[hcurrenti[xp, yp]]*
wie}, {-(1 - xp)*F'[hcurrente[xp, yp]]*
wei, -(1 - yp)*F'[hcurrenti[xp, yp]]*wii - alphai -
F[hcurrenti[xp, yp]]}}
]


(Note this is by necessity entirely untested and unsimplified, I have simply copied and pasted some of the code from inside the For loops in your question directly into this answer.)

Then you can map your expression involving the trace and determinant using a suitable plotting function, e.g.

RegionPlot[Module[{m = myMatrix[wee, wii]}, Tr[m] < 0 && Det[m] > 0],
{wee, 0, 1}, {wii, 0, 2}]]


Or use other functions such as FindMinimum to find optimal points in your parameter space (without resorting to using For loops!).

-