Uporaba programskega okolja Mathematica za izračun vrednosti funkcij ter risanje grafov funkcij

Definicija funkcije

Definirajmo funkcijo f(x) = a (e^bx)cos(cx), kjer so vrednosti parametrov a = 2, b = –0,5 ter c = 1,5.

a=2;
b=-0.5;
c=1.5;
f[x_]:=a (E^(b x)) Cos[c x]

Kolikšna je vrednost funkcije, ko ima njena spremenljivka vrednost (Subscript[x, 0]) = –1,5?

x0=-1.5;
f[x0]

Določimo seznam vrednosti funkcije, ko se spremenljivka x spreminja od vrednosti –5 do 5 s korakom po 0,5.

xSeznam=Table[x,{x,-5,5,0.5}];
fSeznam=f[xSeznam]

Koliko elementov ima ta seznam?

nTock=Part[Dimensions[xSeznam],1]

Diagram poteka funkcije

Z diagramom prikazimo izračunane vrednosti funkcije.

TockeGrafa=Table[{xSeznam[[k]],fSeznam[[k]]},{k,1,nTock}]
graf1a=ListPlot[TockeGrafa]

Opremimo ta diagram z oznakami osi (npr. naj spremenljivka x dimenzijsko ustreza dolžini, funkcija f pa gostoti magnetnega pretoka), nekoliko zmanjšajmo debelino tock, narišimo okvir diagrama, dodajmo naslov diagrama, ...

graf1b=ListPlot[TockeGrafa,Frame->True,BaseStyle->{FontFamily->"Times",FontSize->14},FrameLabel->{"x / m","f(x) / T","",""},PlotStyle->PointSize[0.02],PlotLabel->"Nekaj vrednosti funkcije f(x)"]

Narišimo (zvezen) graf odvisnosti funkcije od njene spremenljivke v mejah –5 ≤ x ≤ 5.

graf1c=Plot[f[x],{x,-5,5},Frame->True,BaseStyle->{FontFamily->"Times",FontSize->14},FrameLabel->{"x / m","f(x) / T","",""},PlotLabel->"Graf funkcije f(x)"]

Opaziti je, da je ta graf na levi odrezan (tako da v levo ne seze do meje x = –5). Popravimo to in obenem dodajmo se pomožne črte za lazje odčitavanje iz diagrama.

graf1d=Plot[f[x],{x,-5,5},Frame->True,BaseStyle->{FontFamily->"Times",FontSize->14},FrameLabel->{"x / m","f(x) / T","",""},GridLines->Automatic,PlotRange->{{-5,5},All},PlotLabel->"Graf funkcije f(x)"]

V isti diagram narisimo v prejšnji tabeli izračunane vrednosti funkcije ter zvezen graf funkcije.

Show[{graf1b,graf1d},PlotLabel->"Nekaj vrednosti ter graf funkcije f(x)"]

Še enkrat dorišimo pomožne črte za lažje odčitavanje.

Show[{graf1b,graf1d},GridLines->Automatic,PlotLabel->"Nekaj vrednosti ter graf funkcije f(x)"]

Še ena funkcija

Definirajmo novo fukcijo (Subscript[f, 2])(x), tako da prejšnjo f(x) skaliramo z vrednostjo –0,5.

f2[x_]:=-0.5 f[x]

Prikaz dveh funkcij v istem diagramu

Narišimo grafa funkcij f(x) in (Subscript[f, 2])(x) v istem diagramu.

graf2a=Plot[{f[x],f2[x]},{x,-5,5},Frame->True,BaseStyle->{FontFamily->"Times",FontSize->14},FrameLabel->{"x / m","f(x) / T, (Subscript[f, 2])(x) / T","",""},GridLines->Automatic,PlotRange->{{-5,5},All},PlotLabel->"Funkciji f(x) in (Subscript[f, 2])(x)"]

Opremimo ta diagram z legendo.

graf2b=Plot[{f[x],f2[x]},{x,-5,5},Frame->True,BaseStyle->{FontFamily->"Times",FontSize->14},FrameLabel->{"x / m","","",""},GridLines->Automatic,PlotRange->{{-5,5},All},PlotLegends->{"f(x) / T", "(Subscript[f, 2])(x) / T"},PlotLabel->"Funkciji f(x) in (Subscript[f, 2])(x)"]

