•Tehtävä 1

In[1]:=

f[x_] := x (1 + 4/x^2)^(1/2)

In[2]:=

f[-1]

Out[2]=

-5^(1/2)

In[3]:=

f[0]

                                      1 Power :: infy :  Infinite expression  -  encountered.                                       0

∞ :: indet :  Indeterminate expression \!\(0\\ \*InterpretationBox[\"ComplexInfinity\", DirectedInfinity[]]\) encountered.

Out[3]=

Indeterminate

In[4]:=

f[1]

Out[4]=

5^(1/2)

In[5]:=

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

[Graphics:HTMLFiles/ratk5_11.gif]

Out[5]=

-Graphics -

Funktiolla ei ole raja-arvoa origossa. Funktio ei ole määritelty origossa eikä sitä voida siinä määritelläkään siten, että siitä tulisi jatkuva.

In[6]:=

Remove[f]

•Tehtävä 2

In[7]:=

f[x_, n_] = Expand[x^n]

Out[7]=

x^n

In[8]:=

g[x_, n_] := Expand[x^2]

In[9]:=

f[a + b, 5]

Out[9]=

(a + b)^5

In[10]:=

g[a + b, 5]

Out[10]=

a^2 + 2 a b + b^2

In[11]:=

? f

Global`f

f[x_, n_] = x^n

In[12]:=

? g

Global`g

g[x_, n_] := Expand[x^2]

Funktion f tapauksessa x^n pyritään kehittämään (Expand) heti. Tässä ei kuitenkaan onnistuta, koska lauseketta x^n ei voida yksinkertaisemmin kirjoittaa. Funktion g tapauksessa se kehitetään vasta funktiota käytettäessä (siis myöhemmin, delayed).

In[13]:=

Remove[f, g]

•Tehtävä 3

In[14]:=

f[x_] := e^(-x^2)

In[15]:=

Table[f[x], {x, 0, 5, 0.1}]

Out[15]=

{1, 0.9900498337491681`, 0.9607894391523232`, 0.9139311852712282`, 0.8521437889662113`, 0.7788 ... .54938188039196`*^-10, 9.859505575991446`*^-11, 3.737571327944243`*^-11, 1.3887943864964021`*^-11}

In[16]:=

f1[x_] = D[f[x], x]

Out[16]=

-2 e^(-x^2) x

In[17]:=

Plot[f1[x], {x, 0, 5}]

[Graphics:HTMLFiles/ratk5_32.gif]

Out[17]=

-Graphics -

In[18]:=

ff[x_] = Integrate[f[x], x]

Out[18]=

1/2 π^(1/2) Erf[x]

In[19]:=

Plot[ff[x], {x, 0, 5}, PlotRange -> All]

[Graphics:HTMLFiles/ratk5_37.gif]

Out[19]=

-Graphics -

In[20]:=

? ff

Global`ff

ff[x_] = 1/2 π^(1/2) Erf[x]

In[21]:=

Remove[f, f1, ff]

•Tehtävä 4

In[22]:=

f[x_ /; x >= 0 && x <= 1/2] := 4 x

In[23]:=

f[x_ /; x >= 1/2 && x <= 1 ] := -4 x + 4

In[24]:=

f[x_ /; x > 1] := 0

In[25]:=

f[x_ /; x < 0] := 0

In[26]:=

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

[Graphics:HTMLFiles/ratk5_47.gif]

Out[26]=

-Graphics -

In[27]:=

Remove[f]

•Tehtävä 5

In[28]:=

p[x_] := x^2 + x

In[29]:=

q[x_] := x^2 + 1

In[30]:=

yht = (x^2 - 2 x - 1) * y ''[x] - 2 * (x - 1) * y '[x] + 2 * y[x] == 0

Out[30]=

2 y[x] - 2 (-1 + x) y^'[x] + (-1 - 2 x + x^2) y^''[x] == 0

In[31]:=

yht /. y -> p // Simplify

Out[31]=

True

In[32]:=

yht /. y -> q // Simplify

Out[32]=

True

In[33]:=

Remove[p, q]

•Tehtävä 6

In[34]:=

f[n_ /; n > 10] := n - 5

In[35]:=

f[n_ /; 1 <= n && n <= 10] := f[f[n + 6]]

In[36]:=

Table[f[n], {n, 1, 100}]

Out[36]=

{6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, ... 1, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95}

In[37]:=

Remove[f]

•Tehtävä 7

In[38]:=

f = Function[x, FactorInteger[x][[1, 1]]]

Out[38]=

Function[x, FactorInteger[x] [[ 1, 1 ]]]

In[39]:=

Table[f[n], {n, 2, 20}]

Out[39]=

{2, 3, 2, 5, 2, 7, 2, 3, 2, 11, 2, 13, 2, 3, 2, 17, 2, 19, 2}

Tulostuu luvun pienin tekijä. Vrt. seuraavaan, ks. dokumentaatiota:

In[40]:=

Table[FactorInteger[n], {n, 2, 20}]

Out[40]=

{{{2, 1}}, {{3, 1}}, {{2, 2}}, {{5, 1}}, {{2, 1}, {3, 1}}, {{7, 1}}, {{2, 3}}, {{3, 2}}, {{2,  ... 1}, {7, 1}}, {{3, 1}, {5, 1}}, {{2, 4}}, {{17, 1}}, {{2, 1}, {3, 2}}, {{19, 1}}, {{2, 2}, {5, 1}}}

In[41]:=

Remove[f]

•Tehtävä 8

In[42]:=

f[x_] := Integrate[Abs[x - t], {t, 0, 1}]

In[43]:=

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

[Graphics:HTMLFiles/ratk5_73.gif]

Out[43]=

-Graphics -

In[44]:=

g[x_] := f '[x]

In[45]:=

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

                                       1 Power :: infy :  Infinite expression  ---  encountered.                                       0.`

                                       1 Power :: infy :  Infinite expression  ---  encountered.                                       0.`

                                       1 Power :: infy :  Infinite expression  ---  encountered.                                       0.`

General :: stop :  Further output of  Power :: \" infy \"  will be suppressed during this calculation.

Plot :: plnr :  g[x]  is not a machine-size real number at  x  =  -1.9999997916666667` .

Plot :: plnr :  g[x]  is not a machine-size real number at  x  =  -1.7971650421354213` .

Plot :: plnr :  g[x]  is not a machine-size real number at  x  =  -1.5759560007031317` .

General :: stop :  Further output of  Plot :: \" plnr \"  will be suppressed during this calculation.

[Graphics:HTMLFiles/ratk5_85.gif]

Out[45]=

-Graphics -

Ei siis onnistu.

In[46]:=

? f

Global`f

f[x_] := ∫ _ 0^1 Abs[x - t] d t

In[47]:=

? g

Global`g

g[x_] := f^'[x]

In[48]:=

Remove[f, g]

Toisin:

In[49]:=

f[x_ /; x >= 1] := Integrate[x - t, {t, 0, 1}]

In[50]:=

f[x_ /; x <= 0] := Integrate[t - x, {t, 0, 1}]

In[51]:=

f[x_ /; 0 < x && x < 1] := Integrate[x - t, {t, 0, x}] + Integrate[t - x, {t, x, 1}]

In[52]:=

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

[Graphics:HTMLFiles/ratk5_96.gif]

Out[52]=

-Graphics -

In[53]:=

g[x_] := f '[x]

In[54]:=

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

[Graphics:HTMLFiles/ratk5_100.gif]

Out[54]=

-Graphics -

In[55]:=

Remove[f, g]

•Tehtävä 9

In[56]:=

f[x_] := Sin[x]/x

In[57]:=

f[π/2]

Out[57]=

2/π

In[58]:=

f[1]

Out[58]=

Sin[1]

In[59]:=

f[1.]

Out[59]=

0.8414709848078965`

In[60]:=

f[0]

                                      1 Power :: infy :  Infinite expression  -  encountered.                                       0

Out[60]=

Indeterminate

In[61]:=

f[0] = 1

Out[61]=

1

In[62]:=

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

[Graphics:HTMLFiles/ratk5_116.gif]

Out[62]=

-Graphics -

In[63]:=

f '[x]

Out[63]=

Cos[x]/x - Sin[x]/x^2

In[64]:=

f '[0]

                                      1 Power :: infy :  Infinite expression  --  encountered.                                        2                                       0

                                      1 Power :: infy :  Infinite expression  -  encountered.                                       0

Out[64]=

Indeterminate

Mutta kuitenkin on f ' (0) = 0.

In[65]:=

? f

Global`f

f[0] = 1
f[x_] := Sin[x]/x

In[66]:=

Remove[f]

•Tehtävä 10

In[67]:=

y[x_] := C _ 1 * Sin[x] + C _ 2 * Cos[x] + Cos[x] * Log[Tan[π/4 - x/2]]

In[68]:=

y[x] + y ''[x] == Tan[x] // FullSimplify

Out[68]=

True

In[69]:=

FullSimplify[ComplexExpand[Log[x]], x < 0]

Out[69]=

i π + Log[-x]


Converted by Mathematica  (August 21, 2003)