Re: Very very basic question about Mathematica expressions

• To: mathgroup at smc.vnet.net
• Subject: [mg111126] Re: Very very basic question about Mathematica expressions
• From: Helen Read <hpr at together.net>
• Date: Wed, 21 Jul 2010 07:12:52 -0400 (EDT)
• References: <i23k1j\$epv\$1@smc.vnet.net>

```On 7/20/2010 3:42 AM, Sam Takoy wrote:
> Hi,
>
> I find that I don't understand a very basic thing about the building
> blocks of Mathematica.
>
> When the first command is
>
> s = x + h
>
> I figured that (string?) "s" represents (string?) "x+h".

To make it a string, i.e., a sequence of text characters, you would
enter the following.

s="x+h"

Strings are useful for lots of things, but I don't think a string is
what you intend. What you have instead is an expression.

> But then by doesn't this work:
>
> Manipulate[ Plot[s, {x, 0, h}], {h, 0.1, 1}]
>

Manipulate needs to know that s is a function of both x and h.

Clear[s]

s[x_,h_]:=x+h

Also you should put an explicit PlotRange in your Plot, so that
Manipulate doesn't go changing the scale on you.

Try it without a PlotRange:

Manipulate[
Plot[s[x, h], {x, 0, h}]

And see how much better it is with one.

Manipulate[
Plot[s[x, h], {x, 0, h}, PlotRange -> {{0, 1}, {0, 1}}], {h, 0.1, 1}]

Defining functions is a very basic idea in Mathematica, and worth
getting used to.

For example, suppose you want to find the extrema of the function

f(x)= -84 x + 9 x^2 + 4 x^3 + 25

So define it as a function.

f[x_] := -84 x + 9 x^2 + 4 x^3 + 25

Plot[f[x], {x, -10, 10}]

Might want to see the 1st derivative along with it.

Plot[{f[x], f'[x]}, {x, -10, 10}]

Solve[f'[x] == 0, x]

f[-7/2]

f[2]

--