function [ ibc, imax, nprint, nquad, problem, ul, ur, xl, xr ] = init ( dummy ) %% INIT initializes variables that define the problem. % % Modified: % % 01 November 2006 % % Parameters: % % Output, 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. % % Output, integer IMAX. % The number of Newton iterations to carry out. % % Output, integer NPRINT. % The number of points at which the computed solution % should be printed out when compared to the exact solution. % % Output, integer NQUAD. % The number of quadrature points used in a subinterval. % This code uses NQUAD = 1. % % Output, integer PROBLEM, indicates which problem to be solved. % * 1, u = x, p=1, q=0, f=x, u(0)=0, u'(1)=1. % * 2, u = 2*(1-cos(0.5*pi*x))/pi, p=1, q=0, % f = -0.5*pi*cos(0.5*pi*x) + 2*sin(0.5*pi*x)*(1-cos(0.5*pi*x)/pi % u(0) = 0, u'(1)=1. % % Output, 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. % % Output, 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. % % Output, real XL. % XL is the left endpoint of the interval over which the % differential equation is being solved. % % Output, real XR. % XR is the right endpoint of the interval over which the % differential equation is being solved. % ibc = 1; imax = 20; nprint = 9; nquad = 1; problem = 1; ul = 0.0; ur = 1.0; xl = 0.0; xr = 1.0; % % Print out the values that have been set. % fprintf ( 1, '\n' ); fprintf ( 1, 'The equation is to be solved for\n' ); fprintf ( 1, 'X greater than XL = ', xl ); fprintf ( 1, ' and less than XR = ', xr ); fprintf ( 1, '\n' ); fprintf ( 1, 'The boundary conditions are:\n' ); fprintf ( 1, '\n' ); if ( ibc == 1 | ibc == 3 ) fprintf ( 1, ' At X = XL, U = %f\n', ul ); else fprintf ( 1, ' At X = XL, U'' = %f\n', ul ); end if ( ibc == 2 | ibc == 3 ) fprintf ( 1, ' At X = XR, U = %f\n', ur ); else fprintf ( 1, ' At X = XR, U'' = %f\n', ur ); end if ( problem == 1 ) fprintf ( 1, '\n' ); fprintf ( 1, ' This is test problem #1:\n' ); fprintf ( 1, '\n' ); fprintf ( 1, ' P(X) = 1, Q(X) = 0, F(X) = X.\n' ); fprintf ( 1, ' Boundary conditions: U(0) = 0, U''(1) = 1.\n' ); fprintf ( 1, '\n' ); fprintf ( 1, ' The exact solution is U(X) = X\n' ); elseif ( problem == 2 ) fprintf ( 1, '\n' ); fprintf ( 1, ' This is test problem #2:\n' ); fprintf ( 1, '\n' ); fprintf ( 1, ' P(X) = 1, Q(X) = 0, \n' ); fprintf ( 1, ' F(X) = -0.5*pi*cos(0.5*pi*X)\n' ); fprintf ( 1, ' + 2*sin(0.5*pi*X)*(1-cos(0.5*pi*X)/pi.\n' ); fprintf ( 1, ' Boundary conditions: U(0) = 0, U''(1) = 1.\n' ); fprintf ( 1, '\n' ); fprintf ( 1, ' The exact solution is U(X) = 2*(1-cos(pi*x/2))/pi\n' ); end fprintf ( 1, '\n' ); fprintf ( 1, 'Number of quadrature points per element is %d\n', nquad ); fprintf ( 1, 'Number of iterations is %d\n', imax );