#1.1
#f(x)=e^-x
from math import e
f1x = (e**(-1.001)-e*-0.999)/0.002
def f1x(x,h):
return (e**(x+h)-e**(x-h))/(2*h)
f1x(1,0.001)
#output 2.718282281505946
#1.2
#f(x)=sin(x)e^(-cos(x))
from math import sin,cos,e
def fsinx(x,h):
return ((sin(x+h)*e**(-cos(x+h)))-((sin(x-h)*e**(-cos(x-h)))))/(2*h)
def fsinx_1():
return ((sin(1+0.001)*e**(-cos(1+0.001)))-((sin(1-0.001)*e**(-cos(1-0.001)))))/(2*0.001)
fsinx(1,0.001)
fsinx_1()
#output 0.7272689097917728
#จงเขียนฟังก์ชันเพื่อแสดงตารางค่าความสัมพันธ์ระหว่าง h กับ ค่า First CDA ของฟังก์ชันต่างๆในข้อ 1. เมื่อกำหนด x=1 และ h=[0.64,0.32,0.16,0.08,0.04,0.02,0.01,0.005,0.0025,0.00125]
def fx(x,h):
return [((sin(x+h[i])*e**(-cos(x+h[i])))-((sin(x-h[i])*e**(-cos(x-h[i])))))/(2*h[i]) for i in range(0,10)]
h=[0.64,0.32,0.16,0.08,0.04,0.02,0.01,0.005,0.0025,0.00125]
fx(1,h)
#output [0.7272315407770419,
# 0.7294856916511139,
# 0.7279664514641956,
# 0.7274522897769059,
# 0.7273152972988396,
# 0.7272805201077245,
# 0.7272717927303579,
# 0.7272696088183261,
# 0.7272690627111111,
# 0.7272689261761833]
-
Kittipong Maneewong authoredb5a5dfeb