最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python數(shù)值方法及數(shù)據(jù)可視化

 更新時間:2022年09月01日 10:24:37   作者:Chandler_river  
這篇文章主要介紹了Python數(shù)值方法及數(shù)據(jù)可視化,文章圍繞主題展開詳細的內(nèi)容介紹,具有一定的參考價值,需要的小伙伴可以參考一下
  • 隨機數(shù)和蒙特卡洛模擬
  • 求解單一變量非線性方程
  • 求解線性系統(tǒng)方程
  • 函數(shù)的數(shù)學(xué)積分
  • 常微分方程的數(shù)值解

等勢線繪圖和曲線:

等勢線 

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
 
x_vals = np.linspace(-5,5,20)
y_vals = np.linspace(0,10,20)
 
X,Y = np.meshgrid(x_vals,y_vals)
Z = X**2 * Y**0.5
line_count = 15
 
ax = Axes3D(plt.figure())
ax.plot_surface(X,Y,Z,rstride=1,cstride=1)
plt.show()

非線性方程的數(shù)學(xué)解:

  • 一般實函數(shù)  Scipy.optimize
  • fsolve函數(shù)求零點(限定只給實數(shù)解)
import scipy.optimize as so
from scipy.optimize import fsolve
 
f = lambda x:x**2-1
fsolve(f,0.5)
fsolve(f,-0.5)
fsolve(f,[-0.5,0.5])
 
 
>>>fsolve(f,-0.5,full_output=True)
>>>(array([-1.]), {'nfev': 9, 'fjac': array([[-1.]]), 'r': array([1.99999875]), 'qtf': array([3.82396337e-10]), 'fvec': array([4.4408921e-16])}, 1, 'The solution converged.')
 
>>>help(fsolve)
>>>Help on function fsolve in module scipy.optimize._minpack_py:
 
fsolve(func, x0, args=(), fprime=None, full_output=0, col_deriv=0, xtol=1.49012e-08, maxfev=0, band=None, epsfcn=None, factor=100, diag=None)
    Find the roots of a function.

    Return the roots of the (non-linear) equations defined by
    ``func(x) = 0`` given a starting estimate.

    Parameters
    ----------
    func : callable ``f(x, *args)``
        A function that takes at least one (possibly vector) argument,
        and returns a value of the same length.
    x0 : ndarray
        The starting estimate for the roots of ``func(x) = 0``.
    args : tuple, optional
        Any extra arguments to `func`.
    fprime : callable ``f(x, *args)``, optional
        A function to compute the Jacobian of `func` with derivatives
        across the rows. By default, the Jacobian will be estimated.
    full_output : bool, optional
        If True, return optional outputs.
    col_deriv : bool, optional
        Specify whether the Jacobian function computes derivatives down
        the columns (faster, because there is no transpose operation).
    xtol : float, optional
        The calculation will terminate if the relative error between two
        consecutive iterates is at most `xtol`.
    maxfev : int, optional
        The maximum number of calls to the function. If zero, then
        ``100*(N+1)`` is the maximum where N is the number of elements
        in `x0`.
    band : tuple, optional
        If set to a two-sequence containing the number of sub- and
        super-diagonals within the band of the Jacobi matrix, the
        Jacobi matrix is considered banded (only for ``fprime=None``).
    epsfcn : float, optional
        A suitable step length for the forward-difference
        approximation of the Jacobian (for ``fprime=None``). If
        `epsfcn` is less than the machine precision, it is assumed
        that the relative errors in the functions are of the order of
        the machine precision.
    factor : float, optional
        A parameter determining the initial step bound
        (``factor * || diag * x||``). Should be in the interval
        ``(0.1, 100)``.
    diag : sequence, optional
        N positive entries that serve as a scale factors for the
        variables.

    Returns
    -------
    x : ndarray
        The solution (or the result of the last iteration for
        an unsuccessful call).
    infodict : dict
        A dictionary of optional outputs with the keys:

        ``nfev``
            number of function calls
        ``njev``
            number of Jacobian calls
        ``fvec``
            function evaluated at the output
        ``fjac``
            the orthogonal matrix, q, produced by the QR
            factorization of the final approximate Jacobian
            matrix, stored column wise
        ``r``
            upper triangular matrix produced by QR factorization
            of the same matrix
        ``qtf``
            the vector ``(transpose(q) * fvec)``

    ier : int
        An integer flag.  Set to 1 if a solution was found, otherwise refer
        to `mesg` for more information.
    mesg : str
        If no solution is found, `mesg` details the cause of failure.

    See Also
    --------
    root : Interface to root finding algorithms for multivariate
           functions. See the ``method=='hybr'`` in particular.

    Notes
    -----
    ``fsolve`` is a wrapper around MINPACK's hybrd and hybrj algorithms.

    Examples
    --------
    Find a solution to the system of equations:
    ``x0*cos(x1) = 4,  x1*x0 - x1 = 5``.

    >>> from scipy.optimize import fsolve
    >>> def func(x):
    ...     return [x[0] * np.cos(x[1]) - 4,
    ...             x[1] * x[0] - x[1] - 5]
    >>> root = fsolve(func, [1, 1])
    >>> root
    array([6.50409711, 0.90841421])
    >>> np.isclose(func(root), [0.0, 0.0])  # func(root) should be almost 0.0.
    array([ True,  True])

