Message Boards Message Boards

0
|
3069 Views
|
4 Replies
|
0 Total Likes
View groups...
Share
Share this post:
GROUPS:

How do I write this function in Mathematica?

Posted 5 years ago

Hello! I am enjoying using Mathematica on a daily basis, but as I am a newbie I do not manage to do everthing I want , yet.

How do I tell Mathematica to compute f(f(x)) when f(x)=(x+3)^2 or something like that?

Best regards, Ulf Karlsson

POSTED BY: Ulf Karlsson
4 Replies

Thanks!

//Ulf

POSTED BY: Ulf Karlsson
Posted 5 years ago

Basically,

f[x_]:=(x+3)^2

would define a function of the variable x. Such that f[1]=16 and f[-1]=4 etc. Then you can write f[f[x]]

You can also write

f@f@x

See here and here. This latter link is a good resource in my opinion.

Good luck!

And glad to help.

POSTED BY: Ehud Behar

I would do it this way:

f[x_] := (x + 3)^2;
f[f[x]]

Beware the difference between square brackets and round parentheses, and between the pattern x_ and the variable x.

POSTED BY: Gianluca Gorni

Thanks!

//Ulf

POSTED BY: Ulf Karlsson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract