125 lines
2.9 KiB
Plaintext
125 lines
2.9 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "d2493461",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"2\n",
|
|
"2\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import sympy\n",
|
|
"\n",
|
|
"x = sympy.symbols('x')\n",
|
|
"h = 2\n",
|
|
"relu = sympy.Max(0, h) + sympy.Max(0, -h)\n",
|
|
"print(sympy.Max(h,0))\n",
|
|
"print(relu)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 17,
|
|
"id": "de59fd98",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/latex": [
|
|
"$\\displaystyle \\left[\\begin{matrix}x_{1} \\left(11 x_{1} - 12 x_{2}\\right) - 20 x_{1} + x_{2} \\left(- 12 x_{1} + 4 x_{2}\\right) + 40 x_{2} - 60\\end{matrix}\\right]$"
|
|
],
|
|
"text/plain": [
|
|
"Matrix([[x_1*(11*x_1 - 12*x_2) - 20*x_1 + x_2*(-12*x_1 + 4*x_2) + 40*x_2 - 60]])"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
},
|
|
{
|
|
"data": {
|
|
"text/latex": [
|
|
"$\\displaystyle \\left[\\begin{matrix}x_{1} \\left(11 x_{1} - 24 x_{2}\\right) - 20 x_{1} + 4 x_{2}^{2} + 40 x_{2} - 60\\end{matrix}\\right]$"
|
|
],
|
|
"text/plain": [
|
|
"Matrix([[x_1*(11*x_1 - 24*x_2) - 20*x_1 + 4*x_2**2 + 40*x_2 - 60]])"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
},
|
|
{
|
|
"data": {
|
|
"text/latex": [
|
|
"$\\displaystyle \\left[\\begin{matrix}x_{1} \\left(14.6 x_{1} - 7.2 x_{2}\\right) - 44 x_{1} + x_{2} \\left(- 7.2 x_{1} + 10.4 x_{2}\\right) + 8 x_{2} - 60\\end{matrix}\\right]$"
|
|
],
|
|
"text/plain": [
|
|
"Matrix([[x_1*(14.6*x_1 - 7.2*x_2) - 44*x_1 + x_2*(-7.2*x_1 + 10.4*x_2) + 8*x_2 - 60]])"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
}
|
|
],
|
|
"source": [
|
|
"import sympy as sp\n",
|
|
"import numpy\n",
|
|
"\n",
|
|
"x_1, x_2 = sp.symbols('x_1, x_2')\n",
|
|
"\n",
|
|
"A_1 = sp.Matrix([[11,-12],[-12,4]])\n",
|
|
"A_2 = sp.Matrix([[11,0],[-24,4]])\n",
|
|
"A_3 = sp.Matrix([[73/5,-36/5],[-36/5,52/5]])\n",
|
|
"\n",
|
|
"b_1 = sp.Matrix([-20,40])\n",
|
|
"b_2 = b_1\n",
|
|
"b_3 = sp.Matrix([-44,8])\n",
|
|
"\n",
|
|
"x = sp.Matrix([x_1,x_2])\n",
|
|
"\n",
|
|
"c = sp.Matrix([-60])\n",
|
|
"\n",
|
|
"q_1 = x.T * A_1 * x + b_1.T * x + c\n",
|
|
"\n",
|
|
"q_2 = x.T * A_2 * x + b_2.T * x + c\n",
|
|
"\n",
|
|
"q_3 = x.T * A_3 * x + b_3.T * x + c\n",
|
|
"\n",
|
|
"display(q_1)\n",
|
|
"\n",
|
|
"display(q_2)\n",
|
|
"\n",
|
|
"display(q_3)\n"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3",
|
|
"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.14.2"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|