% This script uses fixed-point iteration to find the PS solution of the % nonlinear 2-point BVP of the form % y''(t) = exp(y(t)) % with BCs y(-1) = 0, y(1) = 0 % PS code based on Trefethen: Spectral Methods in Matlab clear all clc close all warning off scrnsz = get(0, 'Screensize'); figure('Position', [5 10 scrnsz(3)-5 scrnsz(4)-60]) for N = 2:2:40 [D,t] = cheb(N); D2 = D^2; D2 = D2(2:N,2:N); y = zeros(N-1,1); change = 1; it = 0; while change > 1e-15 % fixed-point iteration ynew = D2\exp(y); change = norm(ynew-y,inf); y = ynew; it = it+1; end y = [0;y;0]; % take care of boundary conditions clf, subplot('position',[.1 .4 .8 .5]) plot(t,y,'.','markersize',16) tt = -1:.01:1; yy = polyval(polyfit(t,y,N),tt); line(tt,yy), grid on title(sprintf('Using %d points. No. steps = %d y(0) =%18.14f',N+1,it,y(N/2+1))) pause end