RepozytoriumzprojektemPython/stopy/Ćwiczenia_7.ipynb

429 lines
12 KiB
Plaintext
Raw Normal View History

2024-11-27 08:39:46 +01:00
{
"cells": [
{
"cell_type": "markdown",
"id": "4cc6c96f",
"metadata": {},
"source": [
"# Ćwiczenia 7"
]
},
{
"cell_type": "markdown",
"id": "1276423e",
"metadata": {},
"source": [
"***TEMAT:*** funkcje wielu zmiennych - gradient, płaszczyzna styczna, reguła łańcucha, pochodne cząstkowe wyższych rzędów"
]
},
{
"cell_type": "markdown",
"id": "adcbd788",
"metadata": {},
"source": [
"## Gradient, płaszczyzna styczna i reguła łańcucha"
]
},
{
"cell_type": "markdown",
"id": "da9cb4e5-acae-4d5b-85a9-f86d1ec751f8",
"metadata": {},
"source": [
"### Gradient"
]
},
{
"cell_type": "markdown",
"id": "516f7bfe-4937-4093-9d5a-69b53ba527df",
"metadata": {},
"source": [
"Gradientem funkcji $f$ w punkcie $(x_1,x_2,...,x_n)$, w którym istnieją wszystkie pochodne cząstkowe funkcji $f$, nazywamy wektor\n",
"\n",
"$$\n",
"\\nabla f(x_1,x_2,...,x_n) = \\left(\\frac{\\partial f}{\\partial x_1}(x_1,x_2,...,x_n), ..., \\frac{\\partial f}{\\partial x_n}(x_1,x_2,...,x_n)\\right).\n",
"$$"
]
},
{
"cell_type": "markdown",
"id": "aefc1880-8ee7-4884-a7d9-833f27ad016b",
"metadata": {},
"source": [
"#### Zadanie 1\n",
"\n",
"Wyznacz gradient następujących funkcji:\n",
"1. $f(x,y)=x^2+3xy$\n",
"2. $g(x,y,z)=ze^{xy}$\n",
"\n",
"Jaka jest interpretacja tego wektora?"
]
},
{
"cell_type": "markdown",
"id": "d24ad98e-0737-437f-9e08-8e2a5e8a1d26",
"metadata": {},
"source": [
"##### Rozwiązanie:"
]
},
{
"cell_type": "markdown",
"id": "62192ddd-704b-4754-8f86-3c3ffda39ad0",
"metadata": {},
"source": [
"Mamy\n",
"$$\n",
"\\nabla f(x,y)=\\left(2x+3y,3x\\right)\n",
"$$\n",
"oraz\n",
"$$\n",
"\\nabla g(x,y,z)=\\left(yze^{xy},xze^{xy},e^{xy}\\right).\n",
"$$\n"
]
},
{
"cell_type": "markdown",
"id": "33d09d4f-c4af-40e3-bcbb-4f916dd5f611",
"metadata": {},
"source": [
"___Interpretacja geometryczna gradientu___\n",
"\n",
">1. Gradient funkcji w punkcie wskazuje __kierunek najszybszego wzrostu funkcji w tym punkcie.__\n",
">\n",
">2. Gradient funkcji w punkcie jest __prostopadły do poziomicy funkcji__ przechodzącej przez ten punkt."
]
},
{
"cell_type": "markdown",
"id": "98578fbf-a1df-4d3b-b8d8-dc4d0009c722",
"metadata": {},
"source": [
"### Płaszczyzna styczna do powierzchni"
]
},
{
"cell_type": "markdown",
"id": "dd8b2261-a2a4-4394-bdaf-e07257516e62",
"metadata": {},
"source": [
"Jeśli funkcja $f(x,y)$ posiada w punkcie $(x_0,y_0)$ pochodne cząstkowe, to płaszczyznę zadaną równaniem\n",
"$$ \n",
"\\frac{\\partial f}{\\partial x} (x_0, y_0)(x-x_0) + \\frac{\\partial f}{\\partial y}(x_0, y_0)(y-y_0)-(z-z_0)= 0 .\n",
"$$\n",
"nazywamy płaszczyzną styczną do wykresu funkcji $f$ w punkcie $(x_0, y_0,f(x_0, y_0))$.\n"
]
},
{
"cell_type": "markdown",
"id": "06be3815-19e7-442e-b873-c0b190ebb60e",
"metadata": {},
"source": [
"#### Zadanie 2\n",
"\n",
"Napisz wzór płaszczyzny stycznej do wykresu funkcji $f(x,y)=x^2+y^2$."
]
},
{
"cell_type": "markdown",
"id": "537b3a74-e291-4e66-97be-323f7ff344b2",
"metadata": {},
"source": [
"##### Rozwiązanie:"
]
},
{
"cell_type": "markdown",
"id": "f58c17e2-0d2b-4c07-9fa8-5165000dd0ed",
"metadata": {},
"source": [
"Płaszczyzna styczna do wykresu naszej funkcji w punkcie $(x_0,y_0,x_0^2+y_0^2)$ ma równanie\n",
"$$\n",
"2x_0(x-x_0)+2y_0(y-y_0)-(z-x_0^2-y_0^2)=0\n",
"$$\n",
"Dla $(x_0,y_0)=(0,0)$ daje to równanie\n",
"$$\n",
"z=0\n",
"$$\n",
"a dla $(x_0,y_0)=(1,1)$ daje to równanie\n",
"$$\n",
"2x+2y-z-2=0.\n",
"$$\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "a9133cb6-005c-4701-a26a-b9d6bf47c0ca",
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"\n",
" <iframe\n",
" width=\"800\"\n",
" height=\"600\"\n",
" src=\"https://www.geogebra.org/calculator/ahx8sscp?style=border%3A+1px+solid+black\"\n",
" frameborder=\"0\"\n",
" allowfullscreen\n",
" \n",
" ></iframe>\n",
" "
],
"text/plain": [
"<IPython.lib.display.IFrame at 0x7f6868351d90>"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import IPython.display as display\n",
"from IPython.display import IFrame\n",
"IFrame('https://www.geogebra.org/calculator/ahx8sscp', width=800, height=600, style=\"border: 1px solid black\")"
]
},
{
"cell_type": "markdown",
"id": "cc16702b-af19-47cf-bda1-57473eb84a1e",
"metadata": {},
"source": [
"### Reguła łańcucha "
]
},
{
"cell_type": "markdown",
"id": "e2eb1c13-3ce9-46e3-9cb7-21cf7d74c8d2",
"metadata": {},
"source": [
"Niech $f,g,h\\colon \\mathbb{R}^2 \\to \\mathbb{R}$ będą funkcjami dwóch zmiennych rzeczywistych o wartościach rzeczywistych. Jeżeli:\n",
"\n",
"1. $g,h$ mają w punkcie $(x_0,y_0)$ pochodne cząstkowe, oraz\n",
"\n",
"2. $f(u,v)$ ma w punkcie $(u_0,v_0)$ pochodne cząstkowe, gdzie $u=g(x_0,y_0),v=h(x_0,y_0)$, \n",
"\n",
"to funkcja złożona $F(x,y)=f(g(x,y),h(x,y))$ ma w punkcie $(x_0,y_0)$ pochodne cząstkowe równe:\n",
"$$\n",
"\\frac{\\partial F}{\\partial x}(x_0,y_0)=\\frac{\\partial f}{\\partial u}(u_0,v_0)\n",
"\\cdot \\frac{\\partial g}{\\partial x}(x_0,y_0)+\\frac{\\partial f}{\\partial v}(u_0,v_0)\n",
"\\cdot \\frac{\\partial h}{\\partial x}(x_0,y_0)\n",
"$$\n",
"\n",
"$$\n",
"\\frac{\\partial F}{\\partial y}(x_0,y_0)=\\frac{\\partial f}{\\partial u}(u_0,v_0)\n",
"\\cdot \\frac{\\partial g}{\\partial y}(x_0,y_0)+\\frac{\\partial f}{\\partial v}(u_0,v_0)\n",
"\\cdot \\frac{\\partial h}{\\partial y}(x_0,y_0)\n",
"$$"
]
},
{
"cell_type": "markdown",
"id": "d7587290-fc47-469a-b378-c79a372f4157",
"metadata": {},
"source": [
"#### Zadanie 3\n",
"Niech \n",
"$$\n",
"f(x,y)=\\sin(x^2+y),\\quad g(x,y)=x^2+y\\quad \\text{ oraz } \\quad h(x,y)=xe^y.\n",
"$$\n",
"Obliczymy pochodne cząstkowe funkcji \n",
"$$ \n",
"F(x,y)=f(g(x,y),h(x,y)).\n",
"$$\n"
]
},
{
"cell_type": "markdown",
"id": "6447f860-e4ec-400b-8d71-b7582ba6530b",
"metadata": {},
"source": [
"##### Rozwiązanie:"
]
},
{
"cell_type": "markdown",
"id": "2ea9e169-4457-4d4c-8804-ff50ade4f495",
"metadata": {},
"source": [
"__I sposób__\n",
"\n",
"Ze wzorów wynika, że\n",
"$$\n",
"F(x,y)=\\sin(x^4+2x^2y+y^2+xe^{y}).\n",
"$$\n",
"Zatem \n",
"$$\n",
"\\frac{\\partial F}{\\partial x}(x,y)=\\cos(x^4+2x^2y+y^2+xe^{y})\\cdot(4x^3+4xy+e^y)\n",
"$$\n",
"oraz\n",
"$$\n",
"\\frac{\\partial F}{\\partial y}(x,y)=\\cos(x^4+2x^2y+y^2+xe^{y})\\cdot(2x^2+2y+xe^y).\n",
"$$\n"
]
},
{
"cell_type": "markdown",
"id": "ebd66e96-50fd-44ce-8afe-375b26fc0e7d",
"metadata": {},
"source": [
"__II sposób__\n",
"\n",
"Skorzystamy tym razem z reguły łańcucha.\n",
"\n",
"Mamy\n",
"\n",
"$$\\frac{\\partial f}{\\partial u}(u,v)= 2u\\cos(u^2+v)\\quad{ oraz }\\quad \n",
"\\frac{\\partial f}{\\partial v}(u,v)=\\cos(u^2+v).$$\n",
"\n",
"Zatem \n",
"$$\n",
"\\frac{\\partial F}{\\partial x}(x,y)=2(x^2+y)\\cos(x^4+2x^2y+y^2+xe^{y})\\cdot 2x+\\cos(x^4+2x^2y+y^2+xe^{y})\\cdot e^y=\n",
"\\cos(x^4+2x^2y+y^2+xe^{y})\\cdot(4x^3+4xy+e^y).\n",
"$$\n",
"oraz\n",
"$$\n",
"\\frac{\\partial F}{\\partial y}(x,y)=2(x^2+y)\\cos(x^4+2x^2y+y^2+xe^{y})\\cdot 1+\\cos(x^4+2x^2y+y^2+xe^{y})\\cdot xe^y=\n",
"\\cos(x^4+2x^2y+y^2+xe^{y})\\cdot(2x^2+2y+xe^y).\n",
"$$"
]
},
{
"cell_type": "markdown",
"id": "d6e27613-9dc9-44f5-80ae-9d5730e75baf",
"metadata": {},
"source": [
"## Pochodne cząstkowe wyższych rzędów"
]
},
{
"cell_type": "markdown",
"id": "9edc2c8f-97d8-4052-b231-5c5a718e9af8",
"metadata": {},
"source": [
"#### Zadanie 4\n",
"Wyznacz wszystkie pochodne cząstkowe rzędu drugiego dla funkcji \n",
"$$f(x,y)=e^{x^2+y}.$$\n",
"Co ciekawego zauważasz?"
]
},
{
"cell_type": "markdown",
"id": "ab762d49-d4fb-4cb1-9109-93f99d2a0482",
"metadata": {},
"source": [
"##### Rozwiązanie:"
]
},
{
"cell_type": "markdown",
"id": "fef2342f-e315-41c3-afb3-f7029dc9b2d3",
"metadata": {},
"source": [
"Mamy\n",
"$$\n",
"\\frac{\\partial f}{\\partial x}(x,y) = 2x e^{x^2 + y}\n",
"$$\n",
"oraz\n",
"$$\n",
"\\frac{\\partial f}{\\partial y}(x,y) =e^{x^2 + y}.\n",
"$$\n",
"Stąd\n",
"$$\n",
"\\frac{\\partial^2 f}{\\partial x^2}(x,y) = 2 e^{x^2 + y} + 4x^2 e^{x^2 + y},\\quad\n",
"\\frac{\\partial^2 f}{\\partial y^2} (x,y)= e^{x^2 + y}, \\quad\n",
"\\frac{\\partial^2 f}{\\partial x \\partial y}(x,y) = 2x e^{x^2 + y}\n",
"\\quad\\text{ oraz }\\quad \\frac{\\partial^2 f}{\\partial y \\partial x}(x,y) = 2x e^{x^2 + y}.\n",
"$$\n",
"\n",
"Zauważamy, że pochodne cząstkowe $\\frac{\\partial^2 f}{\\partial x \\partial y}(x,y)$ oraz $\\frac{\\partial^2 f}{\\partial y \\partial x}(x,y)$ są sobie równe.\n",
"To nie jest przypadek: patrz twierdzenie Schwarza na wykładzie."
]
},
{
"cell_type": "markdown",
"id": "b08b0f21-1684-4afc-9a26-3d72e5d8d7c6",
"metadata": {},
"source": [
"#### Zadanie 5 \n",
"Dla funkcji \n",
"$$f(x,y,z)=x^3y^2z$$\n",
"oblicz\n",
"$$\n",
"\\frac{\\partial^4 f}{\\partial x^4}(x,y,z),\\quad \\frac{\\partial^4 f}{\\partial x^3\\partial z}(x,y,z)\\quad\\text{ oraz }\\quad \\frac{\\partial^4 f}{\\partial z\\partial y \\partial x^2}(x,y,z)\n",
"$$"
]
},
{
"cell_type": "markdown",
"id": "415fe031-6d7e-413a-b3a1-88f9b970b92b",
"metadata": {},
"source": [
"##### Rozwiązanie:"
]
},
{
"cell_type": "markdown",
"id": "a323a470-c82b-4598-bb78-a69d6e9e09b0",
"metadata": {},
"source": [
"Mamy kolejno:\n",
"\n",
"$$ \n",
"\\frac{\\partial f}{\\partial x}(x,y,z)=3x^2y^2z, \\quad \\frac{\\partial^2 f}{\\partial x^2}(x,y,z)=6xy^2z, \\quad \\frac{\\partial^3 f}{\\partial x^3}(x,y,z)=6y^2z.\n",
"$$\n",
"Stąd\n",
"\n",
"$$\n",
"\\quad \\frac{\\partial^4 f}{\\partial x^4}(x,y,z)=0.\n",
"$$\n",
"Ponadto \n",
"$$\n",
"\\frac{\\partial^4 f}{\\partial x^3\\partial z}(x,y,z)=\\frac{\\partial^4 f}{\\partial z\\partial x^3}(x,y,z)=6y^2\n",
"$$\n",
"i \n",
"$$\n",
"\\frac{\\partial^4 f}{\\partial z\\partial y \\partial x^2}(x,y,z)=12xy.\n",
"$$"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.2"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": false,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": true
}
},
"nbformat": 4,
"nbformat_minor": 5
}