0
$\begingroup$
j[t_]=(9 t)/(81 + t^2)^(3/2)
s[b_,t_] = 1/b * NIntegrate[j[t],{t,0,b}]
Plot[s[b,t], {b, -15, 15}, PlotRange -> {-0.04, 0.04}]

1/b * NIntegrate[j[t],{t,0,b}] represents the formula for the average value of a function from 0 to b, and I am seeking to maximize the average value of the function s[b,t] over this interval. How would I go about creating a Manipulate function where the position of a graphic (e.g. a dot) can be adjusted to move it along the curve and display the value of the function at the point set in the manipulate to visually determine the maximum value on such a plot?

$\endgroup$
1
$\begingroup$
Clear["Global`*"]

j[t_] = (9 t)/(81 + t^2)^(3/2);

Note that s has only one argument, that is b; t is the variable of integration.

s[b_?NumericQ] := 1/b*NIntegrate[j[t], {t, 0, b}]

The maximum is given by

{max, arg} = NMaximize[{s[b], -15 < b < 15}, b]

(* {0.0333648, {b -> 11.4482}} *)

Manipulate[
 Module[{pt = {bp, s[bp]}},
  Plot[Evaluate@s[b], {b, -15, 15},
   PlotRange -> {-0.04, 0.04},
   Frame -> True,
   Epilog -> {
     Text[pt[[2]], pt, Sign[bp] {1.5, -2}],
     Red, AbsolutePointSize[4],
     Point[pt]}]],
 {{bp, 1, "Point"}, -15, 15, 0.05, Appearance -> "Labeled"}]

enter image description here

For exact values

s2[b_] = 1/b*Integrate[j[t], {t, 0, b}]

(* (1 - 9/Sqrt[81 + b^2])/b *)

{max2, arg2} = Maximize[{s2[b], -15 < b < 15}, b] // Simplify

(* {(-2 + Sqrt[2 (3 + Sqrt[5])])/(
 18 Sqrt[2 + Sqrt[5]]), {b -> 9 Sqrt[1/2 (1 + Sqrt[5])]}} *)

The approximate values are as before.

{max2, arg2} // N

(* {0.0333648, {b -> 11.4482}} *)
| improve this answer | |
$\endgroup$
  • $\begingroup$ What does bp represent here? How could this be modified to also display the output of s[b] in the manipulate? $\endgroup$ – sabunketohar Sep 4 at 16:38
  • $\begingroup$ The coordinates of the moving point are {bp, s[bp]}, i.e., bp is the argument of the function for the moving point. The control changes the value of bp with the control label displaying the value of bp. The added Text displays the corresponding value of s[bp]. $\endgroup$ – Bob Hanlon Sep 4 at 16:58
  • $\begingroup$ When I replace it with ``` {s[bp],1,"point"} ``` the plot won't display, giving the error "does not have the correct form for a variable specification". Any idea why it is happening? $\endgroup$ – sabunketohar Sep 4 at 19:49
  • $\begingroup$ The control variable must be a variable. When you replaced bp with s[bp], bp is no longer defined and the control definition has the wrong syntax. $\endgroup$ – Bob Hanlon Sep 4 at 19:54

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.