Valmiit funktiot

Kokeile mitä antaa

In[1]:=

Abs[-3.4 + 2 I]

Out[1]=

3.94462

Saatiin kompleksivektorin pituus .

In[2]:=

Sqrt[-4]

Out[2]=

2 

In[3]:=

Log[10, 100]

Out[3]=

2

100 : n logaritmi kannassa 10.

In[4]:=

Log[E]

Out[4]=

1

In[5]:=

Exp[1]

Out[5]=



In[6]:=

4 !

Out[6]=

24

eli 4 * 3 * 2 * 1

In[7]:=

4 !!

Out[7]=

8

eli 4 * 2

In[8]:=

Max[1, 5, 2, 7, 4]

Out[8]=

7

In[9]:=

Min[6, 8, 2, 5, 1, Pi]

Out[9]=

1

In[10]:=

Round[1.6]

Out[10]=

2

In[11]:=

Round[1.4]

Out[11]=

1

In[12]:=

Floor[1.6]

Out[12]=

1

In[13]:=

Ceiling[1.4]

Out[13]=

2

In[14]:=

Sign[4]

Out[14]=

1

In[15]:=

Sign[-4]

Out[15]=

-1

In[16]:=

Re[1 + 3I]

Out[16]=

1

In[17]:=

Im[1 + 3I]

Out[17]=

3

In[18]:=

Conjugate[1 + 3I]

Out[18]=

1 - 3 

In[19]:=

Arg[1 + 3I]

Out[19]=

ArcTan[3]

In[20]:=

SeedRandom[]

Alustettiin satunnaislukugeneraattori .

In[21]:=

Random[]

Random[]

Random[]

Out[21]=

0.422095

Out[22]=

0.59078

Out[23]=

0.129006

In[24]:=

Plot[LegendreP[1, x], {x, -2, 2}]

Plot[LegendreP[2, x], {x, -2, 2}]

Plot[LegendreP[3, x], {x, -2, 2}]

Plot[LegendreP[4, x], {x, -2, 2}]

[Graphics:HTMLFiles/3_ratkaisu_55.gif]

Out[24]=

⁃Graphics⁃

[Graphics:HTMLFiles/3_ratkaisu_57.gif]

Out[25]=

⁃Graphics⁃

[Graphics:HTMLFiles/3_ratkaisu_59.gif]

Out[26]=

⁃Graphics⁃

[Graphics:HTMLFiles/3_ratkaisu_61.gif]

Out[27]=

⁃Graphics⁃

Omat funktiot

Määrittele funktio f(x)=x^2+2x. Laske funktion arvo kun x=3.

In[28]:=

f[x_] := x^2 + 2x

f[3]

Out[29]=

15

Etsi edellä määritellyn funktion nollakohdat.

In[30]:=

Solve[f[x] 0, x]

Out[30]=

{{x -2}, {x0}}

Määrittele f(x)=x^4-3x+e^(-x)  Mathematica'ssa ja piirrä sen kuvaaja välillä [-3,3].

In[33]:=

f[x_] := x^4 - 3x + Exp[-x]

Plot[f[x], {x, -3, 3}]

[Graphics:HTMLFiles/3_ratkaisu_72.gif]

Out[34]=

⁃Graphics⁃

Määrittele g(x)=x^2-3x ja ratkaise yhtälö g(x)=4.

In[35]:=

g[x_] := x^2 - 3x

Solve[g[x] 4, x]

Out[36]=

{{x -1}, {x4}}

Määrittele funktio z(x,y)=sin(x y) cos(x y) ja piirrä se 3D-kuvana ja tasa-arvokäyrinä.

In[37]:=

z[x_, y_] := Sin[x y] Cos[x y]

Plot3D[z[x, y], {x, -1, 1}, {y, -1, 1}]

ContourPlot[z[x, y], {x, -1, 1}, {y, -1, 1}]

[Graphics:HTMLFiles/3_ratkaisu_81.gif]

Out[38]=

⁃SurfaceGraphics⁃

[Graphics:HTMLFiles/3_ratkaisu_83.gif]

