Suppose three functions :
k1[s_, d_,m_] := 3 s + 5 d + m
k2[s_, d_] := 5 s - 7 d
k3[s_, d_,m_] := s + d - m
How to add the following code to plot conditional ki in (s,d) plan while looping over m values for a range, say form -3 to 2 ?
ps = Transpose[{RandomReal[{-2, 2.}, 1000],RandomReal[{-3, 3}, 1000]}];
styleps = Style[{##}, PointSize[.01], Piecewise[{{Blue, 0 < k1[#, #2, -3] <=
10 && -2 < k2[#, #2] <= 2 && 0 < k3[#, #2, -3] <= 10}}, White]] & @@@ ps;
ListPlot[styleps, DataRange -> {{-1, 1}, {-1, 1}}, Frame -> True,
GridLines -> {Table[i, {i, 0, 2, 0.1}], Table[i, {i, -1, 3, 0.2}]},
ImageSize -> 500, Axes -> False, GridLinesStyle -> Lighter[Gray]]
I think one can use For Loop, but I don't know exactly where it can be implied, any ideas?
Answer
Try this:
k1[s_, d_, m_] := 3 s + 5 d + m
k2[s_, d_] := 5 s - 7 d
k3[s_, d_, m_] := s + d - m
ps = Transpose[{RandomReal[{-2, 2.}, 1000],
RandomReal[{-3, 3}, 1000]}];
styleps[m_] :=
Style[{##}, PointSize[.01],
Piecewise[{{Blue,
0 < k1[#, #2, m] <= 10 && -2 < k2[#, #2] <= 2 &&
0 < k3[#, #2, m] <= 10}}, White]] & @@@ ps;
plots = Table[
ListPlot[styleps[m], DataRange -> {{-1, 1}, {-1, 1}},
Frame -> True,
GridLines -> {Table[i, {i, 0, 2, 0.1}],
Table[i, {i, -1, 3, 0.2}]}, ImageSize -> 500, Axes -> False,
GridLinesStyle -> Lighter[Gray]], {m, 0, 2, 2/(10 - 1)}];
This gives 10 plots with m varying from 0 to 2. We can visualize it with an animation for instance:
Animate[plots[[u]], {u, 1, Length[tab], 1}]
Should show you something like this:

Comments
Post a Comment