elif i == 0 and j == 1: return 1 elif i == 1 and j == 0: return 0 elif i == 1 and j == 1: return 1 raise ValueError("Wrong i, j (i=%d, j=%d)." % (i, j)) d.define_ode(F, DFDY) d.assign_dofs() Y = zeros(d.ndofs) J = d.assemble_J(Y) error = 1e10 i = 0 while error > 1e-10: F = d.assemble_F(Y) dY = d.solve(J, F) error = d.calculate_error_l2_norm(dY) print "it=%d, l2_norm=%e" % (i, error) Y += dY i += 1 x = Y from pylab import plot, legend, show sln1, sln2 = d.linearize(x, 5) x1, y1 = sln1 x2, y2 = sln2 plot(x1, y1, label="$u_1$") plot(x2, y2, label="$u_2$") legend() show()
raise ValueError("Wrong i, j (i=%d, j=%d)." % (i, j)) # assign both F and J to the discrete problem: d.define_ode(F, DFDY) # enumeration of unknowns: d.assign_dofs() # definition of the initial condition for the global Newton method: Y = d.get_initial_condition_euler() #plot_Y(Y, a, b) #stop #Y = zeros((d.ndofs,)) # Newton's iteration: error = 1e10 i = 0 J = d.assemble_J(Y) while error > 1e-5: F = d.assemble_F(Y) dY = d.solve(J, F) Y += dY #plot_Y(Y, a, b) error_dY = d.calculate_error_l2_norm(dY) error_F = d.calculate_error_l2_norm(d.assemble_F(Y)) print "it=%d, l2_norm_dY=%e, l2_norm_F=%e" % (i, error_dY, error_F) error = max(error_dY, error_F) i += 1 plot_Y(Y, a, b)