Define certain functions?

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

f[x_]:=x Sin[x]

g[x_]:=-Abs[x]

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]}]

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