function [M] = V_cycle(M,n1,n2) %======================================================== % Solve the cauchy schwartz equations using a V-cycle % This is a recursive algorithm based on cycles in which a fine grid equation % is solved on a coarse grid. % (n1,n2) - are the number of sweeps to preform in the algorithm before and after the recrusion %===================================================================== %===================================================================== for k = 1:1 s = size(M) ; rows = s(1) ; cols = s(2); n = rows-1; h = 1/n; %===================================================================== % n1 sweeps of Relaxation giving an approximation U_tild returning % the residual %===================================================================== for i = 1:n1 M = relax_F(M,n); M = relax_G(M,n); end %Give some estimation to the distance from the solution %In previous work this was preformed by |%R_h = F - laplacian(U_h); % |%norma = norm(R_h(:),2)*h; % need to multiply by h to compare the convergence in the V-cycle %===================================================================== % Coarse to fine residual transfer with full-weighting %===================================================================== % Calculate the residual to solve over the coarser grid and: % Trasfer the F,G with full weighting and the U,V boundaries are zero M_2h = downscale(M); %===================================================================== % Solve for the residual on the coarse grid %===================================================================== new_rows = (rows-1)/2 + 1; new_cols = (cols-1)/2 + 1; if (new_rows <=5) new_rows; M_2h = solve_direct(M_2h); else M_2h = V_cycle(M_2h,n1,n2); end %===================================================================== % Interpolate back to the fine grid and correct the former approx %===================================================================== M_new = upscale(M_2h); % The U,V for the error interpolated to the fine grid (boundaries are zeroed) M = M + M_new; %eval_error(M) %===================================================================== % Additional n2 relaxation sweeps %===================================================================== for i = 1:n2 M = relax_F(M,n); M = relax_G(M,n); end %===================================================================== end %Give some estimation to the distance from the solution %In previous work this was preformed by |%R_h = F - laplacian(U_h); % |%norma = norm(R_h(:),2)*h; % need to multiply by h to compare the convergence in the V-cycle