Message Boards Message Boards

0
|
5272 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Define certain functions?

Posted 8 years ago

Hi, I'm new to using mathematica and I'm having trouble defining certain functions.

I'm trying to define

f[x_]:= x [Sin[x]] 

and

g[x_]:= - Abs[x]

but I'm not sure how to type x sinx in or how to format the negative absolute value correctly so that I can plot the functions later on.

Any help would be appreciated. thanks

POSTED BY: Charlie S
2 Replies

Hi,

There are two ways to try:

You can define via a pure function

f = # Sin[#] &;
g = -Abs[#] &;

Here, # stands for x in the context or your example. Cap it off with an ampersand '&' when using this notation.

Which are evaluated as

In[23]:= f[\[Pi]]

Out[23]= 0

In[24]:= g[-10]

Out[24]= -10

And can be plotted by

Plot[{f[x], g[x]}, {x, 0, 2 \[Pi]}]

enter image description here

Or by

Clear[f, g];
f[x_] := x*Sin[x];
g[x_] := -Abs[x];

Which can be evaluated in the same way described above

Hope this helps.

Ben

POSTED BY: Benjamin Goodman

f[x_]:=x Sin[x]

g

POSTED BY: S M Blinder
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