function [ ibc, tol, ul, ur, xl, xn, xr ] = init ( n ) %% INIT initializes some parameters that define the problem. % % Modified: % % 06 November 2006 % % Parameters: % % Input, integer N % The number of subintervals into which the interval % [XL,XR] is broken. % % 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, real TOL. % A tolerance that is used to determine whether the estimated % error in an interval is so large that it should be subdivided % and the problem solved again. % % 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 XN(0:N). % XN(I) is the location of the I-th node. XN(0) is XL, % and XN(N) is XR. % % Output, real XR. % XR is the right endpoint of the interval over which the % differential equation is being solved. % tol = 0.01; % % Find out which problem we're working on. % problem = get_problem ( 'DUMMY' ); % % Set the boundary conditions for the problem, and % print out its title. % if ( problem == 1 ) ibc = 3; ul = 0.0; ur = 1.0; xl = 0.0; xr = 1.0; fprintf ( 1, '\n' ); fprintf ( 1, 'Exact solution is U = X\n' ); elseif ( problem == 2 ) ibc = 3; ul = 0.0; ur = 1.0; xl = 0.0; xr = 1.0; fprintf ( 1, '\n' ); fprintf ( 1, 'Exact solution is U = X*X\n' ); elseif ( problem == 3 ) ibc = 3; ul = 0.0; ur = 1.0; xl = 0.0; xr = 1.0; fprintf ( 1, '\n' ); fprintf ( 1, 'Exact solution is U = SIN(PI*X/2)\n' ); elseif ( problem == 4 ) ibc = 3; ul = 1.0; ur = 0.0; xl = 0.0; xr = 1.0; fprintf ( 1, '\n' ); fprintf ( 1, 'Exact solution is U = COS(PI*X/2)\n' ); elseif ( problem == 5 ) ibc = 3; beta = get_beta ( 'DUMMY' ); ul = 0.0; ur = 1.0 / ( ( beta + 2.0 ) * ( beta + 1.0 ) ); xl = 0.0; xr = 1.0; fprintf ( 1, '\n' ); fprintf ( 1, 'Rheinboldt problem\n' ); elseif ( problem == 6 ) ibc = 3; alpha = get_alpha ( 'DUMMY' ); xl = 0.0; xr = 1.0; ul = uexact ( xl ); ur = uexact ( xr ); fprintf ( 1, '\n' ); fprintf ( 1, 'Arctangent problem\n' ); end % % The nodes are defined here, and not in the geometry routine. % This is because each new iteration chooses the location % of the new nodes in a special way. % for i = 0 : n xn(i+1) = ( ( n - i ) * xl ... + ( i ) * xr ) ... / ( n ); end fprintf ( 1, 'The equation is to be solved for\n' ); fprintf ( 1, 'X greater than %f\n', xl ); fprintf ( 1, ' and less than %f\n', 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