Kurs Komputerowy S
System Symboliczny
Mathematica

Grafika

{zakres x}   = >   {x, wart_min, wart_max}

Wykresy 2D

Plot[wyrazenie,{zakres x}]
ParametricPlot[{wyrazenie_x, wyrazenie_y}, {zakres t}]
PolarPlot[promien, {zakres θ}]

Plot[Sin[x],{x,0,Pi}]

Plot[{Sin[x],Cos[x]},{x,-Pi,Pi}]

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

ParametricPlot[{{4Sin[x],4Cos[x]},{Sin[x]-1.6,Cos[x]+2},{Sin[x]+1.6,Cos[x]+2},{Sin[x]/4-1.1,Cos[x]/2+2},{Sin[x]/4+1.1,Cos[x]/2+2},{2Sin[x],Cos[x]/2-2}},{x,0,2Pi}]

PolarPlot[Sin[3x],{x,0,2Pi}]

PolarPlot[{1,Sin[3x]},{x,0,2Pi}]

Options[Plot]

Wykresy 3D

Plot3D[wyrazenie, {zakres x}, {zakres y}]
ParametricPlot3D[{wyrazenie_x, wyrazenie_y, wyrazenie_z}, {zakres t}]
ContourPlot3D[wyrazenie,{zakres x}, {zakres y}]
RegionPlot3D[warunki, {zakres x}, {zakres y}]
RevolutionPlot3D[wyrazenie, {zakres r}]

Plot3D[Sin[x]*Cos[y],{x,-Pi,Pi},{y,0,2Pi}]

ParametricPlot3D[{Sin[x],Cos[x],Sin[x]Cos[x]},{x,0,2Pi}]

ParametricPlot3D[{Cos[x]Cos[y],Sin[x]Cos[y],Sin[y]},{x,0,2Pi},{y,-Pi/2,Pi/2}]

ContourPlot3D[(2x^2-y^3)*Sqrt[z],{x,-4,4},{y,-2,2},{z,0,2}]

ContourPlot3D[(2x^2-y^3)*Sqrt[z]==2,{x,-4,4},{y,-2,2},{z,0,2}]

RegionPlot3D[(2x^2-y^3)*Sqrt[z]<2,{x,-4,4},{y,-2,2},{z,0,2}]

RevolutionPlot3D[x^2,{x,1,4}]

RevolutionPlot3D[x^2,{x,1,4},{θ,0,3/2Pi}]

Wykresy 3D na plaszczyznie

ContourPlot[wyrazenie, {zakres x}, {zakres y}]
DensityPlot[wyrazenie, {zakres x}, {zakres y}]
RegionPlot[warunki, {zakres x}, {zakres y}]

Plot3D[Sin[x]*Cos[y],{x,-Pi,Pi},{y,0,2Pi}]

ContourPlot[Sin[x]*Cos[y],{x,-Pi,Pi},{y,0,2Pi}]

DensityPlot[Sin[x]*Cos[y],{x,-Pi,Pi},{y,0,2Pi}]

RegionPlot[Sin[x]*Cos[y]>0,{x,-Pi,Pi},{y,0,2Pi}]

Wykresy funkcji numerycznych

ListPlot[lista]
ListPlot3D[macierz]
ListContourPlot[macierz]
ListDensityPlot[macierz]
ListContourPlot3D[macierz]

ListPointPlot3D[macierz]
DiscretePlot[wyrazenie, iterator]
ListLinePlot[lista]

ListPolarPlot[lista]

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

d=Table[{x,x+RandomReal[2]-1},{x,20}]
ListPlot[d]

d=Table[Sin[x]Cos[y],{x,-Pi,Pi,0.5},{y,0,2Pi,0.5}];
ListPlot3D[d]

ListContourPlot[d]

ListDensityPlot[d]

d=Table[Sin[x]Cos[y],{x,-Pi,Pi,0.1},{y,0,2Pi,0.1}];
ListPointPlot3D[d]

DiscretePlot[Ceiling[i],{i,1,20,0.3}]

ListLinePlot[Table[Ceiling[i],{i,1,20,0.3}]]

ListPolarPlot[Table[Ceiling[i],{i,1,20,0.3}]]

Diagramy

TreePlot[lista_polaczen]
GraphPlot[lista_polaczen]
GraphPlot3D[lista_polaczen]
LayeredGraphPlot[lista_polaczen]

TreePlot[{1->4,1->6,1->8,2->6,3->8,4->5,7->8}]