Out[39]=

⁃ContourGraphics⁃

Yhtälöiden ratkaiseminen

Ratkaise yleinen kolmannen asteen yhtälö
a x^3+b x^2+c x+d==0 käyttämällä reduce-komentoa.

In[40]:=

Reduce[a x^3 + b x^2 + c x + d0, x]

Out[40]=

(a≠0&& (xRoot[d + c #1 + b #1^2 + a #1^3&, 1] || xRoot[d + ... &x -d/c) || (d0&&c0&&b0&&a0)

Etsi yhtälön cos(x)=x ratkaisu.

In[41]:=

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

[Graphics:HTMLFiles/3_ratkaisu_88.gif]

Out[41]=

⁃Graphics⁃

Ratkaisu näyttäisi sijoittuvan 1 : n lähistölle .

In[42]:=

FindRoot[Cos[x] x, {x, 1}]

Out[42]=

{x0.739085}

Ratkaisu Newtonin menetelmällä .

In[43]:=

FindRoot[Cos[x] x, {x, 0.5, 1}]

Out[43]=

{x0.739085}

Ratkaisu sekanttimenetelmällä .

Ratkaise seuraava yhtälöryhmä
    3x+y=2
    y+2z=2
    x+z=1
symbolisesti ja numerisesti

In[44]:=

eqns = {3x + y2, y + 2z2, x + z1}

Solve[eqns, {x, y, z}]

NSolve[eqns, {x, y, z}]

Out[44]=

{3 x + y2, y + 2 z2, x + z1}

Out[45]=

{{x2/5, y4/5, z3/5}}

Out[46]=

{{x0.4, y0.8, z0.6}}

Etsi yhtälöille
    x^2+3 x-1= 0
    3 x^2+5 x+1 = 0
symboliset ja numeeriset ratkaisut.

In[47]:=

eqns = {x^2 + 3x - 10, 3x^2 + 5x + 10}

Solve[eqns, {x}]

NSolve[eqns, {x}]

Out[47]=

{-1 + 3 x + x^20, 1 + 5 x + 3 x^20}

Out[48]=

{}

Out[49]=

{}

Ratkaisu oli tyhjä joukko (ei ratkaisuja) . Tilannetta voi havainnollistaa piirtämällä kuvaajat :

In[52]:=

Plot[{x^2 + 3x - 1, 3x^2 + 5x + 1}, {x, -5, 3}]

[Graphics:HTMLFiles/3_ratkaisu_111.gif]

Out[52]=

⁃Graphics⁃

Kuvaajat leikkaavat kyllä molemmat x - akselin parissakin kohtaa, mutta eivät samoilla x : n arvoilla .

Ratkaise yhtälöryhmä
    x^2+5 x-4 y=0
    2 x-y=3
symbolisesti ja numeerisesti.

In[56]:=

eqns = {x^2 + 5x - 4y0, 2x - y3}

Solve[eqns, {x, y}]

NSolve[eqns, {x, y}]

Out[56]=

{5 x + x^2 - 4 y0, 2 x - y3}

Out[57]=

{{y - 39^(1/2), x1/2 (3 -  39^(1/2))}, {y 39^(1/2), x1/2 (3 +  39^(1/2))}}

Out[58]=

{{x1.5 - 3.1225 , y0. - 6.245 }, {x1.5 + 3.1225 , y0. + 6.245 }}

Ratkaise lineaarinen yhtälöryhmä

    3 x_1 + x_2 + 4 x_3 = 2

    5 x_1 + x_2 + 2 x_3 = 3

     x_1 - 3 x_2 - 2 x_3 = 1

In[59]:=

m = {{3, 1, 4}, {5, 1, 2}, {1, -3, -2}}

b = {2, 3, 1}

LinearSolve[m, b]

Out[59]=

{{3, 1, 4}, {5, 1, 2}, {1, -3, -2}}

Out[60]=

{2, 3, 1}

Out[61]=

{3/5, -1/5, 1/10}


Created by Mathematica  (February 1, 2005) Valid XHTML 1.1!