Še tretja funkcija

Definirajmo še tretjo funkcijo (Subscript[f, 3])(x), tako da prvotno f(x) premaknemo v desno (vzdolž abscise) za vrednost Δx = 0,7.

Δx=0.7;
f3[x_]:=f[x-Δx]

Narišimo grafe treh funkcij f(x), (Subscript[f, 2])(x) in (Subscript[f, 3])(x) v istem diagramu.

graf3a=Plot[{f[x],f2[x],f3[x]},{x,-5,5},Frame->True,BaseStyle->{FontFamily->"Times",FontSize->14},FrameLabel->{"x / m","","",""},GridLines->Automatic,PlotRange->{{-5,5},All},PlotLegends->{"f(x) / T", "(Subscript[f, 2])(x) / T", "(Subscript[f, 3])(x) / T"},PlotLabel->"Funkcije f(x), (Subscript[f, 2])(x) in (Subscript[f, 3])(x)"]

Povečajmo ta diagram.

graf3b=Plot[{f[x],f2[x],f3[x]},{x,-5,5},Frame->True,BaseStyle->{FontFamily->"Times",FontSize->14},FrameLabel->{"x / m","","",""},GridLines->Automatic,PlotRange->{{-5,5},All},PlotLegends->{"f(x) / T", "(Subscript[f, 2])(x) / T", "(Subscript[f, 3])(x) / T"},PlotLabel->"Funkcije f(x), (Subscript[f, 2])(x) in (Subscript[f, 3])(x)",ImageSize->500]

