0
$\begingroup$

I would like to select any value for n, where p[x,y] = k^n

I have tried using the initialize function, but I am not exactly sure what is going wrong

Here is what I have tried so far

Clear[f, m, p, x, y, n]
f[x_] := -x + 6
m1[x_] := -(1/2) x + 3
m2[x_] := -2 x + 6
m3[x_] := 1


p1 = Plot[{f[x], m1[x], m2[x], m3[x]}, {x, 0, 6}, 
PlotRange -> {{0, 6}, {0, 6}}, AxesLabel -> {x, y}, 
AspectRatio -> Automatic];

Manipulate[
Show[p1, centroid],
{{n, 10, "value of n"}, 2, 20, 1 , Appearance -> "Labeled"}
Initialization :>
(

p[x_, y_] := k^n;

mass = Integrate[p[x, y], {x, 0, 6}, {y, 0, p[x, y]}];
momentx = Integrate[p[x, y]*y, {x, 0, 6}, {y, 0, p[x, y]}];
momenty = Integrate[p[x, y]*x, {x, 0, 6}, {y, 0, p[x, y]}];
xbar = momenty/mass;
ybar = momentx/mass;
centroid = Graphics[{PointSize[Large], Point[{xbar, ybar}]}];

)
]
$\endgroup$
1
$\begingroup$

There are two primary issues (and a missing comma). For one your k is never defined, the more serious one is that all of your Initialization definitions are immediate and don't end up changing with the controls.

By moving the definitions into the actual Show expression you get a manipulable expression:

Manipulate[
 Show[p1,
  Graphics[{PointSize[Large],
    With[{p = Function[k^n]},
     With[{
       mass = Integrate[p[x, y], {x, 0, 6}, {y, 0, p[x, y]}],
       momentx = Integrate[p[x, y]*y, {x, 0, 6}, {y, 0, p[x, y]}],
       momenty = Integrate[p[x, y]*x, {x, 0, 6}, {y, 0, p[x, y]}]
       },
      Point[{momentx, momenty}/mass]
      ]
     ]
    }]
  ],
 {{n, 10, "value of n"}, 2, 20, 1, Appearance -> "Labeled"},
 {k, .01, 2}
 ]
$\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.