Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

MWE

I have some data indexed by gamma. For each gamma I want to find the intersection points of two lists and plot the lists and the intersection points. I convert the two lists into two functions ifun[gamma] and ifun2[gamma] using interpolation, find their intersection using FindRoot and plot them. Instead of creating a separate plot for each gamma, I'd like to be able to throw that inside Manipulate. But I am running into trouble with Manipulate needing to explicitly define dependence on variables, as mentioned in the possible issues.

Table[ifun[gamma]=Interpolation[Table[{i, i^gamma}, {i, 1, 10}]], {gamma, 1, 2, 1}]
Table[ifun2[gamma]=Interpolation[Table[{i, gamma^gamma}, {i, 1, 10}]], {gamma, 1, 2, 1}]
Table[solE[gamma] = {x} /.FindRoot[ifun[gamma][x] == ifun2[gamma][x], {x, 0.15}], {gamma, 1,  2}]

Framed@Show[ListPlot[{#, ifun[1][#]} & /@ solE[1], PlotStyle -> PointSize[Large]], Plot[{ifun[1][x], ifun2[1][x]}, {x, 0, 10}],RegionPlot[x < solE[1][[1]] && -5 < y < 5, {x, 0, 10}, {y, -5, 5}, PlotStyle -> {{Yellow, Opacity[0.2]}}]]

enter image description here

Update2

Ok so I did the indexing on the data and not on the functions, solved for the solutions outside the manipulate and just stored the points, interpolated inside Manipulate for plotting..and it works.

Table[data1[gamma] = Table[{i, i^gamma}, {i, 1, 10}], {gamma, 1, 2}]
Table[data2[gamma] = Table[{i, gamma^gamma}, {i, 1, 10}], {gamma, 1, 2, 1}]
Table[solE[gamma] = {x} /.FindRoot[Interpolation[data1[gamma]][x] ==
 Interpolation[data2[gamma]][x], {x, 0.15}], {gamma, 1, 2}]

This works:

Manipulate[fun = Interpolation[data1[gamma]];fun2 = Interpolation[data2[gamma]];Plot[{fun[x], fun2[x]}, {x, 1, 5}, Epilog -> {Black, PointSize[Large],   Point[{solE[gamma][[1]], fun[solE[gamma][[1]]]}]},  AxesOrigin -> {0.5, 0}], {gamma, 1, 2, 1}]

enter image description here

share|improve this question
    
Could you tell me if you tried working with my answer and if so what it did/didn't do? –  rm -rf Oct 4 '12 at 22:31
    
Hey rm-rf, thanks for your answer. I tried working with it and it worked. I'll posted the working verison below in the question. The trick was to index the data and calculate a fresh interpolation inside the Manipulate, as opposed to indexing the interpolation function. –  Amatya Oct 4 '12 at 22:45

1 Answer 1

up vote 1 down vote accepted

You haven't shared your data, so I can't run your code. Here's an example of using an InterpolatingFunction inside a Manipulate:

Manipulate[
    pts = {{0, 0}, {1, 1}, {2, 3}, {a, b}, {4, 3}, {5, 0}};
    ifun = Interpolation[pts];
    Plot[ifun[x], {x, 0, 5}, PerformanceGoal -> "Quality",
        Epilog -> {Black, PointSize[Large], Point[pts], Red, Point[{a, b}]}], 
    {{a, 3}, 0, 5}, {{b, 4}, 0, 5}]

Moving the sliders will recalculate the interpolating function for the new set of points.

share|improve this answer
    
Thanks, I'll post data in a sec and also try your method. The problem with me is that my interpolating functions look like ifun[gamma][x] where gamma $\in \{1,100\}$. I'll post a MWE in a few minutes. –  Amatya Oct 4 '12 at 21:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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