Re: Some Easy (hopefully) Questions
- To: mathgroup at christensen.cybernetics.net
- Subject: [mg2038] Re: Some Easy (hopefully) Questions
- From: David Harvatin <dtharvat at sprint.uccs.edu>
- Date: Sat, 16 Sep 1995 01:41:41 -0400
- Organization: University of Colorado at Boulder
Rob Carscadden <carscadd at pps.pubpol.duke.edu> wrote:
>I'm trying to run a model using Mathematica. I've scoured all our
>libraries and all the books are gone. Working with all too basic
>Mathematica By Example, I haven't been able to find how to do some rather
>easy things.
>
>The first thing I want to do is find a max (I need to plug the max and
>where it occurs into anther equation). I have a function, and I have
>taken both the first and second derivatives. I solve for f'(x) = 0. But
>here's where the trouble comes in. I want to plug these points back into
>my f(x). How can I do this. Look at the following example:
>
>possmax = Solve[(x - 1)^2 == 0,x] // N
>
>I get {{x -> 1.},{x ->1.}}
>and when I try
>
>possmax[[1]]
>
>I get {x ->1.}
>
>but I want the number 1 instead.
>
>I know this if probably extremely basic, but due to lack of available
>documentation here, I can not figure it out.
>
>
>P.S. another useful trick to know would be how many objects are in a
>list. My function a bit more complicated (compositions, logs etc.), and I
>don't exactly how many solutions I will have from the Solve[ ] statement.
>
>--
>
>Rob Carscadden
>carscadd at pps.duke.edu
>http://www.duke.edu/~cars
>49% of all Statistics are made up on the spot!
>
>
>
>
>
Rob,
To answer your first question, suppose you want to put both solutions into an expression called
exp1 that is also a function of x :
exp1 = 5 x -3. The ReplaceAll operator (forward slash then period) will replace all
occurrences of x in exp1 with the values you obtain for possmax if you do the following :
exp1 /. possmax
Your answer will be in the form of a list, with each element of the list corresponding to one
of your x values in possmax. If you want only one solution, then do the following :
exp1 /. possmax[[1]] or
exp1 /. possmax[[2]]
To answer your second question, use the Length command :
Length[possmax] gives you an answer of 2. For a list such as : list = { {1,2},{3,4} },
Length[list] also gives an answer of 2.
Good luck. I had to learn Mathcad without the benefit of the book, so I know how you feel.
BTW, unlike Mathcad, Stephen Wolfram's MMA book is readily available in most large bookstores
for around $50.
Dave Harvatin
dtharvat at sprint.uccs.edu