Lekcja 3


Funkcje

Mathematica pozwala na definiowanie funkcji uzytkownikja. Przykladowa definicja wyglada tak:

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

Z funkcji mozemy korzystac w dosyc naturalny sposob; na przyklad tak:

f [ 10 ]

121

Albo tak:

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

Rowniez takie wykorzystanie jest dopuszczalne

Integrate [ f [ x ] , x ]

x + x 2 + x 3 3

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

Integrate :: ilim : Invalid integration variable or limit(s) in ⁠ - 2.9998774285714287 ⁠. "Invalid integration variable or limit(s) in \[NoBreak]\\!\\(-2.9998774285714287\\)\[NoBreak]. \\!\\(\\*ButtonBox[\\\"\[RightSkeleton]\\\", ButtonStyle->\\\"Link\\\", ButtonFrame->None, ButtonData:>\\\"paclet:ref/message/Integrate/ilim\\\", ButtonNote -> \\\"Integrate::ilim\\\"]\\)"

Integrate :: ilim : Invalid integration variable or limit(s) in ⁠ - 2.877428448979592 ⁠. "Invalid integration variable or limit(s) in \[NoBreak]\\!\\(-2.877428448979592\\)\[NoBreak]. \\!\\(\\*ButtonBox[\\\"\[RightSkeleton]\\\", ButtonStyle->\\\"Link\\\", ButtonFrame->None, ButtonData:>\\\"paclet:ref/message/Integrate/ilim\\\", ButtonNote -> \\\"Integrate::ilim\\\"]\\)"

Integrate :: ilim : Invalid integration variable or limit(s) in ⁠ - 2.754979469387755 ⁠. "Invalid integration variable or limit(s) in \[NoBreak]\\!\\(-2.754979469387755\\)\[NoBreak]. \\!\\(\\*ButtonBox[\\\"\[RightSkeleton]\\\", ButtonStyle->\\\"Link\\\", ButtonFrame->None, ButtonData:>\\\"paclet:ref/message/Integrate/ilim\\\", ButtonNote -> \\\"Integrate::ilim\\\"]\\)"

General :: stop : Further output of ⁠ Integrate :: ilim ⁠ will be suppressed during this calculation. "Further output of \[NoBreak]\\!\\(\\*StyleBox[\\(Integrate :: ilim\\), \\\"MessageName\\\"]\\)\[NoBreak] will be suppressed during this calculation. \\!\\(\\*ButtonBox[\\\"\[RightSkeleton]\\\", ButtonStyle->\\\"Link\\\", ButtonFrame->None, ButtonData:>\\\"paclet:ref/message/General/stop\\\", ButtonNote -> \\\"General::stop\\\"]\\)" przyklad3__2

Nie jest to chyba to czego oczekiwaliśmy...

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

Teraz lepiej! Ale czemu tak jest? Zdefiniujmy nowa funkcje:

g [ x_ ] := Integrate [ f [ x ] , x ]

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

Integrate :: ilim : Invalid integration variable or limit(s) in ⁠ - 2.9998774285714287 ⁠. "Invalid integration variable or limit(s) in \[NoBreak]\\!\\(-2.9998774285714287\\)\[NoBreak]. \\!\\(\\*ButtonBox[\\\"\[RightSkeleton]\\\", ButtonStyle->\\\"Link\\\", ButtonFrame->None, ButtonData:>\\\"paclet:ref/message/Integrate/ilim\\\", ButtonNote -> \\\"Integrate::ilim\\\"]\\)"

Integrate :: ilim : Invalid integration variable or limit(s) in ⁠ - 2.877428448979592 ⁠. "Invalid integration variable or limit(s) in \[NoBreak]\\!\\(-2.877428448979592\\)\[NoBreak]. \\!\\(\\*ButtonBox[\\\"\[RightSkeleton]\\\", ButtonStyle->\\\"Link\\\", ButtonFrame->None, ButtonData:>\\\"paclet:ref/message/Integrate/ilim\\\", ButtonNote -> \\\"Integrate::ilim\\\"]\\)"

Integrate :: ilim : Invalid integration variable or limit(s) in ⁠ - 2.754979469387755 ⁠. "Invalid integration variable or limit(s) in \[NoBreak]\\!\\(-2.754979469387755\\)\[NoBreak]. \\!\\(\\*ButtonBox[\\\"\[RightSkeleton]\\\", ButtonStyle->\\\"Link\\\", ButtonFrame->None, ButtonData:>\\\"paclet:ref/message/Integrate/ilim\\\", ButtonNote -> \\\"Integrate::ilim\\\"]\\)"

General :: stop : Further output of ⁠ Integrate :: ilim ⁠ will be suppressed during this calculation. "Further output of \[NoBreak]\\!\\(\\*StyleBox[\\(Integrate :: ilim\\), \\\"MessageName\\\"]\\)\[NoBreak] will be suppressed during this calculation. \\!\\(\\*ButtonBox[\\\"\[RightSkeleton]\\\", ButtonStyle->\\\"Link\\\", ButtonFrame->None, ButtonData:>\\\"paclet:ref/message/General/stop\\\", ButtonNote -> \\\"General::stop\\\"]\\)" przyklad3__4

To moze tak jak poprzednio:

h [ x_ ] := Evaluate [ Integrate [ f [ x ] , x ] ] ;

Plot [ h [ x ] , { x , - 3 , 3 } ] przyklad3__5

No i zadzialalo...

Clear [ f ]

? f

Globalf

? h

Globalh

h [ x_ ] := x + x 2 + x 3 3  

? g

Globalg

g[x_]:=∫f[x]dx

Clear [ g , h ]

? g

Globalg

? h

Global`h

Polecenie  ? pozwala na sprawdzenie jak zdefiniowany jest dany symbol. Polecenie Clean kasuje wszystkie definicje...