f[x_]:=x^2+x+1
My recommendation is to use more complicated names for functions to avoid duplication and to always clear the string that you are using as the name. So, a better way here would be to writeClear[myf,x]; myf[x_]:=x^2+x+1
Pi*2^(1/2)
and Shift+Enter.N[Pi*2^(1/2)]
and, as always, Shift+Enter.Exp[x], Log[x], Sin[x], Cos[x], Abs[x], ...
or some which are for some mysterious reason absent from our curriculum:Sign[x], Floor[x], Ceiling[x], UnitStep[x], ...
Please see the menu itemPlot[Sin[x],{x,0,2*Pi}]
Here Sin[x] is one variable, and the domain {x,0,2*Pi} is another variable. But this function can have many more variables. Options[Plot] will give you all. Plot[
{Sin[x],Cos[x]}, {x,0,2*Pi},
PlotStyle->{{Thickness[0.007],Blue},{Thickness[0.007],Green}},
PlotRange->{-2,2}
]
Plot3D[ Sin[x]*Cos[y], {x,0,2*Pi}, {y,0,2*Pi} ]
plots a function of two variables.D[Sin[3 x]^2 + Cos[4 x], x]
finds the derivative with respect of x.Simplify[D[Sin[3 x]^2 + Cos[4 x], x]]
finds an algebraically simpler form of the previous answer. Sometimes FullSimplify[] gives more desirable results.Integrate[-4 Sin[4 x] + 3 Sin[6 x], x]
finds an antiderivative.Table[Sin[x + s],{s, 0, 2 Pi, Pi/20}]
produces a list of forty-one shifts of the sine function.Plot[ Evaluate[Table[Sin[x + s],{s, 0, 2 Pi, Pi/20}]], {x, 0 , 2 Pi} ]
Manipulate[ Plot[Evaluate[Sin[x + s]],{x, 0 , 2 Pi}], {s, 0, 2 Pi, Pi/20} ]
Clear[ff,x];
ff[x_]:= 1- 2 Exp[(x^2)(Cos[x]-1)]
Clear[f1, f2, f3, x];
f1[x_] = Random[] + x*Random[];
f2[x_] = Random[] + x*Random[];
f3[x_] = Random[] + x*Random[];
Plot[
{f1[x],f2[x],f3[x]}, {x,-5,5},
PlotStyle->{{Thickness[0.007],Red},
{Thickness[0.007],Green}, {Thickness[0.007],Blue}},
PlotRange->{-5,5}, AspectRatio->Automatic
]
Clear[g,x];
g[x_]:= Random[] + x*Random[];
Clear[Repeat, n];
Repeat[1] = 1;
Repeat[n_]:= Repeat[n - Repeat[n - 1]] + 1
Timing[Repeat[60]]
On my computer it takes 2.735 seconds to calculate that Repeat[60] = 11. The reason for this is that as defined above the function Repeat[] does not remember any values that it calculates. We can make Mathematica remember all the function values it finds by changing the syntax in the definition:
Clear[Repeat, n];
Repeat[1] = 1;
Repeat[n_]:= Repeat[n] = Repeat[n - Repeat[n - 1]] + 1
Table[Repeat[k], {k, 1, 106} ]
or by plotting its graph (which consists of points with integer coordinates)
Show[
Graphics[{
{PointSize[0.015], Table[Point[{k, Repeat[k]}], {k, 1, 106}]}
}],
PlotRange -> {{0, 107}, {0, 15.5}},
Frame -> True, ImageSize -> 400
]
Show[
Graphics[{ (* the start of the graphics, it is a list *)
{ (* the grid lines are in this list *)
Thickness[0.003], GrayLevel[0.8],
Table[Line[{{0, j}, {107, j}}], {j, 1, 15}],
Table[Line[{{j(j + 1)/2, 0}, {j(j + 1)/2, 16}}], {j, 1, 15}]
}, (* the next list are the points on the graph*)
{PointSize[0.015], Blue, Table[Point[{k, Repeat[k]}], {k, 1, 107}]}
}], (* the end of the graphics *)
PlotRange -> {{0, 107}, {0, 15.5}},
AspectRatio -> 1/2,
Frame -> True,
FrameTicks -> {Table[j(j + 1)/2, {j, 1, 15}], Range[1, 15], {}, Range[1, 15]},
ImageSize -> 400
]
Clear[Rf1, Rf2, Rf3, n];
Rf1[n_]:= Round[Sqrt[2*n]];
Rf2[n_]:= Floor[(1/2) + Sqrt[2*n]];
Rf3[n_]:= Ceiling[(-1/2) + Sqrt[2*n]];
Table[
{k, Repeat[k], Rf1[k], Rf2[k], Rf3[k]},
{k, 1, 100}
]//TableForm
Clear[W, n];
W[1] = 1; W[2] = 1;
W[n_]:= W[n] = W[n - W[n - 1]] + 2
Clear[Wf1, n];
Wf1[n_]:= 2*Floor[Sqrt[n]]-(-1)^(n+Ceiling[Sqrt[n]])