關(guān)鍵字參數(shù):  full_output=True 

多項式的復(fù)數(shù)根 :np.roots([最高位系數(shù),次高位系數(shù),... ... x項系數(shù),常數(shù)項])

>>>f = lambda x:x**4 + x -1
>>>np.roots([1,0,0,1,-1])
>>>array([-1.22074408+0.j        ,  0.24812606+1.03398206j,
        0.24812606-1.03398206j,  0.72449196+0.j        ])
  • 求解線性等式   scipy.linalg
  • 利用dir()獲取常用函數(shù)

import numpy as np
import scipy.linalg as sla
from scipy.linalg import inv
a = np.array([-1,5])
c = np.array([[1,3],[3,4]])
x = np.dot(inv(c),a)
 
>>>x
>>>array([ 3.8, -1.6])

數(shù)值積分  scipy.integrate 

  •  利用dir()獲取你需要的信息
  • 對自定義函數(shù)做積分

import scipy.integrate as si
from scipy.integrate import quad
import numpy as np
import matplotlib.pyplot as plt
f = lambda x:x**1.05*0.001
 
interval = 100
xmax = np.linspace(1,5,interval)
integral,error = np.zeros(xmax.size),np.zeros(xmax.size)
for i in range(interval):
    integral[i],error[i] = quad(f,0,xmax[i])
plt.plot(xmax,integral,label="integral")
plt.plot(xmax,error,label="error")
plt.show()

對震蕩函數(shù)做積分

quad 函數(shù)允許 調(diào)整他使用的網(wǎng)格

>>>(-0.4677718053224297, 2.5318630220102742e-05)
>>>quad(np.cos,-1,1,limit=100)
>>>(1.6829419696157932, 1.8684409237754643e-14)
>>>quad(np.cos,-1,1,limit=1000)
>>>(1.6829419696157932, 1.8684409237754643e-14)
>>>quad(np.cos,-1,1,limit=10)
>>>(1.6829419696157932, 1.8684409237754643e-14)

微分方程的數(shù)值解 參見  Python數(shù)值求解微分方程方法(歐拉法,隱式歐拉)

向量場與流線圖:

vector(x,y) = (y,-x)  

import numpy as np
import matplotlib.pyplot as plt
coords = np.linspace(-1,1,30)
X,Y = np.meshgrid(coords,coords)
Vx,Vy = Y,-X
 
