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
]
Albo tak:
Plot
[
f
[
x
]
,
{
x
,
-
3
,
3
}
]
![przyklad3__1](http://kmim.wm.pwr.edu.pl/myszka/wp-content/uploads/sites/2/2015/09/przyklad3__1.gif)
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](http://kmim.wm.pwr.edu.pl/myszka/wp-content/uploads/sites/2/2015/09/przyklad3__2.gif)
Nie jest to chyba to czego oczekiwaliśmy...
Plot
[
Evaluate
[
∫
f
[
x
]
ⅆ
x
]
,
{
x
,
-
3
,
3
}
]
![przyklad3__3](http://kmim.wm.pwr.edu.pl/myszka/wp-content/uploads/sites/2/2015/09/przyklad3__3.gif)
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](http://kmim.wm.pwr.edu.pl/myszka/wp-content/uploads/sites/2/2015/09/przyklad3__4.gif)
To moze tak jak poprzednio:
h
[
x_
]
:=
Evaluate
[
Integrate
[
f
[
x
]
,
x
]
]
;
Plot
[
h
[
x
]
,
{
x
,
-
3
,
3
}
]
![przyklad3__5](http://kmim.wm.pwr.edu.pl/myszka/wp-content/uploads/sites/2/2015/09/przyklad3__5.gif)
No i zadzialalo...
Clear
[
f
]
?
f
Globalf
?
h
Globalh
h
[
x_
]
:=
x
+
x
2
+
x
3
3
|
|
?
g
Globalg
Clear
[
g
,
h
]
?
g
Globalg
?
h
Global`h
Polecenie ? pozwala na sprawdzenie jak zdefiniowany jest dany symbol. Polecenie Clean kasuje wszystkie definicje...