function [tp,yp] = colloc3(x0); % % function [t,y] = colloc3(x0); % % Solves the modified Euler buckling problem % from page 3.65 with the collocation method. % The Newton iteration starts at the column % vector x0. % global LAMBDA; Np = 1000; errtol = 1.0e-12; n = length(x0); h = pi / (n+1); t = linspace(h,pi-h,n); tp = linspace(0,pi,Np); % Create the collocation matrix from y'', and the auxiliary matrix B A = zeros(n,n); B = zeros(n,n); for l=1:n for k=1:n A(l,k) = -k*k*cos(k*t(l)); B(l,k) = cos(k*t(l)); end; end; % Start the Newton iteration it = 0; x = x0; delx = x; while norm(delx)>errtol it = it + 1; F = A*x + LAMBDA * sin(B*x); DF = A + LAMBDA * (diag(cos(B*x)) * B); delx = DF \ (-F); x = x + delx; end; fprintf('\n'); fprintf('Converged in %d iterations!\n\n',it); yp = 0.0 * tp; for k=1:n yp = yp + x(k)*cos(k*tp); end;