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

python微元法計(jì)算函數(shù)曲線長(zhǎng)度的方法

 更新時(shí)間:2018年11月08日 14:31:53   作者:落葉_小唱  
今天小編就為大家分享一篇python微元法計(jì)算函數(shù)曲線長(zhǎng)度的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧

計(jì)算曲線長(zhǎng)度,根據(jù)線積分公式:

python微元法計(jì)算函數(shù)曲線長(zhǎng)度,令積分函數(shù) f(x,y,z) 為1,即計(jì)算曲線的長(zhǎng)度,將其微元化:

python微元法計(jì)算函數(shù)曲線長(zhǎng)度

其中

python微元法計(jì)算函數(shù)曲線長(zhǎng)度

根據(jù)此時(shí)便可在python編程實(shí)現(xiàn),給出4個(gè)例子,代碼中已有詳細(xì)注釋,不再贅述

'''
計(jì)算曲線長(zhǎng)度,根據(jù)線積分公式:
\int_A^Bf(x,y,z)dl,令積分函數(shù)為1,即計(jì)算曲線的長(zhǎng)度
'''
import numpy as np
from mpl_toolkits.mplot3d import *
import matplotlib.pyplot as plt

## 求二維圓周長(zhǎng),半徑為1,采用參數(shù)形式
def circle_2d(dt=0.001,plot=True):
 dt = dt # 變化率
 t = np.arange(0,2*np.pi, dt)
 x = np.cos(t)
 y = np.sin(t)

 # print(len(t))
 area_list = [] # 存儲(chǔ)每一微小步長(zhǎng)的曲線長(zhǎng)度

 for i in range(1,len(t)):
  # 計(jì)算每一微小步長(zhǎng)的曲線長(zhǎng)度,dx = x_{i}-x{i-1},索引從1開始
  dl_i = np.sqrt( (x[i]-x[i-1])**2 + (y[i]-y[i-1])**2 ) 
  # 將計(jì)算結(jié)果存儲(chǔ)起來
  area_list.append(dl_i)

 area = sum(area_list)# 求和計(jì)算曲線在t:[0,2*pi]的長(zhǎng)度

 print("二維圓周長(zhǎng):{:.4f}".format(area))
 if plot:
  fig = plt.figure()
  ax = fig.add_subplot(111)
  ax.plot(x,y)
  plt.title("circle")
  plt.show()


## 二維空間曲線,采用參數(shù)形式
def curve_param_2d(dt=0.0001,plot=True):
 dt = dt # 變化率
 t = np.arange(0,2*np.pi, dt)
 x = t*np.cos(t)
 y = t*np.sin(t)

 # print(len(t))
 area_list = [] # 存儲(chǔ)每一微小步長(zhǎng)的曲線長(zhǎng)度

 # 下面的方式是循環(huán)實(shí)現(xiàn)
 # for i in range(1,len(t)):
 #  # 計(jì)算每一微小步長(zhǎng)的曲線長(zhǎng)度,dx = x_{i}-x{i-1},索引從1開始
 #  dl_i = np.sqrt( (x[i]-x[i-1])**2 + (y[i]-y[i-1])**2 ) 
 #  # 將計(jì)算結(jié)果存儲(chǔ)起來
 #  area_list.append(dl_i)

 # 更加pythonic的寫法
 area_list = [np.sqrt( (x[i]-x[i-1])**2 + (y[i]-y[i-1])**2 ) for i in range(1,len(t))]

 area = sum(area_list)# 求和計(jì)算曲線在t:[0,2*pi]的長(zhǎng)度

 print("二維參數(shù)曲線長(zhǎng)度:{:.4f}".format(area))

 if plot:

  fig = plt.figure()
  ax = fig.add_subplot(111)
  ax.plot(x,y)
  plt.title("2-D Parameter Curve")
  plt.show()