TreePlot[{1->4,1->6,1->8,2->6,3->8,4->5,7->8},VertexLabeling->True]

GraphPlot[{1->4,1->6,1->8,2->6,3->8,4->5,7->8}]

GraphPlot[{1->4,1->6,1->8,2->6,3->8,4->5,7->8},VertexLabeling->True]

GraphPlot3D[{1->4,1->6,1->8,2->6,3->8,4->5,7->8}]

GraphPlot3D[{1->2,1->3,1->4,1->5,2->3,2->4,2->5,3->4,3->5,4->5}]

LayeredGraphPlot[{1->4,1->6,1->8,2->6,3->8,4->5,7->8}]

Options[LayeredGraphPlot]

Opcje

Options[polecenie]

Options[Plot]

Plot[{Sin[x],Cos[x]},{x,0,2Pi}]

Plot[{Sin[x],Cos[x]},{x,0,2Pi},PlotStyle->{{RGBColor[1,0,0],Dashing[{0.08,0.04}]},{RGBColor[0,1,0],Thickness[0.01],Dashing[{0.02}]}},PlotLabel->"Wykresy funkcji sin(x) i cos(x)",AxesLabel->{"x",""},Ticks->{Table[z,{z,0,2Pi,Pi/2}],{{-1.0,"-1.0"},-0.5,0.0,0.5,{1.0,"1.0"}}},Background->RGBColor[0,1,1],Filling->Axis,PlotRange->{{-Pi/2,5/2Pi},All},GridLines->{None,{-1,-Sqrt[2]/2,-0.5,0.5,Sqrt[2]/2,1}},GridLinesStyle->Dashing[{0.02}],LabelStyle->RGBColor[1,0,0]]

Options[Plot3D]

Obiekty graficzne

Graphics[lista_obiektow]
Graphics3D[lista_obiektow]

primitives (obiekty)

Point[{x,y}]
Line[{{x1,y1},...}]
Arrow[{{x1,y1},...}]
Polygon[{{x1,y1},...}]
Rectangle[{x1,y1},{x2,y2}]
Circle[{x,y},r]
Disk[{x,y},r]
BezierCurve[{{x1,y1},...}]
BSplineCurve
Text[wyrazenie,{x,y}]

Graphics[Point[{0,0}]]

Graphics[Line[{{0,0},{1,1},{2,1}}]]

Graphics[Arrow[{{0,0},{1,1},{2,1}}]]

Graphics[Polygon[{{0,0},{1,1},{2,1}}]]

Graphics[Rectangle[{0,0},{2,1}]]

Graphics[Circle[{0,0},1]]

Graphics[Disk[{0,0},1]]

pt={{0,0},{1,1}};Graphics[{BezierCurve[pt],Point[pt]}]

pt={{0,0},{1,1},{2,0}};Graphics[{BezierCurve[pt],Point[pt],Dashing[{0.02}],Line[pt]}]

pt={{0,0},{1,1},{2,0},{3,1}};Graphics[{BezierCurve[pt],Point[pt],Dashing[{0.02}],Line[pt]}]

pt={{0,0},{1,1},{2,0},{3,1},{4,0},{5,1}};Graphics[{BezierCurve[pt],Point[pt],Dashing[{0.02}],Line[pt]}]

pt={{0,0},{1,1},{2,0},{3,1},{4,0},{5,1}};Graphics[{BSplineCurve[pt],Point[pt],Dashing[{0.02}],Line[pt]}]

Graphics[{Text[2+x^2+5x,{0,0}],Point[{0,0}]}]

colors

White
Black
Gray -        LightGray
Red -         LightRed
Green -     LightGreen
Blue -        LightBlue
Cyan -       LightCyan
Magenta - LightMagenta
Yellow -     LightYellow
Brown -      LightBrown
Orange -   LightOrange
Pink -        LightPink
Purple -    LightPurple

directives (parametry)

GrayLevel[n]
Hue[h]
RGBColor[r,g,b]
CMYKColor[c,m,y,k]
Opacity[a]
PointSize[d]
Thicknes[d]
Dashing[{d1,...}]
AbsolutePointSize[d]
AbsoluteThicknes[d]
AbsoluteDashing[{d1,...}]

Directive[g1,...]
Arrowheads[spec]
CapForm[spec]
EdgeForm[g]
FaceForm[g]
JoinForm[spec]

