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},
PlotRange->{{0 , 2 Pi},{-1.2,1.2}}] ,
{s, 0, 2 Pi, Pi/20, ControlPlacement -> Top} ]
Clear[gg,x];
gg[x_]:= 1- 2 Exp[(x^2)(Cos[x]-1)]
FindRoot[gg[x] == 0, {x, 1},
AccuracyGoal -> Infinity, PrecisionGoal -> 12,
MaxIterations -> 1000, WorkingPrecision -> 16]
{x /. FindRoot[gg[x] == 0, {x, 2 # Pi - .1},
AccuracyGoal -> Infinity, PrecisionGoal -> 12,
MaxIterations -> 1000, WorkingPrecision -> 16],
x /. FindRoot[gg[x] == 0, {x, 2 # Pi + .1},
AccuracyGoal -> Infinity, PrecisionGoal -> 12,
MaxIterations -> 1000, WorkingPrecision -> 16]} & /@ Range[1, 12]
Table[
{x /. FindRoot[gg[x] == 0, {x, 2 k Pi - .1},
AccuracyGoal -> Infinity, PrecisionGoal -> 12,
MaxIterations -> 1000, WorkingPrecision -> 16],
x /. FindRoot[gg[x] == 0, {x, 2 k Pi + .1},
AccuracyGoal -> Infinity, PrecisionGoal -> 12,
MaxIterations -> 1000, WorkingPrecision -> 16]},
{k,1, 12}]
Table[{x /. FindRoot[gg[x] == 0, {x, 2 nn Pi - 2/10, 2 nn Pi}, MaxIterations -> 1000, WorkingPrecision -> 100, Method -> "Brent"], 2 nn Pi, x /. FindRoot[gg[x] == 0, {x, 2 nn Pi, 2 nn Pi + 2/10}, MaxIterations -> 1000, WorkingPrecision -> 100, Method -> "Brent"]}, {nn, 1, 25}]
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]])
Clear[mM];
mM = { {1,2,3}, {4,5,6}, {7,8,9} }
Clear[mM];
MatrixForm[mM]
Clear[mM];
mM.{1,-2,1}
Clear[mM];
mM.{{1,1}, {-2,1}, {1,1} }
FullSimplify[
Transpose[Eigensystem[mM][[2]]].DiagonalMatrix[
Eigensystem[mM][[1]]
].Inverse[Transpose[Eigensystem[mM][[2]]]]]
Clear[mA];
mA = Partition[Range[30],6]
Now I will split the matrix mA in four blocks using all the entries of mA only once. mA11=Take[mA,3,2], mA12=Take[mA,3,-4], mA21=Take[mA,-2,2], mA22=Take[mA,-2,-4].
Now we have four matrices. The command ArrayFlatten[] allows us to use smaller matrices to form a bigger one. To illustrate the command ArrayFlatten[] we reconstruct the matrix mA from the smaller pieces that we formed in the preceding paragraph.
ArrayFlatten[{{mA11, mA12}, {mA21, mA22}}]
The result of the preceding command should be exactly the matrix mA.
The logic of the preceding command is that we write a $2\!\times\!2$ matrix which consists of matrices whose dimensions match. The command ArrayFlatten[] makes one big matrix of the four blocks.
Clear[RowReduceAug,b];
RowReduceAug[mat_] := Module[{mm, rrm},
mm = Length[mat];
rrm = Take[ RowReduce[
ArrayFlatten[{{mat, IdentityMatrix[mm]}}]
] ,All,-mm];
rrm.Transpose[Append[Transpose[mat], Array[b, mm]]]]
rrm = Take[ RowReduce[
ArrayFlatten[{{mat, IdentityMatrix[mm]}}]
] ,All,-mm];