34 lines
779 B
Python
34 lines
779 B
Python
import numpy as np
|
|
|
|
f_m = 0.2
|
|
f_c = 2*f_m
|
|
A_c = 1
|
|
a = 1
|
|
|
|
def g(t):
|
|
return A_c*np.cos(2*np.pi*f_m*t) + A_c*np.cos(2*np.pi*f_c*t)
|
|
|
|
# first derivative of g(t)
|
|
def dg_dt(t):
|
|
return -(2*np.pi*f_m)*A_c*np.sin(2*np.pi*f_m*t) + -(2*np.pi*f_c)*A_c*np.sin(2*np.pi*f_c*t)
|
|
|
|
# second derivative of g(t)
|
|
def ddg_dtt(t):
|
|
return -(2*np.pi*f_m)**2*A_c*np.cos(2*np.pi*f_m*t) + -(2*np.pi*f_c)**2*A_c*np.cos(2*np.pi*f_c*t)
|
|
|
|
# use Newton's method to find the maximum of the function
|
|
def newton_method(t):
|
|
for i in range(3):
|
|
t = t - dg_dt(t)/ddg_dtt(t)
|
|
print(f"Iteration {i+1}: {t}\t{g(t)}")
|
|
|
|
def dc_dt(t):
|
|
return A_c*a*np.pi*f_c*np.cos(2*np.pi*f_c*t)
|
|
|
|
if __name__ == '__main__':
|
|
T_c = 1/f_c
|
|
t_min = T_c/2
|
|
newton_method(t_min)
|
|
|
|
newton_method(0)
|