d=0.01;
Graphics[Table[{GrayLevel[i],Polygon[{{i,0},{i+d,0},{i+d,1},{i,1}}]},{i,0,1,d}],AspectRatio->0.125,Axes->{True,False}]

d=0.01;
Graphics[Table[{Hue[i],Polygon[{{i,0},{i+d,0},{i+d,1},{i,1}}]},{i,0,1,d}],AspectRatio->0.125,Axes->{True,False}]

d=0.01;
Graphics[{Table[{RGBColor[r,g,0.5],Polygon[{{r,g},{r+d,g},{r+d,g+d},{r,g+d},{r,g}}]},{r,0,1,d},{g,0,1,d}],Table[{RGBColor[0,0,b],Polygon[{{1.1,b},{1.2,b},{1.2,b+d},{1.1,b+d},{1.1,b}}]},{b,0,1,d}]},Frame->True,FrameLabel->{"r","g","","b"},FrameTicks->{{All,All},{Join[Table[{i,"",{0.008,0}},{i,0,1,0.05}],Table[{i,NumberForm[i,{1,1}]},{i,0,1,0.2}]],None}},RotateLabel->False]

Graphics[{GrayLevel[0.5],Polygon[{{0,0},{1,0},{0,1}}]}]

Graphics[{Hue[0.5],Polygon[{{0,0},{1,0},{0,1}}]}]

Graphics[{RGBColor[1,0,1],Polygon[{{0,0},{1,0},{0,1}}]}]

Graphics[{CMYKColor[0.5,0,1,0],Polygon[{{0,0},{1,0},{0,1}}]}]

Graphics[{Rectangle[{0.25,0.25},{0.75,0.75}],RGBColor[1,0,0],Opacity[0.5],Polygon[{{0,0},{1,0},{0,1}}]}]

Graphics[{Rectangle[{0.25,0.25},{0.75,0.75}],Opacity[0.5,RGBColor[0,1,0]],Polygon[{{0,0},{1,0},{0,1}}]}]

Graphics[{Point[{0,0}],PointSize[0.05],Point[{1,0}],PointSize[0.1],Point[{2,0}]}]

Graphics[{Line[{{0,0},{0,1}}],Thickness[0.05],Line[{{1,0},{1,1}}],Thickness[0.1],Line[{{2,0},{2,1}}]}]

Graphics[{Line[{{0,0},{0,1}}],Dashing[{0.05}],Line[{{1,0},{1,1}}],Dashing[{0.04,0.02}],Line[{{2,0},{2,1}}]}]

Graphics[{Arrowheads[.2],Arrow[{{0,0},{1,1}}],Arrowheads[{-0.1,0.1}],Arrow[{{1,0},{1/2,1/2}}]}]

Show[obiekt]

p=Graphics[Circle[{0,0},1]];
q=Graphics[Line[{{-1,-1},{1,1},{1,-1},{-1,1},{-1,-1}}]];
Show[p,q]

Clear[p];
p1=Plot[x^2,{x,-2,2}];
p2=Plot[(x-4)^2,{x,2,4}];
p3=Plot[(x+4)^2,{x,-4,-2}];
p4=Plot[-2-Abs[Sin[10x]/5],{x,-5,5}];
p5=Graphics[{Line[{{-2,-2},{-2,4}}],Line[{{2,-2},{2,4}}],Line[{{-4,0},{4,0}}]}];
p[x_]:=Graphics[{Line[{{x+0.2,-3.2},{x-0.14,-2.86}}],Line[{{x+0.2,-2.8},{x-0.14,-3.14}}],Point[{x-0.286,-3}],Circle[{x-0.286,-3},0.2,{Pi/4,7Pi/4}],Line[{{x+0.2,-3.2},{x+0.2,-2.8}}]}];
Show[p1,p2,p3,p4,p5,p[-2],p[1],PlotRange->{{-4,4},All},Axes->False]

w=Plot[Sin[x],{x,0,2Pi}]

Show[w,PlotRange->{-0.5,0.5},Axes->False]

Przyklady

bx=6Cos[u](1+Sin[u]);
by=16Sin[u];
rad=4(1-Cos[u]/2);
X=If[Pi<u≤2Pi,bx+rad Cos[v+Pi],bx+rad Cos[u]Cos[v]];
Y=If[Pi<u≤2Pi,by,by+rad Sin[u]Cos[v]];
Z=rad Sin[v];
ParametricPlot3D[{X,Y,Z},{u,0,2Pi},{v,0,2Pi},PlotPoints->{48,12},Axes->False,Boxed->False]

