Grafika v Mathematici

Andrej Bauer

Risanje grafov

Plot[Sin[x],{x,-5,5}]

ParametricPlot[{Cos[t],Sin[t]},{t,0,2π}]

ParametricPlot[{Cos[9*t],Sin[5*t]},{t,0,2π}]

ParametricPlot[{Sin[t],Sin[2*t]},{t,0,2π}]

VectorPlot[{(x/(1+(x^2)+(y^2))),y},{x,-3,3},{y,-3,3}]

Plot3D[(Sqrt[(x^2)+(2+Sin[3*x+y])*(y^2)]),{x,-2,2},{y,-2,2}]

DensityPlot[(Sqrt[(x^2)+(2+Sin[3*x+y])*(y^2)]),{x,-2,2},{y,-2,2}]

ContourPlot[(Sqrt[(x^2)+(2+Sin[3*x+y])*(y^2)]),{x,-2,2},{y,-2,2}]

ContourPlot[(Sqrt[(x^2)+(2+Sin[3*x+y])*(y^2)])==2,{x,-2,2},{y,-2,2}]

ContourPlot[(((x+2*y))^2)+(((y-1))^2)==3,{x,-7,3},{y,-3,3},Axes->True]

PolarPlot[(ϕ/(1+(ϕ^2))),{ϕ,0,30π},PlotRange->All]

ParametricPlot3D[{Cos[t],Sin[t],t/10},{t,0,20π}]

ParametricPlot3D[{Cos[u],Sin[u],v},{u,0,2π},{v,0,3}]

ParametricPlot3D[{Cos[3u+v/4],Sin[u],v*Cos[u]},{u,0,2π},{v,0,3}]

ParametricPlot3D[{v*Cos[u],v*Sin[u],v},{u,0,2π},{v,-1,1}]

ParametricPlot3D[{(Sqrt[1-(v^2)])*Cos[u],(Sqrt[1-(v^2)])*Sin[u],v},{u,0,2π},{v,-1,1}]

VectorPlot3D[{-y,z,x},{x,-2,2},{y,-2,2},{z,-2,2}]

ListPlot[{1,2,5,4,3,2,1,5,4,3}]

Graphics in Graphics3D

V Mathematici lahko predstavimo 2D in 3D grafične objekte z ukazoma Graphics in Graphics3D. Grafične objekte naštejemo v seznamu.

Graphics[
{
Circle[{1,1},2],
Point[{1,0}],
Line[{{0,0}, {3,4}, {4,3}}]
}
]

Graphics3D[{
Cylinder[{{0,0,0},{1,2,1}},1/3],
Sphere[{0,0,3},1/2], 
Polygon[{{0,0,1},{1,0,0},{1,1,1}}]}]

Poleg objektov lahko določamo tudi barve in ostale lastnosti. Objekti so lahko hierarhično gnezdeni v sezname in podsezname.

Graphics[
{
 {Thickness[0.01],Dashing[{0.1,0.05}], Line[{{-4,0},{4,0},{4,5},{-4,5}, {-4,0}}]},
{Red,Polygon[{{-5,5},{5,5},{0,7}}]}
}
]

Graphics[Table[Line[{{0,0},{Cos[k*2π/100],Sin[k*2π/100]}}],{k,1,100}]]

Graphics[
{
Circle[{0,0},1],
Table[Line[{{0,0},{Cos[k*2π/100],Sin[k*2π/100]}}],{k,1,100}]
}]

Graphics[
{
Circle[{0,0},1],
Table[{Hue[k/100],Line[{{0,0},{Cos[k*2π/100],Sin[k*2π/100]}}]},{k,1,100}]
}]

ClearAll[mavrica]
mavrica[n_]:=Graphics[
{
Circle[{0,0},1],
Table[{Hue[k/n],Line[{{0,0},{Cos[k*2π/n],Sin[k*2π/n]}}]},{k,1,n}]
}]

mavrica[20]

mavrica[300]

Manipulate

Plot[Sin[4*x+3],{x,-4,4}]

Manipulate[
Plot[Sin[a*x+b],{x,-4,4}],
{a,-5,5},{b,-3,3}
]

Z ukazom Manipulate lahko prikažemo grafični objekt, ki je odvisen od parametrov.

Izračunajmo tangento v točki (Subscript[x, 0]) na funkcijo y = f[x]:

ClearAll[f]

f'[x0]*x+n/.Solve[f[x0]==f'[x0]*x0+n,n]

ClearAll[tangenta]
tangenta::usage="tangenta[f[x],x,(Subscript[x, 0])] je enačba tangente na f[x] v točki x = (Subscript[x, 0])";
tangenta[f_,x0_,x_]:=Function[t,f'[x0]*(t-x0)+f[x0]][x]

ClearAll[f]
f[t_]:=Cos[t]*t
Manipulate[
Plot[{f[x],tangenta[f,x0,x]},{x,-5,5},PlotRange->{{-5,5},{-5,5}},AspectRatio->Automatic],
{{x0,2},-5,5}]

Manipulate[Expand[(((a+b))^k)],{k,0,10,1}]

Animate

Animacije delamo z ukazom Animate, ki sicer deluje podobno kot Manipulate, le da samodejno spreminja vrednost parametra.

ClearAll[f]
f[t_]:=Cos[t]*t
Animate[Plot[{f[x],tangenta[f,x0,x]},{x,-5,5},PlotRange->{{-5,5},{-5,5}},AspectRatio->Automatic],{x0,-5,5}]

Animate[
Graphics[{Hue[r],Disk[{0,0},1/2+Sin[π*5*r]/3]},PlotRange->{{-1,1},{-1,1}}],{r,0,1}]