{ "cells": [ { "cell_type": "code", "execution_count": 14, "id": "b21d3072-49a3-47c8-b6ed-5926fc165ad5", "metadata": {}, "outputs": [], "source": [ "from sympy.vector import CoordSys3D, Del, express\n", "from sympy import vector\n", "from sympy import symbols\n", "from sympy.abc import x, y, z, r, theta\n", "import numpy as np" ] }, { "cell_type": "code", "execution_count": 2, "id": "941cd86f-95b3-4d6b-98b4-e94fe9391bac", "metadata": {}, "outputs": [], "source": [ "a1, a2, a3 = symbols(\"a1 a2 a3\")" ] }, { "cell_type": "code", "execution_count": 3, "id": "97495bbf-c436-416c-9746-4ebf454a4137", "metadata": {}, "outputs": [], "source": [ "N = CoordSys3D('N')" ] }, { "cell_type": "code", "execution_count": 4, "id": "ac3437bd-5da2-4663-b056-a4a9ee407a8c", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\mathbf{\\hat{i}_{N}}$" ], "text/plain": [ "N.i" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "N.i" ] }, { "cell_type": "code", "execution_count": 5, "id": "d88ed004-11a8-4b21-8fe8-c40e55d77b92", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\operatorname{Point}\\left(N.origin, \\mathbf{\\hat{0}}\\right)$" ], "text/plain": [ "N.origin" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "N.origin" ] }, { "cell_type": "code", "execution_count": 6, "id": "43946e3c-6b3b-4a95-a857-ccb2e98374a7", "metadata": { "jupyter": { "source_hidden": true } }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\operatorname{Point}\\left(A, \\left(a_{1}\\right)\\mathbf{\\hat{i}_{N}} + \\left(a_{2}\\right)\\mathbf{\\hat{j}_{N}} + \\left(a_{3}\\right)\\mathbf{\\hat{k}_{N}}, \\operatorname{Point}\\left(N.origin, \\mathbf{\\hat{0}}\\right)\\right)$" ], "text/plain": [ "A" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A = N.origin.locate_new(\"A\", a1*N.i + a2*N.j + a3*N.k)\n", "A" ] }, { "cell_type": "code", "execution_count": 7, "id": "bf493bda-b7c5-4f27-b190-6a94ab9adae1", "metadata": {}, "outputs": [], "source": [ "C = CoordSys3D('C')" ] }, { "cell_type": "code", "execution_count": 8, "id": "b008fe56-e9c8-4b57-8f2a-32f778f329c5", "metadata": {}, "outputs": [], "source": [ "delop = Del()" ] }, { "cell_type": "code", "execution_count": 9, "id": "8816c468-b001-492e-95ef-cb3b17b71bbf", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left(\\mathbf{{x}_{C}} \\mathbf{{y}_{C}}\\right)\\mathbf{\\hat{j}_{C}} + \\left(- \\mathbf{{x}_{C}} \\mathbf{{z}_{C}}\\right)\\mathbf{\\hat{k}_{C}}$" ], "text/plain": [ "C.x*C.y*C.j + (-C.x*C.z)*C.k" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(delop ^ C.x*C.y*C.z*C.i).doit()" ] }, { "cell_type": "code", "execution_count": 10, "id": "3963fcc1-4476-4934-a4e3-7575bddbe5d5", "metadata": {}, "outputs": [], "source": [ "C = N.create_new('C', transformation='cylindrical', variable_names=(\"r\", \"theta\", \"z\"))" ] }, { "cell_type": "code", "execution_count": 11, "id": "7868851b-1291-4f21-afc0-334f740619cc", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left(x\\right)\\mathbf{\\hat{i}_{N}} + \\left(y\\right)\\mathbf{\\hat{j}_{N}} + \\left(z\\right)\\mathbf{\\hat{k}_{N}}$" ], "text/plain": [ "x*N.i + y*N.j + z*N.k" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "v1 = x*N.i + y*N.j+ z*N.k\n", "v1" ] }, { "cell_type": "code", "execution_count": 12, "id": "e55937ab-31d1-4cfe-ae65-ccd99dc3d800", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left(- \\frac{d}{d \\mathbf{{z}_{N}}} y + \\frac{d}{d \\mathbf{{y}_{N}}} z\\right)\\mathbf{\\hat{i}_{N}} + \\left(\\frac{d}{d \\mathbf{{z}_{N}}} x - \\frac{d}{d \\mathbf{{x}_{N}}} z\\right)\\mathbf{\\hat{j}_{N}} + \\left(- \\frac{d}{d \\mathbf{{y}_{N}}} x + \\frac{d}{d \\mathbf{{x}_{N}}} y\\right)\\mathbf{\\hat{k}_{N}}$" ], "text/plain": [ "(-Derivative(y, N.z) + Derivative(z, N.y))*N.i + (Derivative(x, N.z) - Derivative(z, N.x))*N.j + (-Derivative(x, N.y) + Derivative(y, N.x))*N.k" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cv1 = delop.cross(v1)\n", "cv1" ] }, { "cell_type": "code", "execution_count": 13, "id": "d2fce40e-292e-495e-b0d9-6db9529487bd", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left(- \\frac{d}{d \\mathbf{{z}_{N}}} y + \\frac{d}{d \\mathbf{{y}_{N}}} z\\right)\\mathbf{\\hat{i}_{C}} + \\left(\\frac{d}{d \\mathbf{{z}_{N}}} x - \\frac{d}{d \\mathbf{{x}_{N}}} z\\right)\\mathbf{\\hat{j}_{C}} + \\left(- \\frac{d}{d \\mathbf{{y}_{N}}} x + \\frac{d}{d \\mathbf{{x}_{N}}} y\\right)\\mathbf{\\hat{k}_{C}}$" ], "text/plain": [ "(-Derivative(y, N.z) + Derivative(z, N.y))*C.i + (Derivative(x, N.z) - Derivative(z, N.x))*C.j + (-Derivative(x, N.y) + Derivative(y, N.x))*C.k" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "express(cv1, C)" ] }, { "cell_type": "code", "execution_count": 15, "id": "fee5ea69-87af-4bf3-95df-b807f05688f6", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "numpy.ndarray" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(np.array((1,2,3)))" ] }, { "cell_type": "code", "execution_count": 16, "id": "14aaf5d0-b984-4638-88cb-169fc3cbecee", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type((1,2,3)) == tuple" ] }, { "cell_type": "code", "execution_count": 17, "id": "5482e5cb-d850-429b-b80a-744afcfee2c9", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type((1,2,3)) == list" ] }, { "cell_type": "code", "execution_count": 20, "id": "535a8ca7-2ca5-4820-b312-34b6a451f845", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(super(tuple)) == super" ] }, { "cell_type": "code", "execution_count": null, "id": "b1a7fe52-84b8-4f58-90af-f5fc1a5027d8", "metadata": {}, "outputs": [], "source": [] } ], "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.8.10" } }, "nbformat": 4, "nbformat_minor": 5 }