(Legended[, (LineLegend["\!\(\*\nStyleBox[\"f\", \"Text\",\nFontFamily->\"Times New Roman\",\nFontSize->14,\nFontWeight->\"Plain\",\nFontSlant->\"Italic\",\nFontVariations->{\"CompatibilityType\"->0}]\)\!\(\*\nStyleBox[\"(\", \"Text\",\nFontFamily->\"Times New Roman\",\nFontSize->14,\nFontWeight->\"Plain\",\nFontSlant->\"Italic\",\nFontVariations->{\"CompatibilityType\"->0}]\)\!\(\*\nStyleBox[\"x\", \"Text\",\nFontFamily->\"Times New Roman\",\nFontSize->14,\nFontWeight->\"Plain\",\nFontSlant->\"Italic\",\nFontVariations->{\"CompatibilityType\"->0}]\)\!\(\*\nStyleBox[\")\", \"Text\",\nFontFamily->\"Times New Roman\",\nFontSize->14,\nFontWeight->\"Plain\",\nFontSlant->\"Italic\",\nFontVariations->{\"CompatibilityType\"->0}]\)\!\(\*\nStyleBox[\" \", \"Text\",\nFontFamily->\"Times New Roman\",\nFontSize->14,\nFontWeight->\"Plain\",\nFontSlant->\"Italic\",\nFontVariations->{\"CompatibilityType\"->0}]\)\!\(\*\nStyleBox[\"/\", \"Text\",\nFontFamily->\"Times New Roman\",\nFontSize->14,\nFontWeight->\"Plain\",\nFontSlant->\"Italic\",\nFontVariations->{\"CompatibilityType\"->0}]\)\!\(\*\nStyleBox[\" \", \"Text\",\nFontFamily->\"Times New Roman\",\nFontSize->14,\nFontWeight->\"Plain\",\nFontSlant->\"Italic\",\nFontVariations->{\"CompatibilityType\"->0}]\)\!\(\*\nStyleBox[\"T\", \"Text\",\nFontFamily->\"Times New Roman\",\nFontSize->14,\nFontWeight->\"Plain\",\nFontVariations->{\"CompatibilityType\"->0}]\)", "\!\(\*\nStyleBox[SubscriptBox[\n  StyleBox[\"f\", \"Text\",\nFontFamily->\"Times New Roman\",\nFontSize->14,\nFontWeight->\"Plain\",\nFontSlant->\"Italic\",\nFontVariations->{\"CompatibilityType\"->0}], \n  StyleBox[\"2\",\nFontSlant->\"Plain\"]], \"Text\",\nFontFamily->\"Times New Roman\",\nFontSize->14,\nFontWeight->\"Plain\",\nFontSlant->\"Italic\",\nFontVariations->{\"CompatibilityType\"->0}]\)\!\(\*\nStyleBox[\"(\", \"Text\",\nFontFamily->\"Times New Roman\",\nFontSize->14,\nFontWeight->\"Plain\",\nFontSlant->\"Italic\",\nFontVariations->{\"CompatibilityType\"->0}]\)\!\(\*\nStyleBox[\"x\", \"Text\",\nFontFamily->\"Times New Roman\",\nFontSize->14,\nFontWeight->\"Plain\",\nFontSlant->\"Italic\",\nFontVariations->{\"CompatibilityType\"->0}]\)\!\(\*\nStyleBox[\")\", \"Text\",\nFontFamily->\"Times New Roman\",\nFontSize->14,\nFontWeight->\"Plain\",\nFontSlant->\"Italic\",\nFontVariations->{\"CompatibilityType\"->0}]\)\!\(\*\nStyleBox[\" \", \"Text\",\nFontFamily->\"Times New Roman\",\nFontSize->14,\nFontWeight->\"Plain\",\nFontSlant->\"Italic\",\nFontVariations->{\"CompatibilityType\"->0}]\)\!\(\*\nStyleBox[\"/\", \"Text\",\nFontFamily->\"Times New Roman\",\nFontSize->14,\nFontWeight->\"Plain\",\nFontSlant->\"Italic\",\nFontVariations->{\"CompatibilityType\"->0}]\)\!\(\*\nStyleBox[\" \", \"Text\",\nFontFamily->\"Times New Roman\",\nFontSize->14,\nFontWeight->\"Plain\",\nFontSlant->\"Italic\",\nFontVariations->{\"CompatibilityType\"->0}]\)\!\(\*\nStyleBox[\"T\", \"Text\",\nFontFamily->\"Times New Roman\",\nFontSize->14,\nFontWeight->\"Plain\",\nFontVariations->{\"CompatibilityType\"->0}]\)", "\!\(\*\nStyleBox[SubscriptBox[\n  StyleBox[\"f\", \"Text\",\nFontFamily->\"Times New Roman\",\nFontSize->14,\nFontWeight->\"Plain\",\nFontSlant->\"Italic\",\nFontVariations->{\"CompatibilityType\"->0}], \n  StyleBox[\"3\",\nFontSlant->\"Plain\"]], \"Text\",\nFontFamily->\"Times New Roman\",\nFontSize->14,\nFontWeight->\"Plain\",\nFontSlant->\"Italic\",\nFontVariations->{\"CompatibilityType\"->0}]\)\!\(\*\nStyleBox[\"(\", \"Text\",\nFontFamily->\"Times New Roman\",\nFontSize->14,\nFontWeight->\"Plain\",\nFontSlant->\"Italic\",\nFontVariations->{\"CompatibilityType\"->0}]\)\!\(\*\nStyleBox[\"x\", \"Text\",\nFontFamily->\"Times New Roman\",\nFontSize->14,\nFontWeight->\"Plain\",\nFontSlant->\"Italic\",\nFontVariations->{\"CompatibilityType\"->0}]\)\!\(\*\nStyleBox[\")\", \"Text\",\nFontFamily->\"Times New Roman\",\nFontSize->14,\nFontWeight->\"Plain\",\nFontSlant->\"Italic\",\nFontVariations->{\"CompatibilityType\"->0}]\)\!\(\*\nStyleBox[\" \", \"Text\",\nFontFamily->\"Times New Roman\",\nFontSize->14,\nFontWeight->\"Plain\",\nFontSlant->\"Italic\",\nFontVariations->{\"CompatibilityType\"->0}]\)\!\(\*\nStyleBox[\"/\", \"Text\",\nFontFamily->\"Times New Roman\",\nFontSize->14,\nFontWeight->\"Plain\",\nFontSlant->\"Italic\",\nFontVariations->{\"CompatibilityType\"->0}]\)\!\(\*\nStyleBox[\" \", \"Text\",\nFontFamily->\"Times New Roman\",\nFontSize->14,\nFontWeight->\"Plain\",\nFontSlant->\"Italic\",\nFontVariations->{\"CompatibilityType\"->0}]\)\!\(\*\nStyleBox[\"T\", \"Text\",\nFontFamily->\"Times New Roman\",\nFontSize->14,\nFontWeight->\"Plain\",\nFontVariations->{\"CompatibilityType\"->0}]\)"])])