Grafika v Mathematici

Andrej Bauer

Risanje grafov

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

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

ParametricPlot[{Cos[5*x],Sin[7*x]},{x,0,2π}]

VectorPlot[{y,x},{x,-3,3},{y,-3,3}]

VectorPlot[{-y,x},{x,-3,3},{y,-3,3}]

VectorPlot[{-y*Cos[3*x],(x^2)Sin[4*y]},{x,-5,5},{y,-5,5}]

Plot3D[(x^2)-(y^2),{x,-3,3},{y,-3,3}]

Plot3D[((Cos[x*y+y])/(1+(x^2)+(y^2))),{x,-3,3},{y,-3,3},PlotRange->All]

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

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

ContourPlot[((Cos[x*y+y])/(1+(x^2)+(y^2)))==1/2,{x,-3,3},{y,-3,3}]

ContourPlot[(((x-1))^2)+(((y+1))^2)==2,{x,-5,5},{y,-5,5}]

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

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

ParametricPlot3D[{Cos[t],Sin[t],t/10},{t,-40,40}]

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

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

Histogram[Table[Mod[(k^2)+3k,17],{k,1,1000}]]

ListPlot[Table[Mod[(k^2)+3k,17],{k,1,1000}]]

ListPlot[Table[(k^2),{k,1,100}]]

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

Graphics[
{
Circle[{1,1},2], 
Point[{1,0}],
Line[{{0,0}, {3,4}, {4,3}}]
},
Axes->True
]

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}}]
},
Boxed->False]

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

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

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

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

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

soncek[700]

Manipulate

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

Manipulate[
Plot[Sin[a*x+b],{x,-4,4}],
{a,-2,2},
{b,0,4}
]

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

Manipulate[
ParametricPlot3D[{(r+Cos[v])*Cos[u],(r+Cos[v])*Sin[u],Sin[v]},{u,0,2π},{v,0,2π},
PlotRange->{{-5,5},{-5,5},{-5,5}}],
{{r,3},-5,5}
]

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

ClearAll[tangenta]
tangenta[f_,x0_,x]=

Kako napišemo v Mathematici funkcijski predpis x ↦(x^2)+3?

Function[x,(x^2)+3]

Function[x,(x^2)+3][3+u]

Za hackerje:

(((#)^2)+3)&

(((#)^2)+3)&[3+u]

(If[#1==0,1,#1*#0[#1-1]])&[10]

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

Manipulate[Expand[(((x+y))^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}]