function output ( f, ibc, indx, n, nu, ul, ur, xn ) %% OUTPUT prints out the computed solution. % % Modified: % % 06 November 2006 % % Parameters: % % Input, real F(NU). % ASSEMBLE stores into F the right hand side of the linear % equations. % SOLVE replaces those values of F by the solution of the % linear equations. % % Input, integer IBC. % IBC declares what the boundary conditions are. % 1, at the left endpoint, U has the value UL, % at the right endpoint, U' has the value UR. % 2, at the left endpoint, U' has the value UL, % at the right endpoint, U has the value UR. % 3, at the left endpoint, U has the value UL, % and at the right endpoint, U has the value UR. % 4, at the left endpoint, U' has the value UL, % at the right endpoint U' has the value UR. % % Input, integer INDX(0:N). % For a node I, INDX(I) is the index of the unknown % associated with node I. % If INDX(I) is equal to -1, then no unknown is associated % with the node, because a boundary condition fixing the % value of U has been applied at the node instead. % Unknowns are numbered beginning with 1. % If IBC is 2 or 4, then there is an unknown value of U % at node 0, which will be unknown number 1. Otherwise, % unknown number 1 will be associated with node 1. % If IBC is 1 or 4, then there is an unknown value of U % at node N, which will be unknown N or N+1, % depending on whether there was an unknown at node 0. % % Input, integer N % The number of subintervals into which the interval % [XL,XR] is broken. % % Input, integer NU. % NU is the number of unknowns in the linear system. % Depending on the value of IBC, there will be N-1, % N, or N+1 unknown values, which are the coefficients % of basis functions. % % Input, real UL. % If IBC is 1 or 3, UL is the value that U is required % to have at X = XL. % If IBC is 2 or 4, UL is the value that U' is required % to have at X = XL. % % Input, real UR. % If IBC is 2 or 3, UR is the value that U is required % to have at X = XR. % If IBC is 1 or 4, UR is the value that U' is required % to have at X = XR. % % Input, real XN(0:N). % XN(I) is the location of the I-th node. XN(0) is XL, % and XN(N) is XR. % fprintf ( 1, '\n' ); fprintf ( 1, 'Node X(I) U(X(I)) Uexact Error\n' ); fprintf ( 1, '\n' ); for i = 0 : n if ( i == 0 ) if ( ibc == 1 | ibc == 3 ) u = ul; else u = f(indx(i+1)); end elseif ( i == n ) if ( ibc == 2 | ibc == 3 ) u = ur; else u = f(indx(i+1)); end else u = f(indx(i+1)); end uex = uexact ( xn(i+1) ); error = u - uex; fprintf ( 1, ' %4d %12f %12f %12f %12f\n', i, xn(i+1), u, uex, error ); end