3
$\begingroup$

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.

enter image description here

enter image description here

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

2 Answers 2

4
$\begingroup$

You may use TrackingFunctionand InverseFunction in Manipulate.

Say you have some function w that maps f to t

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

Mathematica graphics

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"}
 ]

enter image description here

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]

Mathematica graphics

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}}
 ]

enter image description here

Hope this helps.

$\endgroup$
2
  • $\begingroup$ It's amazing. Does it also work if I move the t slider? Or do I have to create something separate for both? $\endgroup$ Oct 14, 2021 at 11:56
  • 1
    $\begingroup$ @VictorNielsen Works for both t and f. $\endgroup$
    – Edmund
    Oct 14, 2021 at 14:12
1
$\begingroup$
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]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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