<jupyter_start><jupyter_text>数值微分* 利用中心微分近似计算$f(x)=\exp(x)$在$x=1.5$的一阶导数，步长取0.1, 0.01, 0.001<jupyter_code>import math
def f(x):
    return math.exp(x)

def centerDifferential(x,step=0.1,function=f):
    return (function(x+step)-function(x-step))/2/step
a1=centerDifferential(1.5,step=0.1  )
a2=centerDifferential(1.5,step=0.01 )
a3=centerDifferential(1.5,step=0.001)

print(a1)
print(a2)
print(a3)<jupyter_output>4.489162287752202
4.481763765529401
4.481689817286139<jupyter_text>* 将结果与精确解$f'(1.5)=\exp(1.5)$进行比较，分析误差随着步长的变化以及理论依据。<jupyter_code>standard=math.exp(1.5)
print("standard")
print(standard)

print("error")
print(a1-standard)
print(a2-standard)
print(a3-standard)<jupyter_output>standard
4.4816890703380645
error
0.007473217414137423
7.469519133618263e-05
7.469480740596168e-07
{'fraction_non_alphanumeric': 0.16751269035532995, 'fraction_numerical': 0.20812182741116753, 'mean_word_length': 8.74074074074074, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '458981', 'license': 'MIT', 'n_tokens_mistral': 486, 'n_tokens_neox': 425, 'n_words': 33, 'path': '4_Differential.ipynb', 'repo_name': 'ShawHaines/ComputationalPhysics', 'size': '788'}