zhe41223118/cp2023

  • Home
    • SMap
    • reveal
    • blog
  • About
  • w15
    • try Do
    • ANS 1
    • ANS 2
  • w13
    • step 1
    • step 2
    • step 3
    • bad
  • w12
  • w11
  • w8
  • w7
    • Hello
    • Hello 迴圈與重複
    • Hellogd2
    • korea
  • w4-w5
    • INFO
    • mass-spring-damper
    • Euler Method
  • replit
    • part 1
    • part 2
    • part 3
  • set wifi
  • work
  • program
  • file
  • w17
  • Brython
mass-spring-damper << Previous Next >> replit

Euler Method

參考來源:歐拉方法

數值分析相關資料:

歐拉法(Euler's Method)是一種用於數值解常微分方程(ODEs)的基本數值分析方法。該方法由Leonhard Euler提出,被廣泛應用於解析度較差的情況下的ODEs,尤其是當找不到解析解時。

歐拉法的基本思想:

  1. 離散化: 將自變量(通常是時間)劃分成小的步長。
  2. 近似: 使用當前的微分值(斜率)來估計下一個時間步長的函數值。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
def euler_method(f, y0, t0, tn, h):
    """
    使用歐拉法進行數值積分
 
    Parameters:
    - f: 函數 f(t, y) 表示 ODE 的右側
    - y0: 初值
    - t0: 初始時間
    - tn: 終止時間
    - h: 步長
 
    Returns:
    - t_values: 時間值的列表
    - y_values: 對應的函數值列表
    """
    t_values = [t0]
    y_values = [y0]
    t = t0
    y = y0
 
    while t < tn:
        y = y + h * f(t, y)
        t = t + h
        t_values.append(t)
        y_values.append(y)
 
    return t_values, y_values

mass-spring-damper << Previous Next >> replit

Copyright © All rights reserved | This template is made with by Colorlib