plt.quiver(X,Y,Vx,Vy)
plt.show()
------------------
import numpy as np
import matplotlib.pyplot as plt
 
coords = np.linspace(-2,2,10)
X,Y = np.meshgrid(coords,coords)
Z = np.exp(np.exp(X+Y))
 
ds = 4/6
dX,dY = np.gradient(Z,ds)
plt.contourf(X,Y,Z,25)
plt.quiver(X,Y,dX.transpose(),dY.transpose(),scale=25)
plt.show()

到此這篇關(guān)于Python數(shù)值方法及數(shù)據(jù)可視化的文章就介紹到這了,更多相關(guān)Python數(shù)值 視化內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • tensorflow+k-means聚類簡單實現(xiàn)貓狗圖像分類的方法

    tensorflow+k-means聚類簡單實現(xiàn)貓狗圖像分類的方法

    這篇文章主要介紹了tensorflow+k-means聚類簡單實現(xiàn)貓狗圖像分類,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-04-04
  • Python實現(xiàn)名片管理系統(tǒng)

    Python實現(xiàn)名片管理系統(tǒng)

    這篇文章主要為大家詳細介紹了Python實現(xiàn)名片管理系統(tǒng),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-02-02
  • Python Socket編程詳細介紹

    Python Socket編程詳細介紹

    這篇文章主要介紹了Python Socket編程詳細介紹,socket可以建立連接,傳遞數(shù)據(jù),具有一定的參考價值,感興趣的小伙伴們可以參考一下。
    2017-03-03
  • Python 互換字典的鍵值對實例

    Python 互換字典的鍵值對實例

    今天小編就為大家分享一篇Python 互換字典的鍵值對實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-02-02
  • Python魔法方法 容器部方法詳解

    Python魔法方法 容器部方法詳解

    這篇文章主要介紹了Python魔法方法 容器部方法詳解,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-01-01
  • 如何利用Python實現(xiàn)給Excel表格截圖

    如何利用Python實現(xiàn)給Excel表格截圖

    這篇文章主要為大家詳細介紹了如何利用Python實現(xiàn)給Excel表格截圖功能,文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2025-02-02
  • Python+Opencv實現(xiàn)數(shù)字識別的示例代碼

    Python+Opencv實現(xiàn)數(shù)字識別的示例代碼

    這篇文章主要介紹了Python+Opencv實現(xiàn)數(shù)字識別的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-03-03
  • 人工智能——K-Means聚類算法及Python實現(xiàn)

    人工智能——K-Means聚類算法及Python實現(xiàn)

    這篇文章主要介紹了人工智能——K-Means聚類算法及Python實現(xiàn),一個能夠找到我圈出的這?些點集的算法,就被稱為聚類算法,下面就來看看文章具體的介紹吧
    2022-01-01
  • 使用Python自制一個回收站清理器

    使用Python自制一個回收站清理器

    經(jīng)常筆記本電腦的回收站存儲了很多的文件,需要打開回收站全部選中進行清理。這篇文章將使用Python自制一個回收站清理器,需要的可以參考一下
    2023-03-03
  • Python模擬登陸實現(xiàn)代碼

    Python模擬登陸實現(xiàn)代碼

    本篇文章主要介紹了Python模擬登陸實現(xiàn)代碼,這里整理了詳細的代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-06-06

最新評論

张北县| 汉阴县| 桐梓县| 广德县| 博野县| 图木舒克市| 高陵县| 庆云县| 庆安县| 福州市| 张家港市| 乌拉特中旗| 商河县| 大姚县| 巴中市| 崇州市| 正镶白旗| 甘泉县| 牟定县| 芮城县| 察隅县| 拉萨市| 巴林左旗| 共和县| 阜南县| 北川| 温州市| 嘉黎县| 格尔木市| 石景山区| 咸宁市| 邳州市| 万年县| 本溪市| 肇州县| 宜城市| 和田市| 舒城县| 富平县| 黑水县| 库尔勒市|