Упражнение с2
import matplotlib.pyplot as plt import numpy as np from matplotlib import cm fig = plt.figure() ax = fig.add_subplot(projection = '3d') xs = np.linspace(0, 1, 50) ys = np.linspace(0, 1, 50) X, Y = np.meshgrid(xs, ys) Z = X*Y ax.plot_surface(X, Y, Z, cmap=cm.cool, linewidth=0) xs = np.linspace(0, 1, 50) ys = np.linspace(0, 1, 50) X, Y = np.meshgrid(xs, ys) Z=X-X+Y-Y ax.plot_wireframe(X, Y, Z, rstride = 2, cstride = 2) xs = np.linspace(0, 1, 50) zs = np.linspace(0, 1, 50) X, Z = np.meshgrid(xs, zs) Y=X**2+Z*0 ax.plot_wireframe(X, Y, Z, rstride = 2, cstride = 2) ys = np.linspace(0, 1, 50) zs = np.linspace(0, 1, 50) Y, Z = np.meshgrid(ys, zs) X=Y**2+Z*0 ax.plot_wireframe(X, Y, Z, rstride = 2, cstride = 2)
<mpl_toolkits.mplot3d.art3d.Line3DCollection at 0x540a990>
from sympy.abc import x, y, z ff = z*x*y e, f = (0, x*y) c, d = (x**2, sqrt(x)) a, b = (0, 1) Iz = sp.integrate(ff, (z, e, f)) Iy = sp.integrate(Iz, (y, c, d)) Ix = sp.integrate(Iy, (x, a, b)) print(f'I = {Ix}')
I = 1/96
Упражнение с3
import matplotlib.pyplot as plt import numpy as np from matplotlib import cm fig = plt.figure() ax = fig.add_subplot(projection = '3d') xs = np.linspace(0, 0.1, 50) ys = np.linspace(0, 0.1, 50) X, Y = np.meshgrid(xs, ys) Z = (1+sqrt(1-4*X**2-4*Y**2))/2 ZZ = (1-sqrt(1-4*X**2-4*Y**2))/2 #Y=sqrt(Z-X**2-Z**2) #YY=-sqrt(Z-X**2-Z**2) ax.plot_surface(X, Y, Z, cmap=cm.cool, linewidth=0) ax.plot_surface(X, Y, ZZ, cmap=cm.cool, linewidth=0)
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) File /lib/python3.11/site-packages/sympy/core/cache.py:70, in __cacheit.<locals>.func_wrapper.<locals>.wrapper(*args, **kwargs) 69 try: ---> 70 retval = cfunc(*args, **kwargs) 71 except TypeError as e: TypeError: unhashable type: 'numpy.ndarray' During handling of the above exception, another exception occurred: SympifyError Traceback (most recent call last) Cell In[18], line 9 7 ys = np.linspace(0, 0.1, 50) 8 X, Y = np.meshgrid(xs, ys) ----> 9 Z = (1+sqrt(1-4*X**2-4*Y**2))/2 10 ZZ = (1-sqrt(1-4*X**2-4*Y**2))/2 11 #Y=sqrt(Z-X**2-Z**2) 12 #YY=-sqrt(Z-X**2-Z**2) File /lib/python3.11/site-packages/sympy/functions/elementary/miscellaneous.py:152, in sqrt(arg, evaluate) 68 """Returns the principal square root. 69 70 Parameters (...) 149 .. [2] https://en.wikipedia.org/wiki/Principal_value 150 """ 151 # arg = sympify(arg) is handled by Pow --> 152 return Pow(arg, S.Half, evaluate=evaluate) File /lib/python3.11/site-packages/sympy/core/cache.py:74, in __cacheit.<locals>.func_wrapper.<locals>.wrapper(*args, **kwargs) 72 if not e.args or not e.args[0].startswith('unhashable type:'): 73 raise ---> 74 retval = func(*args, **kwargs) 75 return retval File /lib/python3.11/site-packages/sympy/core/power.py:287, in Pow.__new__(cls, b, e, evaluate) 284 if evaluate is None: 285 evaluate = global_parameters.evaluate --> 287 b = _sympify(b) 288 e = _sympify(e) 290 # XXX: This can be removed when non-Expr args are disallowed rather 291 # than deprecated. File /lib/python3.11/site-packages/sympy/core/sympify.py:529, in _sympify(a) 503 def _sympify(a): 504 """ 505 Short version of :func:`~.sympify` for internal usage for ``__add__`` and 506 ``__eq__`` methods where it is ok to allow some things (like Python (...) 527 528 """ --> 529 return sympify(a, strict=True) File /lib/python3.11/site-packages/sympy/core/sympify.py:450, in sympify(a, locals, convert_xor, strict, rational, evaluate) 447 continue 449 if strict: --> 450 raise SympifyError(a) 452 if iterable(a): 453 try: SympifyError: SympifyError: array([[1. , 0.99998334, 0.99993336, ..., 0.96319867, 0.96161599, 0.96 ], [0.99998334, 0.99996668, 0.9999167 , ..., 0.96318201, 0.96159933, 0.95998334], [0.99993336, 0.9999167 , 0.99986672, ..., 0.96313203, 0.96154935, 0.95993336], ..., [0.96319867, 0.96318201, 0.96313203, ..., 0.92639733, 0.92481466, 0.92319867], [0.96161599, 0.96159933, 0.96154935, ..., 0.92481466, 0.92323199, 0.92161599], [0.96 , 0.95998334, 0.95993336, ..., 0.92319867, 0.92161599, 0.92 ]])
from sympy.abc import x, y, z ff = sqrt(x**2+y**2+z**2) e, f = ((1-sqrt(1-4*X**2-4*Y**2))/2, (1+sqrt(1-4*X**2-4*Y**2))/2) c, d = (-sqrt(-x**2), sqrt(-x**2)) a, b = (-0.5, -0.5) Iz = sp.integrate(ff, (z, e, f)) Iy = sp.integrate(Iz, (y, c, d)) Ix = sp.integrate(Iy, (x, a, b)) print(f'I = {Ix}')
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) File /lib/python3.11/site-packages/sympy/core/cache.py:70, in __cacheit.<locals>.func_wrapper.<locals>.wrapper(*args, **kwargs) 69 try: ---> 70 retval = cfunc(*args, **kwargs) 71 except TypeError as e: TypeError: unhashable type: 'numpy.ndarray' During handling of the above exception, another exception occurred: SympifyError Traceback (most recent call last) Cell In[19], line 3 1 from sympy.abc import x, y, z 2 ff = z*x*y ----> 3 e, f = ((1-sqrt(1-4*X**2-4*Y**2))/2, (1+sqrt(1-4*X**2-4*Y**2))/2) 4 c, d = (-sqrt(-x**2), sqrt(-x**2)) 5 a, b = (-0.5, -0.5) File /lib/python3.11/site-packages/sympy/functions/elementary/miscellaneous.py:152, in sqrt(arg, evaluate) 68 """Returns the principal square root. 69 70 Parameters (...) 149 .. [2] https://en.wikipedia.org/wiki/Principal_value 150 """ 151 # arg = sympify(arg) is handled by Pow --> 152 return Pow(arg, S.Half, evaluate=evaluate) File /lib/python3.11/site-packages/sympy/core/cache.py:74, in __cacheit.<locals>.func_wrapper.<locals>.wrapper(*args, **kwargs) 72 if not e.args or not e.args[0].startswith('unhashable type:'): 73 raise ---> 74 retval = func(*args, **kwargs) 75 return retval File /lib/python3.11/site-packages/sympy/core/power.py:287, in Pow.__new__(cls, b, e, evaluate) 284 if evaluate is None: 285 evaluate = global_parameters.evaluate --> 287 b = _sympify(b) 288 e = _sympify(e) 290 # XXX: This can be removed when non-Expr args are disallowed rather 291 # than deprecated. File /lib/python3.11/site-packages/sympy/core/sympify.py:529, in _sympify(a) 503 def _sympify(a): 504 """ 505 Short version of :func:`~.sympify` for internal usage for ``__add__`` and 506 ``__eq__`` methods where it is ok to allow some things (like Python (...) 527 528 """ --> 529 return sympify(a, strict=True) File /lib/python3.11/site-packages/sympy/core/sympify.py:450, in sympify(a, locals, convert_xor, strict, rational, evaluate) 447 continue 449 if strict: --> 450 raise SympifyError(a) 452 if iterable(a): 453 try: SympifyError: SympifyError: array([[1. , 0.99998334, 0.99993336, ..., 0.96319867, 0.96161599, 0.96 ], [0.99998334, 0.99996668, 0.9999167 , ..., 0.96318201, 0.96159933, 0.95998334], [0.99993336, 0.9999167 , 0.99986672, ..., 0.96313203, 0.96154935, 0.95993336], ..., [0.96319867, 0.96318201, 0.96313203, ..., 0.92639733, 0.92481466, 0.92319867], [0.96161599, 0.96159933, 0.96154935, ..., 0.92481466, 0.92323199, 0.92161599], [0.96 , 0.95998334, 0.95993336, ..., 0.92319867, 0.92161599, 0.92 ]])
