# How do you make two interactive sliders dependent on eachother?

I have this code.

Definition of q is:

α=0.86;

q[x_,y_,t_,u_,f_]:=(((1-α) (y-t*x-f))/(((α^α)((1-α)^(1-α)) (y-t*x-f))/u)^(1/(1-α)));

Manipulate[
Plot[{q[x, y, t, u, f]}*30000, {x, 0, 40}, PlotRange -> {0, 1000},
PlotStyle -> {Thickness[0.008]}, AxesLabel -> {"x", "q(x)"},
Filling -> Bottom,
PlotLabel ->
"Housing Consumption (floor space per dwelling in sqm) "], {y,
70000, 100000}, {t, 600, 800}, {u, 5633.58, 6000}, {f, 0, 50000}]


What do I do, if I want f and t to be dependent on each other? For example, if I move up one, the other goes down using a function.

• What is the definition for q? Oct 11, 2021 at 13:40
• I added it to the description. Oct 11, 2021 at 13:53
• What is α? Always check that the code will execute with the info provided. Oct 11, 2021 at 14:27
• Yes I see, I added it. Oct 11, 2021 at 14:30

Say you have some function w that maps f to t

w[f_] := 800 - 200/50000 f
Plot[w[x], {x, 0, 50000}]


When with definitions in OP

Manipulate[
Plot[{q[x, y, t, u, f]}*30000
, {x, 0, 40}
, PlotRange -> {0, 1000}
, PlotStyle -> {Thickness[0.008]}
, AxesLabel -> {"x", "q(x)"}
, Filling -> Bottom
, PlotLabel ->
"Housing Consumption (floor space per dwelling in sqm)"
]
, {{y, 100000}, 70000, 100000}
, {{t, 800}, 600, 800
, TrackingFunction -> (t = #; f = InverseFunction[w][#]; &)
, Appearance -> "Labeled"}
, {{u, 6000}, 5633.58, 6000}
, {f, 0, 50000
, TrackingFunction -> (f = #; t = w[#]; &)
, Appearance -> "Labeled"}
]


In fact, you can evaluate multiple relationships in the manipulate with the addition of a relationship function paramerter g.

Say there is another relationship, w2.

w2[f_] := 600 + (100/π) (Sin[(2 π f)/50000] + (2 π f)/50000)
Plot[w2[x], {x, 0, 50000}, ImageSize -> 250]


Then

Manipulate[
Plot[{q[x, y, t, u, f]}*30000
, {x, 0, 40}
, PlotRange -> {0, 1000}
, PlotStyle -> {Thickness[0.008]}
, AxesLabel -> {"x", "q(x)"}
, Filling -> Bottom
, PlotLabel ->
"Housing Consumption (floor space per dwelling in sqm)"
]
, {{y, 100000}, 70000, 100000}
, {{t, 800}, 600, 800
, TrackingFunction -> (t = #; f = InverseFunction[g][#]; &)
, Appearance -> "Labeled"}
, {{u, 6000}, 5633.58, 6000}
, {f, 0, 50000
, TrackingFunction -> (f = #; t = g[#]; &)
, Appearance -> "Labeled"}
, {{g, w}, {w, w2}}
]


Hope this helps.

• It's amazing. Does it also work if I move the t slider? Or do I have to create something separate for both? Oct 14, 2021 at 11:56
• @VictorNielsen Works for both t and f. Oct 14, 2021 at 14:12
Clear["Global*"]

\$Version

(* "12.3.1 for Mac OS X x86 (64-bit) (June 19, 2021)" *)

α = 0.86;

q[x_, y_, t_, u_,
f_] := (((1 - α) (y - t*x -
f))/(((α^α) ((1 - α)^(1 - α)) (y - t*x -
f))/u)^(1/(1 - α)));


Assume that the relation between f and t is linear

f == a*t + b /.
Solve[f == a*t + b /. {{f -> 0, t -> 800}, {f -> 50000, t -> 600}}, {a,
b}][[1]]

(* f == 200000 - 250 t *)


Since they move in opposite directions, the starting values are at opposite sides of their respective range.

fOld = 0;
tOld = 800;

Manipulate[
If[f == fOld && t != tOld,
f = 200000 - 250 t; fOld = f; tOld = t,
If[t == tOld && f != fOld,
t = (200000 - f)/250; tOld = t; fOld = f]];
Plot[{q[x, y, t, u, f]}*30000, {x, 0, 40},
PlotRange -> {0, 1000},
PlotStyle -> {Thickness[0.008]},
AxesLabel -> {"x", "q(x)"},
Filling -> Bottom,
PlotLabel ->
"Housing Consumption (floor space per dwelling in sqm)"],
{{y, 77000}, 70000, 100000, 100, Appearance -> "Labeled"},
{{t, 800}, 600, 800, 1, Appearance -> "Labeled"},
{{u, 5633.58}, 5633.58, 6000, 0.01, Appearance -> "Labeled"},
{{f, 0}, 0, 50000, 100, Appearance -> "Labeled"},
TrackedSymbols :> All]
`