0
$\begingroup$

Quick Question: What is the best way to map this function so it performs seperately for 102 different values of x?

tag[p_, x_] := Piecewise[{{Part[probeList, x], Norm[p - {5, 5} - Part[userEditedProbeCoordinates, x]] < 10}}]
Manipulate[Show[rttp, PlotLabel -> tag[p]], {{p, {0, 0}}, Locator}] 

I want to map it to all values of x between 1 and 102, using my list "bigrange". So I was thinking I could use

Map[tag,bigrange] 

but this obviously doesn't work since tag is applied to 2 variables.

Are there any other ways to approach this problem, or some clever solution?

Here is an example of code that works for the first 2, but not all 102.

tag[ppp_] := Piecewise[{{Part[probeList, 1], Norm[ppp - {5, 5} -Part[userEditedProbeCoordinates, 1]] < 10}, {Part[probeList, 2], Norm[ppp - {5, 5} - Part[userEditedProbeCoordinates, 2]] < 10} }]
Manipulate[Show[rttp, PlotLabel -> tag[ppp]], {{ppp, {0, 0}}, Locator}]  

Thanks so much.

$\endgroup$
  • $\begingroup$ What should be the value of p for each x? $\endgroup$ – J. M. will be back soon Jun 14 '16 at 17:00
  • $\begingroup$ p doesn't change, the full code involving p is there. $\endgroup$ – UndercoverPie Jun 14 '16 at 17:01
  • $\begingroup$ So, Manipulate[Show[rttp, PlotLabel -> tag[p, #]], {{p, {0, 0}}, Locator}] & /@ bigrange? $\endgroup$ – J. M. will be back soon Jun 14 '16 at 17:02
  • $\begingroup$ Hm replacing my second line with that is doing the same thing, seems to have the same results. I don't have much experience with pure functions, should this work without further edits? tag[p_, x_] := Piecewise[{{Part[probeList, x], Norm[p - {5, 5} - Part[userEditedProbeCoordinates, x]] < 10}}] Manipulate[ Show[rttp, PlotLabel -> tag[p, #]], {{p, {0, 0}}, Locator}] & /@ bigrange $\endgroup$ – UndercoverPie Jun 14 '16 at 17:06
  • 1
    $\begingroup$ Thanks jjc, I just realised p is actually the position of the cursor in this function. Do you have any ideas for dealing with this? $\endgroup$ – UndercoverPie Jun 15 '16 at 9:16
1
$\begingroup$

Piecewise basically uses an array, so you can put it with a Table. for example

val = Sort@RandomReal[1, 10]
step[x_] = Piecewise[Table[{i, val[[i - 1]] < x < val[[i]]}, {i, 2, 10}]];
Plot[step[x], {x, 0, 1}, GridLines -> {val, {}}]

{0.254837, 0.27277, 0.302014, 0.339608, 0.504063, 0.567221, 0.826478, \ 0.869325, 0.879442, 0.904477}

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.