p1r=ParametricPlot3D[{-3+Sin[p],Sin[t](2+Cos[p]),Cos[t](2+Cos[p])},{t,0,2Pi},{p,0,2Pi}];
p1g=ParametricPlot3D[{Sin[p],Sin[t](2+Cos[p]),Cos[t](2+Cos[p])},{t,0,2Pi},{p,0,2Pi}];
p1b=ParametricPlot3D[{3+Sin[p],Sin[t](2+Cos[p]),Cos[t](2+Cos[p])},{t,0,2Pi},{p,0,2Pi}];
p2=ParametricPlot3D[{u,Cos[t],Sin[t]},{t,0,2Pi},{u,-6,6}];
p5a=ParametricPlot3D[{7.5+2Sin[p],2Sin[t]Cos[p],2Cos[t]Cos[p]},{t,0,2Pi},{p,-Pi/3,Pi/2}];
p5b=ParametricPlot3D[{-7.5+2Sin[p],2Sin[t]Cos[p],2Cos[t]Cos[p]},{t,0,2Pi},{p,Pi/2,-Pi/3}];
Show[p1r,p1g,p1b,p2,p5a,p5b,Axes->False,Boxed->False,PlotRange->{-6,6}]

Animacje

Animate[wyrazenie,iterator}
ListAnimate[{lista}]
Manipulate[wyrazenie,iterator]

Do[Print[Plot[Sin[t x],{x,0,2Pi}]],{t,1,20}]

Animate[Plot[Sin[t x],{x,0,2Pi}],{t,1,20}]

t1={};
Do[AppendTo[t1,Plot[Sin[t x],{x,0,2Pi}]],{t,1,20}]

ListAnimate[t1]

Animate[t1[[i]],{i,1,Length[t1]}]

Animate[Plot[Sin[a x]+Sin[ x],{x,0,10},PlotRange->2],{a,1,15}]

Animate[Plot[Sin[a x]+Sin[ x],{x,0,10},PlotRange->2],{a,1,15},AnimationRunning->False]

Manipulate[Show[p1,p2,p3,p4,p5,p[i],p[i+3],PlotRange->{{-4,4},All},Axes->False],{i,5,-8,-0.5}]

Manipulate[Graphics[{PointSize[0.05],Point[{n1,n2}]},PlotRange->{{-1,1},{-1,1}}],{n1,-1,1},{n2,-1,1}]

Manipulate[Graphics[{PointSize[0.05],Point[{n1,n2}]},PlotRange->{{-1,1},{-1,1}}],{n1,-1,1},{n2,-1,1,Appearance->"Labeled"}]

Manipulate[Graphics[{PointSize[0.05],Point[{n1,n2}]},PlotRange->{{-1,1},{-1,1}}],{{n1,0},-1,1},{{n2,0},-1,1}]

Manipulate[Graphics[{PointSize[0.05],Point[{n1,n2}]},PlotRange->{{-1,1},{-1,1}}],{{n1,0,"wspolrzedna x"},-1,1},{{n2,0,"wspolrzedna y"},-1,1}]

Manipulate[Graphics[{PointSize[0.05],Point[n1]},PlotRange->{{-1,1},{-1,1}}],{n1,{-1,-1},{1,1}}]

Manipulate[Graphics[{PointSize[0.05],Point[n1]},PlotRange->{{-1,1},{-1,1}}],{{n1,{0,0}},{-1,-1},{1,1}}]

Manipulate[Graphics[{PointSize[0.05],Point[n1]},PlotRange->{{-1,1},{-1,1}}],{{n1,{0,0},"{x,y}"},{-1,-1},{1,1}}]

Manipulate[Graphics[{Thickness[0.01],Arrowheads[0.1],Arrow[{n1,n2}]},PlotRange->{{-1,1},{-1,1}}],{{n1,{0,0},"{x,y}"},{-1,-1},{1,1}},{{n2,{1,1}},Locator}]

px[x_]:=Graphics[{Line[{{x[[1]]+0.2,x[[2]]-3.2},{x[[1]]-0.14,x[[2]]-2.86}}],Line[{{x[[1]]+0.2,x[[2]]-2.8},{x[[1]]-0.14,x[[2]]-3.14}}],Point[{x[[1]]-0.286,x[[2]]-3}],Circle[{x[[1]]-0.286,x[[2]]-3},0.2,{Pi/4,7Pi/4}],Line[{{x[[1]]+0.2,x[[2]]-3.2},{x[[1]]+0.2,x[[2]]-2.8}}]}];

