% This script finds the PS solution of the % linear 2-point BVP with non-homogeneous boundary conditions of the form % y''(t) = exp(4*y(t)) % with BCs y'(-1) = 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]) %%%% exact solution tt = linspace(-1,1,101); exact = ( exp(4*tt) - 4*exp(-4)*(tt-1) - exp(4) )/16; N = 16; [D,t] = cheb(N); D2 = D^2; D2(N+1,:) = D(N+1,:); % to impose derivative boundary condition D2 = D2(2:N+1,2:N+1); % delete first row/col due to homogeneous BC y = D2\[exp(4*t(2:N)); 0]; y = [0; y]; % add homogeneous BC-value plot(t,y,'.','markersize',16) yy = polyval(polyfit(t,y,N),tt); % interpolate grid data line(tt,yy) title([num2str(N+1) ' point PS: max err = ' num2str(norm(yy-exact,inf))],'fontsize',12)