import numpy as np import general_newton as gn import test_fun as tf # create grid of complex numbers re_lim = [-0.2, 0.2] re_num = 1000 im_lim = [-0.2, 0.2] im_num = 1000 Z = gn.complex_grid(re_lim, re_num, im_lim, im_num) # generate rational functions p = np.array([1.0, 0.0, -2.0, 2.0]) q = np.array([2, 0, -10]) dp = tf.poly_der(p) dq = tf.poly_der(q) params = {'p': p, 'dp': dp, 'q': q, 'dq': dq} f_val = tf.poly_fun df_val = tf.d_poly_fun max_iter = 50 # run newton's method roots, con_root, con_num = gn.newton_method(Z, f_val, df_val, params, max_iter=max_iter) # print computed roots print "Computed " + str(len(roots)) + " roots of " + f_val.__name__
import numpy as np import general_newton as gn import test_fun as tf # create grid of complex numbers re_lim = [-0.2, 0.2] re_num = 1000 im_lim = [-0.2, 0.2] im_num = 1000 Z = gn.complex_grid(re_lim, re_num, im_lim, im_num) # generate rational functions p = np.array([1.0, 0.0, -2.0, 2.0]) q = np.array([2, 0, -10]) dp = tf.poly_der(p) dq = tf.poly_der(q) params = {'p': p, 'dp': dp, 'q':q, 'dq':dq} f_val = tf.poly_fun df_val = tf.d_poly_fun max_iter = 50 # run newton's method roots, con_root, con_num = gn.newton_method(Z, f_val, df_val, params, max_iter=max_iter) # print computed roots print "Computed " + str(len(roots)) + " roots of " + f_val.__name__ if len(roots) < 8: for root in roots: print "%.4f \t+\t%.4fi" %(root.real, root.imag)
if not os.path.exists(directory): os.makedirs(directory) else: shutil.rmtree(directory) os.makedirs(directory) # create grid of complex numbers re_lim = [-5, 5] re_num = 1000 im_lim = [-5, 5] im_num = 1000 Z = gn.complex_grid(re_lim, re_num, im_lim, im_num) # generate polynomial functions p = [1.0, 0.0, -2.0, 2.0] dp = tf.poly_der(p) params = {'p': p, 'dp': dp} f_val = tf.poly_fun df_val = tf.d_poly_fun known_roots = np.roots(p) # frame parameters vid_len = 5 # length of gif frame_ps = 18 # number of frames per second quality = 22 # the quality of the encoding # colors colors = [(0, 255, 255), (128, 128, 255), (255, 0, 255), (255, 128, 128)] # generalized newton parameter, a a_seq = np.linspace(1.5, 0.6, 600)
# get parameterized roots speeds = np.array([1,4,1,4]) num_times = vid_len * frame_ps param_roots = tf.parameterized_roots1(speeds, num_times) max_iter = 50 # create image sequence for i in range(num_times): # print progress img_file_name = directory + '/' + imagename + '%05d' % (i+1) + '.png' print 'Creating frame ' + str(i+1) + ' of ' + str(num_times) # create polynomial from roots known_roots = param_roots[i,:] p = np.flipud(poly.polyfromroots(known_roots)) dp = tf.poly_der(p) # update param dictionary params['p'] = p params['dp'] = dp # newton's method roots, con_root, con_num = gn.newton_method(Z, f_val, df_val, params, disp_time=False, known_roots=known_roots, max_iter = max_iter) # create image in folder gn.newton_plot(con_root, con_num, colors, save_path=img_file_name, max_shade=max_iter) # create the movie ctrlStr = 'ffmpeg -r %d -i %s%%05d.png -c:v libx264 -preset slow -crf %d %s' %(frame_ps, directory + '/' + imagename, quality, filename) subprocess.call(ctrlStr, shell=True)