args = "x,y,z" # really sloppy handling, use argparse if len(sys.argv) > 1: try: N = int(sys.argv[1]) except: raise Exception("argument must be an integer N (partition size in RK4)") else: N = 4 # just set verbosity based on size of N v = (N < 5) x0 = np.array([[1,1,1]]).T x_sol = cm_rk4(case_one, args, x0, N, verbose=v) # now just do some data F, X = parse_symbolic(case_one, args) # get F value at x* F1 = F.subs(list(zip(X, x_sol))) err = F1.norm() # wow, these methods are great print("||F(x*)|| = ", err) x_check = nsolve(F, X, (1,1,1)) print("solution according to sympy.solvers.nsolve:") print(x_check.T)
#!/usr/bin/env python3 import numpy as np from newtons_for_systems import solve_nonlinear_system from continuation import cm_rk4 system = ["4*x1^2 - 20*x1 + (1/4)*x2^2 + 8", "(1/2)*x1*x2^2 + 2*x1 - 5*x2 + 8"] args = "x1, x2" x0 = np.array([[0,0]]).T print("newton's method (one iteration)") x_a = solve_nonlinear_system(system, args, x0, M=1) print("(newton's method):", x_a.T) print("*"*40) print("continuation method (one iteration)") x_c = cm_rk4(system, args, x0, N=1, verbose=False) print("x^(1) = ", x_c.T)