# how to compute linked Manipulates with a more efficient code

I have several Manipulate codes as parts of a large block diagonal model. Each diagonal model produces outputs which are used in the second diagonal model, outputs of which are in turn used in the 3rd diagonal model and so on. I have a minimal example code as follows, which works just fine:

Row[{
Manipulate[
{
Plot[Sin[a x + b], {x, 0, 6}],
out1 = Sin[a x + b]
},
{{a, 2, "Multiplier"}, 1, 4},
{{b, 0, "Phase Parameter"}, 0, 10}
],
Spacer[40],
Manipulate[
{
Plot[a x + Sqrt[out1], {x, 0, 6}],
out2 = a x + Sqrt[out1]
},
{{a, 5, "Multiplier"}, 5, 10}
],
Spacer[40],
Manipulate[
Plot3D[b y + Sqrt[out1] + Sqrt[out2] x^2, {y, 0, 6}, {x, 0, 6}],
{{b, 1, "Multiplier"}, 1, 10}
]
}]


When I change a parameter in the 1st Manipulate, the output generated is automatically used as an input in the 2nd Manipulate and then in the 3rd Manipulate

1. How can these separate Manipulates be connected in a recursive manner and more efficiently, maybe with other codes like Block or While ...?
2. More troubling is how can I choose the Manipulate that I prefer to link to another Manipulate if there are more than 2 Manipulates?
• looks like a job for TrackingFunction
– kglr
Aug 20, 2023 at 12:03
• Should  out2 = a x + Sqrt[out] read  out2 = a x + Sqrt[out1]? And what about Sqrt[out1] if out1 is negative? Same for out2. Aug 20, 2023 at 12:58
• @Daniel Huber: You are right. It was a typo. I will correct it now. Better to have the real part of the imaginary number in case any of the outputs are Sqrt[-1]. Aug 20, 2023 at 16:24

## 1 Answer

It is unclear why you want multiple Manipulate. A single one will do everything that you show.

\$Version

(* "13.3.1 for Mac OS X ARM (64-bit) (July 24, 2023)" *)

Clear["Global*"]

imgSize = 300;

Manipulate[
Grid@{
{Plot[Sin[a x + b], {x, 0, 6}, ImageSize -> imgSize],
out1 = Sin[a x + b]},
{Plot[c x + Sqrt[out1], {x, 0, 6}, ImageSize -> imgSize],
out2 = c x + Sqrt[Sin[a x + b]]},
{Plot3D[d y + Sqrt[out1] + Sqrt[out2] x^2, {y, 0, 6}, {x, 0, 6},
ImageSize -> imgSize],
out3 = d y + Sqrt[out1] + Sqrt[out2] x^2}},
{{a, 2, "Multiplier"}, 1, 4, 0.25, Appearance -> "Labeled"},
{{b, 0, "Phase Parameter"}, 0, 10, 0.1, Appearance -> "Labeled"},
{{c, 5, "Multiplier 2"}, 5, 10, 0.05, Appearance -> "Labeled"},
{{d, 1, "Multiplier 3"}, 1, 10, 0.1, Appearance -> "Labeled"},
TrackedSymbols :> {a, b, c, d}]


• I perfectly understand your point. My question is a general question, not about the example given. I have already done what you showed in your answer. Since there are many instances I need to link Manipulate`s from different notebooks, I was thinking there must be a clever way of doing this integration. Aug 21, 2023 at 10:53