## 二維空間曲線
def curve_2d(dt=0.0001,plot=True):
 dt = dt # 變化率
 t = np.arange(-6,10, dt)
 x = t
 y = x**3/8 - 4*x + np.sin(3*x)

 # print(len(t))
 area_list = [] # 存儲(chǔ)每一微小步長(zhǎng)的曲線長(zhǎng)度

 # for i in range(1,len(t)):
 #  # 計(jì)算每一微小步長(zhǎng)的曲線長(zhǎng)度,dx = x_{i}-x{i-1},索引從1開始
 #  dl_i = np.sqrt( (x[i]-x[i-1])**2 + (y[i]-y[i-1])**2 ) 
 #  # 將計(jì)算結(jié)果存儲(chǔ)起來
 #  area_list.append(dl_i)

 area_list = [np.sqrt( (x[i]-x[i-1])**2 + (y[i]-y[i-1])**2 ) for i in range(1,len(t))]

 area = sum(area_list)# 求和計(jì)算曲線在t:[0,2*pi]的長(zhǎng)度

 print("二維曲線長(zhǎng)度:{:.4f}".format(area))

 if plot:
  fig = plt.figure()
  ax = fig.add_subplot(111)
  ax.plot(x,y)
  plt.title("2-D Curve")
  plt.show()

## 三維空間曲線,采用參數(shù)形式
def curve_3d(dt=0.001,plot=True):
 dt = dt # 變化率
 t = np.arange(0,2*np.pi, dt)
 x = t*np.cos(t)
 y = t*np.sin(t)
 z = 2*t

 # print(len(t))
 area_list = [] # 存儲(chǔ)每一微小步長(zhǎng)的曲線長(zhǎng)度

 for i in range(1,len(t)):
  # 計(jì)算每一微小步長(zhǎng)的曲線長(zhǎng)度,dx = x_{i}-x{i-1},索引從1開始
  dl_i = np.sqrt( (x[i]-x[i-1])**2 + (y[i]-y[i-1])**2 + (z[i]-z[i-1])**2 ) 
  # 將計(jì)算結(jié)果存儲(chǔ)起來
  area_list.append(dl_i)

 area = sum(area_list)# 求和計(jì)算曲線在t:[0,2*pi]的長(zhǎng)度

 print("三維空間曲線長(zhǎng)度:{:.4f}".format(area))

 if plot:
  fig = plt.figure()
  ax = fig.add_subplot(111,projection='3d')
  ax.plot(x,y,z)
  plt.title("3-D Curve")
  plt.show()

if __name__ == '__main__':

 circle_2d(plot=True)
 curve_param_2d(plot=True)
 curve_2d(plot=True)
 curve_3d(plot=True)

得到結(jié)果:

二維圓周長(zhǎng):6.2830
二維參數(shù)曲線長(zhǎng)度:21.2558
二維曲線長(zhǎng)度:128.2037
三維空間曲線長(zhǎng)度:25.3421

python微元法計(jì)算函數(shù)曲線長(zhǎng)度

python微元法計(jì)算函數(shù)曲線長(zhǎng)度

python微元法計(jì)算函數(shù)曲線長(zhǎng)度

python微元法計(jì)算函數(shù)曲線長(zhǎng)度

以上這篇python微元法計(jì)算函數(shù)曲線長(zhǎng)度的方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

您可能感興趣的文章:

相關(guān)文章

最新評(píng)論

夏邑县| 嘉峪关市| 黔江区| 桃园市| 武陟县| 乳源| 保定市| 康平县| 隆尧县| 南安市| 乌鲁木齐县| 英吉沙县| 浦城县| 大厂| 大田县| 门源| 西乌珠穆沁旗| 梁平县| 泰和县| 黄山市| 堆龙德庆县| 农安县| 重庆市| 福海县| 盐山县| 北海市| 依兰县| 乌兰浩特市| 贺兰县| 平南县| 余江县| 潞西市| 云林县| 武陟县| 宁海县| 遂宁市| 游戏| 黎平县| 山丹县| 湟源县| 惠安县|