1. Trang chủ
  2. » Giáo Dục - Đào Tạo

Thảo luận nhóm TMU học PHẦN TOÁN CAO cấp NHIỆM vụ sử DỤNG PYTHON GIẢI các bài TOÁN

49 20 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 49
Dung lượng 1,58 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

File "D:\toandaicuong\main.py", line 4, in x = np.linalg.solvea,b File "", line 180, in solve File "D:\toandaicuong\venv\lib\site-packages\numpy\linalg\linalg.py", line 393, in solve r

Trang 1

TRƯỜNG ĐẠI HỌC THƯƠNG MẠI

KHOA HTTTKT & TMĐT

BÀI THẢO LUẬN HỌC PHẦN: TOÁN CAO CẤP NHIỆM VỤ: SỬ DỤNG PYTHON GIẢI CÁC BÀI TOÁN

2213AMTA1011

Giảng viên : Lê Văn TuấnNhóm thực hiện : Nhóm 8

Trang 5

NHIỆM VỤ 3 : Giải hệ PTTT của bài 3.4, 3.6, 3.9 với m =

Trang 7

File "D:\toandaicuong\main.py", line 4, in <module> x =

np.linalg.solve(a,b)

File "< array_function internals>", line 180, in solve File

"D:\toandaicuong\venv\lib\site-packages\numpy\linalg\linalg.py", line 393, in solve

r = gufunc(a, b, signature=signature, extobj=extobj) File "D:\toandaicuong\venv\lib\site-

packages\numpy\linalg\linalg.py", line 88, in

_raise_linalgerror_singular

raise LinAlgError("Singular matrix")

numpy.linalg.LinAlgError: Singular matrix

Hệ vô nghiệm hoặc vô số nghiệm

from matplotlib import pyplot as plt

from mpl_toolkits.mplot3d import Axes3D x =

np.arange(8,16,0.4)

y = x*(((1-2*x)**2)**(1/3)) plt.plot(x,y) plt.xlabel("Truc x")

plt.ylabel("Truc y") plt.title('Toan cao cap') plt.show()

Kết quả :

Trang 8

Nhập:

import numpy as np

from matplotlib import pyplot as plt

from mpl_toolkits.mplot3d import Axes3D x =

Trang 9

Nhập:

import numpy as np

from matplotlib import pyplot as plt

from mpl_toolkits.mplot3d import Axes3D x =

Trang 10

Nhập:

import numpy as np

from matplotlib import pyplot as plt

from mpl_toolkits.mplot3d import Axes3D x =

Trang 11

Nhập:

import numpy as np

from matplotlib import pyplot as plt

from mpl_toolkits.mplot3d import Axes3D x =

Trang 12

Nhập:

import numpy as np

from matplotlib import pyplot as plt

from mpl_toolkits.mplot3d import Axes3D x =

np.arange(8,16,0.4)

y =(x+1)*(((x**2)-1)**(1/3)) plt.plot(x,y) plt.xlabel("Truc x")

plt.ylabel("Truc y") plt.title('Toan cao cap') plt.show()

Kết quả :

Trang 13

Nhập:

import numpy as np

from matplotlib import pyplot as plt

from mpl_toolkits.mplot3d import Axes3D x =

np.arange(8,16,0.4)

y =x*(((x**2)-1)**(1/8)) plt.plot(x,y) plt.xlabel("Truc x")

plt.ylabel("Truc y") plt.title('Toan cao cap') plt.show()

Kết quả :

Trang 14

B Vẽ đồ thị các hàm số trong bài 7.3 trên miền x [8,16]; y [1,8]

7.3.1

Nhập:

import numpy as np

from matplotlib import pyplot as plt

from mpl_toolkits.mplot3d import Axes3D x =

Trang 15

Nhập:

import numpy as np

from matplotlib import pyplot as plt

from mpl_toolkits.mplot3d import Axes3D x =

Trang 16

Nhập:

import numpy as np

from matplotlib import pyplot as plt

from mpl_toolkits.mplot3d import Axes3D x =

Trang 21

z_y = sympy lambdify((x, y), z_y)

x, y = sympy.symbols ('x y', real = True)

z = sympy.log(x + sympy.sqrt(x**2 + y**2))

Trang 23

return -x*arctan(sqrt(x**2 - y**2))/(x**2 + y**2)**(3/2) +

x/(sqrt(x**2 - y**2)*sqrt(x**2 + y**2)*(x**2 - y**2 + 1))

<lambdifygenerated-2>:2: RuntimeWarning: invalid value

encountered in sqrt

return -y*arctan(sqrt(x**2 - y**2))/(x**2 + y**2)**(3/2)

- y/(sqrt(x**2 - y**2)*sqrt(x**2 + y**2)*(x**2 - y**2 + 1))

Trang 25

Nhập :

import sympy

x, y = sympy.symbols ('x y', real = True)

z = sympy.log(x + sympy.sqrt(x**2 + y**2))

Trang 28

<lambdifygenerated-2>:2: RuntimeWarning: invalid value

encountered in sqrt

return 3*x*y*arctan(sqrt(x**2 - y**2))/(x**2 + y**2)**(5/2)