Manipulate[Show[px[n-{2,0}],px[n+{2,0}],PlotRange->{{-10,10},{-8,0}}],{{n,{0,0}},Locator}]

Manipulate[Show[px[n-{2,0}],px[n+{2,0}],PlotRange->{{-10,10},{-8,0}}],{{n,{0,0}},{-7,-4},{7,0},Locator}]

Manipulate[Graphics[{Point[{{0,0},n1,n2,{6,0}}],BezierCurve[{{0,0},n1,n2,{6,0}}],Dashing[{0.02}],Line[{{0,0},n1,n2,{6,0}}]},PlotRange->{{-1,7},{-5,5}}],{{n1,{2,2}},Locator},{{n2,{4,-2}},Locator}]

Ćwiczenia

Wyznaczanie pola powierzchni trójkąta

Przykład 1

pole1:=Manipulate[TableForm[{Graphics[{PointSize[0.02],Point[{c,{0,0},{6,0}}],Line[{c,{0,0},{6,0},c}],Text["A",{0,0},{1,1}],Text["B",{6,0},{-1,1}],Text["C",c,{0,-1}]},PlotRange->{{-1,7},{-1,7}}],Abs[Det[{{0,0}-c,{0,0}-{6,0}}]]}],{{c,{3,3},"Punkt C"},{0,0},{6,6}}]

pole1

Przykład 2

pole2:=Manipulate[TableForm[{Graphics[{PointSize[0.02],Point[{c,{0,0},{6,0}}],Line[{c,{0,0},{6,0},c}],Text["A (0,0)",{0,0},{0,1}],Text["B (6,0)",{6,0},{0,1}],Text[StringJoin["C (",ToString[c[[1]]],",",ToString[c[[2]]],")"],c,{0,-1}]},PlotRange->{{-1,7},{-1,7}}],StringJoin["Pole: ",ToString[Abs[Det[{{0,0}-c,{0,0}-{6,0}}]]]]}],{{c,{3,3},"Punkt C"},{0,0},{6,6}}]

pole2

Przykład 3

pole3:=Manipulate[TableForm[{Graphics[{PointSize[0.02],Point[{n1,{0,0},{6,0}}],Line[{n1,{0,0},{6,0},n1}],Text["A",{0,0},{1,1}],Text["B",{6,0},{-1,1}],Text["C",n1,{0,-1}]},PlotRange->{{-1,7},{-1,7}}],Abs[Det[{{0,0}-n1,{0,0}-{6,0}}]]}],{{n1,{3,3}},Locator}]

pole3

Wyznaczanie kąta między wektorami

Wyznaczanie okręgu opisanego na trójkącie

Wyznaczanie okręgu wpisanego w trójkąt

Obrazki

Import["nazwa"]
ImageData[obrazek]
Image[dane]
Export

Directory[]

SetDirectory["d:\\kks"]

p=Import["kotek.jpg"]

pp=ImageData[p];
pp[[1,1]]

Dimensions[pp]

p2=Import["kotek.jpg","Data"]/255//N;
p2[[1,1]]

Image[pp]

usuncolor[x_,c_]:=Module[{col},
If[c=="r",col=1,If[c=="g",col=2,If[c=="b",col=3,Return[HoldForm[usuncolor[x,c]]]]]];
Image[Map[Insert[#1,0,col]&,Map[Drop[#1,{col}]&,x,{2}],{2}]]]

usuncolor[pp,"r"]

neg[x_]:=Image[Map[Abs[1-#1]&,x,{2}]]

neg[pp]

przytnij[x_,{{x1_,y1_},{x2_,y2_}}]:=Module[{p,d=Dimensions[x]},
If[x1<1||x1>d[[2]]||x2<1||x2>d[[2]]||y1<1||y1>d[[1]]||y2<1||y2>d[[1]],Return[HoldForm[przytnij[x,{{x1,y1},{x2,y2}}]]]];
p=Take[x,{y1,y2}];
p=Transpose[Take[Transpose[p],{x1,x2}]];
Image[p]]

przytnij[pp,{{208,66},{480,542}}]

Image[pp]

jasnosc[x_,c_]:=Image[Map[#1*c&,x,{2}]]

jasnosc[pp,1.6]