Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2012

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Manipulate help

  • To: mathgroup at smc.vnet.net
  • Subject: [mg128592] Re: Manipulate help
  • From: "Nasser M. Abbasi" <nma at 12000.org>
  • Date: Thu, 8 Nov 2012 02:08:46 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-newout@smc.vnet.net
  • Delivered-to: mathgroup-newsend@smc.vnet.net
  • References: <k7ct9k$dqn$1@smc.vnet.net>
  • Reply-to: nma at 12000.org

On 11/6/2012 11:58 PM, 07.350z wrote:
> Create a Manipulate demonstration that draws the tangent line to a curve at the point
>specified by a continuous control. For the curve, the user should be able to
>choose between the graphs of the following functions. Make sure your demonstration
>shows the curve, the point, and the tangent line at that point. The functions are 7cos(x),
> x^2/10, 2ln(1+x^2)
>
> Show[Manipulate[
>    Plot[y, {x, -10, 10},
>     PlotRange -> {-10, 10}], {y, {7 Cos[x], x^2/10, 2*Log[1 + x^2]}}],
>   Do[Module[{slopeM, tangentLine, x},
>     slopeM = D[{7 Cos[x], x^2/10, 2*Log[1 + x^2]}, x] /. x -> t;
>     tangentLine = slopeM*x - t;
>     Return[
>      Plot[{{7 Cos[x], x^2/10, 2*Log[1 + x^2]}, tangentLine}, {t, -5,
>        5}]]], {x, -10, 10}]]
>
> I know the first part of code is right, but I'm having trouble adding the tangent line.
>Any help would be great thanks!
>

may be

-------------------------------------------
Manipulate[
  Module[{lineEquation, pt = {at, y /. x -> at}},
    lineEquation = getSlope[at, y, x];
   Plot[{y, lineEquation }, {x, -10, 10}, PlotRange -> {-10, 10},
    Epilog -> {Red, PointSize[.02], Point[pt]}]
   ],
  
  {y, {7 Cos[x], x^2/10, 2*Log[1 + x^2]}},
  {{at, 0, "x"}, -10, 10, 1, Appearance -> "Labeled"},
  TrackedSymbols :> {y, at},
  
  Initialization :>
   (
    getSlope[at_, y_, var_] := Module[{slope, h, intercept},
      h = y /. var -> at;
      slope = D[y, var] /. var -> at;
      intercept = h - at*slope;
      slope*var + intercept
      ]
    )
  ]
----------------------------------

--Nasser




  • Prev by Date: Re: Conformal Mapping
  • Next by Date: Non Commutative Multiply
  • Previous by thread: Manipulate help
  • Next by thread: FindFit::nrlnum Error Message