+ 2*x*y/(sqrt(x**2 - y**2)*sqrt(x**2 + y**2)*(x**2 - y**2 +

1)**2) + x*y/((x**2 - y**2)**(3/2)*sqrt(x**2 + y**2)*(x**2 -

(sqrt(x**2 - y**2)*sqrt(x**2 + y**2)*(x**2 - y**2 + 1))

Trang 29

Giải thích : Lỗi do tập xác định vì => x>y mà x<y (8<16)

Trang 30

Optimization terminated successfully

Current function value: 0.000000 Iterations: 15

Function evaluations: 30[0.5]

Trang 31

Kết quả :

Optimization terminated successfully

Current function value: -0.250000 Iterations: 18

Function evaluations: 36[-0.5]

from scipy.optimize import fmin

def f(x): return x/math.exp(x)

Trang 32

Nhập: import math

from scipy.optimize import fmin

def f(x): return x*(math.log(x))**2

min_loc = fmin(f, 1.0)

print(min_loc)

print(f(*min_loc))

Kết quả :

Optimization terminated successfully

Current function value: 0.000000 Iterations: 10

Function evaluations: 20[1.]

Trang 33

min_loc = fmin(f, 1.0)

print(min_loc)

print(f(*min_loc))

Kết quả :

Optimization terminated successfully

Current function value: 1.000000 Iterations: 17

Function evaluations: 34[-8.8817842e-16]

from scipy.optimize import fmin

def f(x): return (x+1)*((math.pow(x,2)-1)**1/3)

min_loc = fmin(f, 1.0)

print(min_loc)

print(f(*min_loc))

Kết quả :

Optimization terminated successfully

Current function value: -0.395062

Trang 34

Iterations: 16Function evaluations: 32[0.33330078]

Optimization terminated successfully

Current function value: -0.128300 Iterations: 15

Function evaluations: 30[0.57734375]

-0.12830005979537965

Ghi chú Hàm số đạt min tại x = 0.57734375 Giá

trị min: -0.12830005979537965

Trang 35

Ghi chú Giá trị max vượt quá giá trị lớn nhất của

Python (hàm số tiến ra vô cùng)

Trang 36

Ghi chú Giá trị max vượt quá giá trị lớn nhất của

Python (hàm số tiến ra vô cùng)

6.10.3,

Nhập: import math

from scipy.optimize import fmin

def f(x): return -(x/math.e**x)

min_loc = fmin(f, 1.0)

print(min_loc)

print(-f(*min_loc))

Kết quả :

Optimization terminated successfully

Current function value: -0.367879 Iterations: 10

Function evaluations: 20[1.]

0.36787944117144233

Trang 37

Ghi chú Hàm số đạt max tại x = 1 Giá trị

max : 0.36787944117144233

6.10.4,

Nhập: import math

from scipy.optimize import fmin

def f(x): return -(x*math.log(x)**2)

Ghi chú Giá trị max vượt quá giá trị lớn nhất của

Python (hàm số tiến ra vô cùng)

6.10.5,

Nhập: import math

from scipy.optimize import fmin

def f(x): return -(math.exp(x)/(x+1))

min_loc = fmin(f, 1.0)

Trang 38

from scipy.optimize import fmin

def f(x): return -((x+1)*((math.pow(x,2)-1)**1/3))

Ghi chú Giá trị max vượt quá giá trị lớn nhất của

Python (hàm số tiến ra vô cùng)

6.10.7,

Nhập: import math

Trang 39

from scipy.optimize import fmin

Ghi chú Giá trị max vượt quá giá trị lớn nhất của

Python (hàm số tiến ra vô cùng)

7.9

* Tìm MIN

7.9.1,

Nhập: import math

from scipy.optimize import fmin

def f(x,y): return x**2 + x*y +y**2 +x-y+1

min_loc = fmin(lambda vec: f(vec[0],

vec[1]), [0.1, 0.1])

print(min_loc)

print(f(*min_loc))

Trang 40

Kết quả :

Optimization terminated successfully

Current function value: 0.000000 Iterations: 39

Function evaluations: 76[-1.00001244 1.00003511]

from scipy.optimize import fmin

def f(x,y): return 2*x**4+y**4-x**2-2*y**2

min_loc = fmin(lambda vec: f(vec[0],

vec[1]), [0.1, 0.1])

print(min_loc)

print(f(*min_loc))

Kết quả :

Optimization terminated successfully

Current function value: -1.125000 Iterations: 46

Function evaluations: 89

Trang 42

Nhập :

import sympy

x, y = sympy.symbols ('x y', real = True)

z = sympy.log(x + sympy.sqrt(x**2 + y**2)) z_x = sympy.diff(z, x)

Trang 45

import sympy

x, y = sympy.symbols ('x y', real = True)

Trang 46

z xy sympy diff(z x y)

Trang 49

<lambdifygenerated-2>:2: RuntimeWarning: invalid value encountered in sqrt

return 3*x*y*arctan(sqrt(x**2 - y**2))/(x**2 + y**2)**(5/2) + 2*x*y/(sqrt(x**2 - y**2)*sqrt(x**2 + y**2)*(x**2 - y**2 +

1)**2) + x*y/((x**2 - y**2)**(3/2)*sqrt(x**2 + y**2)*(x**2 -

- y**2)*sqrt(x**2 + y**2)*(x**2 - y**2 + 1))

28

Ngày đăng: 05/08/2022, 10:23

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

🧩 Sản phẩm bạn có thể quan tâm

w