Упражнение 4
x1,y1=symbols('x1 y1') X1=Matrix([[x1,y1]]) X=T/sqrt(2)*X1.T # матрица Т - матрица перехода из примера 2 print('x=',simplify(X[0,0])) print('y=',simplify(X[1,0])) F=X[0]**2+4*X[0]*X[1]+4*X[1]**2-6*X[0]-2*X[1]+1 A=Matrix([[1,2],[2,4]]) AA=np.array([[2,-2],[-2,5]]) t,d=A.diagonalize() print("Собственные векторы:",t) print("Собственные числа:",d)
x= sqrt(2)*(-x1 + y1)/2 y= sqrt(2)*(x1 + y1)/2 Собственные векторы: Matrix([[-2, 1], [1, 2]]) Собственные числа: Matrix([[0, 0], [0, 5]])
xx1=t[0,0] xx2=t[0,1] xx3=xx1**2+xx2**2 print(xx3) yy1=t[1,0] yy2=t[1,1] yy3=yy1**2+yy2**2 print(y3)
5 5
x1,y1=symbols('x1 y1') x5=((t[0,0]*x1)/np.sqrt(5))+((y1*t[0,1])/np.sqrt(5)) y5=((t[1,0]*x1)/np.sqrt(5))+((y1*t[1,1])/np.sqrt(5)) print(x5) print(y5) xy5=-6*x5-2*y5 print(simplify(xy5))
-0.894427190999916*x1 + 0.447213595499958*y1 0.447213595499958*x1 + 0.894427190999916*y1 4.47213595499958*x1 - 4.47213595499958*y1
x1,y1=symbols('x1 y1') la1=0 la2=5 k1=10/np.sqrt(5) k2=-10/np.sqrt(5) print(k1) print(k2) f=1 aa=k2/(2*la2) bb=k2**2/(4*la2) F2=simplify((la2*(y1+aa)**2-bb+f+k1*x1)) F2
4.47213595499958 -4.47213595499958
4.47213595499958*x1 + 5*(y1 - 0.447213595499958)**2 - 2.22044604925031e-16
var('x y') plot_implicit(Eq(5*(y-0.45)**2+4.47*x+1,1),title='В новой СК', xlabel='x1',ylabel='y1')
<sympy.plotting.plot.Plot at 0x6a06d78>
Пример 4
x1,y1,z1=symbols('x1 y1 z1') XX=Matrix([[x1,y1,z1]]) X=T/3*XX.T # матрица Т1 - матрица перехода из упр.10.2 print(D1) print('x=',simplify(X[0,0])) print('y=',simplify(X[1,0])) print('z=',simplify(X[2,0])) H=6*X[0]**2-4*X[0]*X[1]+5*X[1]**2+7*X[2]**2+4*X[0]*X[2]-18 H=simplify(H/18) H
--------------------------------------------------------------------------- ShapeError Traceback (most recent call last) Input In [38], in <cell line: 3>() 1 x1,y1,z1=symbols('x1 y1 z1') 2 XX=Matrix([[x1,y1,z1]]) ----> 3 X=T/3*XX.T # матрица Т1 - матрица перехода из упр.10.2 4 print(D1) 5 print('x=',simplify(X[0,0])) File C:\Programs\Anaconda3\lib\site-packages\sympy\core\decorators.py:106, in call_highest_priority.<locals>.priority_decorator.<locals>.binary_op_wrapper(self, other) 104 if f is not None: 105 return f(self) --> 106 return func(self, other) File C:\Programs\Anaconda3\lib\site-packages\sympy\matrices\common.py:2774, in MatrixArithmetic.__mul__(self, other) 2745 @call_highest_priority('__rmul__') 2746 def __mul__(self, other): 2747 """Return self*other where other is either a scalar or a matrix 2748 of compatible dimensions. 2749 (...) 2771 matrix_multiply_elementwise 2772 """ -> 2774 return self.multiply(other) File C:\Programs\Anaconda3\lib\site-packages\sympy\matrices\common.py:2796, in MatrixArithmetic.multiply(self, other, dotprodsimp) 2792 if (hasattr(other, 'shape') and len(other.shape) == 2 and 2793 (getattr(other, 'is_Matrix', True) or 2794 getattr(other, 'is_MatrixLike', True))): 2795 if self.shape[1] != other.shape[0]: -> 2796 raise ShapeError("Matrix size mismatch: %s * %s." % ( 2797 self.shape, other.shape)) 2799 # honest SymPy matrices defer to their class's routine 2800 if getattr(other, 'is_Matrix', False): ShapeError: Matrix size mismatch: (2, 2) * (3, 1).
# Построение эллипсоида в сферических координатах fig = plt.figure(figsize=(7, 7)) # создаём холст ax = fig.add_subplot(111, projection='3d') coefs = (6, 3, 2)# коэффициенты уравнения rx, ry, rz = 1/np.sqrt(coefs) # радиусы # Сферические углы: u = np.linspace(0, 2*np.pi, 100) v = np.linspace(0, np.pi, 100) # Уравнение эллипсоида: x = rx*np.outer(np.cos(u), np.sin(v)) y = ry*np.outer(np.sin(u), np.sin(v)) z = rz*np.outer(np.ones_like(u), np.cos(v)) ax.plot_surface(x,y,z, rstride=5, cstride=5, color='m') plt.xlabel('x') plt.ylabel('y') plt.title('Эллипсоид') plt.show()
