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

python微元法計算函數(shù)曲線長度的方法

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

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

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

python微元法計算函數(shù)曲線長度

其中

python微元法計算函數(shù)曲線長度

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

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

## 求二維圓周長,半徑為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 = [] # 存儲每一微小步長的曲線長度

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

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

 print("二維圓周長:{:.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 = [] # 存儲每一微小步長的曲線長度

 # 下面的方式是循環(huán)實現(xiàn)
 # for i in range(1,len(t)):
 #  # 計算每一微小步長的曲線長度,dx = x_{i}-x{i-1},索引從1開始
 #  dl_i = np.sqrt( (x[i]-x[i-1])**2 + (y[i]-y[i-1])**2 ) 
 #  # 將計算結果存儲起來
 #  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)# 求和計算曲線在t:[0,2*pi]的長度

 print("二維參數(shù)曲線長度:{:.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 = [] # 存儲每一微小步長的曲線長度

 # for i in range(1,len(t)):
 #  # 計算每一微小步長的曲線長度,dx = x_{i}-x{i-1},索引從1開始
 #  dl_i = np.sqrt( (x[i]-x[i-1])**2 + (y[i]-y[i-1])**2 ) 
 #  # 將計算結果存儲起來
 #  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)# 求和計算曲線在t:[0,2*pi]的長度

 print("二維曲線長度:{:.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 = [] # 存儲每一微小步長的曲線長度

 for i in range(1,len(t)):
  # 計算每一微小步長的曲線長度,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 ) 
  # 將計算結果存儲起來
  area_list.append(dl_i)

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

 print("三維空間曲線長度:{:.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)

得到結果:

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

python微元法計算函數(shù)曲線長度

python微元法計算函數(shù)曲線長度

python微元法計算函數(shù)曲線長度

python微元法計算函數(shù)曲線長度

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

您可能感興趣的文章:

相關文章

最新評論

松桃| 黄浦区| 桑植县| 福泉市| 沭阳县| 安平县| 理塘县| 平利县| 东源县| 连城县| 余庆县| 盈江县| 沙坪坝区| 巩留县| 儋州市| 阳新县| 黄山市| 云龙县| 门源| 嘉鱼县| 襄垣县| 远安县| 康保县| 磐石市| 犍为县| 雷山县| 股票| 潍坊市| 济宁市| 常德市| 安图县| 金寨县| 宁海县| 邹城市| 勃利县| 宁安市| 兴隆县| 黄陵县| 孝昌县| 渭南市| 安远县|