function [ u, h, nu ] = solvex ( ibc, kount, n, nl, nmax, ul, ur, xn ) %% SOLVEX discretizes and solves a differential equation given the nodes. % % Modified: % % 05 November 2006 % % Parameters: % % 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 KOUNT, the number of adaptive steps that have been taken. % % Input, integer N % The number of subintervals into which the interval % [XL,XR] is broken. % % Input, integer NL. % The number of basis functions used in a single % subinterval. (NL-1) is the degree of the polynomials % used. For this code, NL is fixed at 2, meaning that % piecewise linear functions are used as the basis. % % Input, integer NMAX, the maximum number of unknowns that can be handled. % % 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. % % Output, real U(NU), the finite element coefficients of the % solution of the differential equation. % % Output, real H(N) % H(I) is the length of subinterval I. This code uses % equal spacing for all the subintervals. % % Output, 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. % % Local parameters: % % Local, real ADIAG(NU). % ADIAG(I) is the "diagonal" coefficient of the I-th % equation in the linear system. That is, ADIAG(I) is % the coefficient of the I-th unknown in the I-th equation. % % Local, real ALEFT(NU). % ALEFT(I) is the "left hand" coefficient of the I-th % equation in the linear system. That is, ALEFT(I) is the % coefficient of the (I-1)-th unknown in the I-th equation. % There is no value in ALEFT(1), since the first equation % does not refer to a "0-th" unknown. % % Local, real ARITE(NU). % ARITE(I) is the "right hand" coefficient of the I-th % equation in the linear system. ARITE(I) is the coefficient % of the (I+1)-th unknown in the I-th equation. There is % no value in ARITE(NU) because the NU-th equation does not % refer to an "NU+1"-th unknown. % % Local, 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. % % Local, integer NODE(NL,N). % For each subinterval I: % NODE(1,I) is the number of the left node, and % NODE(2,I) is the number of the right node. % % Local, integer NQUAD % The number of quadrature points used in a subinterval. % % Local, real WQUAD(NQUAD). % WQUAD(I) is the weight associated with the I-th point % of an NQUAD point Gaussian quadrature rule. % % Local, real XQUAD(NQUAD,NMAX), the I-th quadrature point % in interval J. % nquad = 2; % % Given a set of N nodes (where N increases on each iteration), % compute the other geometric information. % [ h, indx, node, nu, wquad, xquad ] = geometry ( ibc, n, nl, nmax, nquad, xn ); % % Assemble the linear system. % [ adiag, aleft, arite, f ] = assemble ( h, n, indx, node, nu, nl, ... nquad, nmax, ul, ur, wquad, xn, xquad ); % % Print out the linear system, just once. % if ( kount == 1 ) prsys ( adiag, aleft, arite, f, nu ); end % % Solve the linear system. % u = solve ( adiag, aleft, arite, f, nu ); % % Print out the solution. % fprintf ( 1, '\n' ); fprintf ( 1, 'Basic solution\n' ); output ( u, ibc, indx, n, nu, ul, ur, xn );