User:Eml5526.s11.team2.stewart/HW3

clear all; clc; format long syms x Uh; U = -118/27*log((2+3*x)/5) + (20*x-15*x^2+139)/36; % Exact Solution m = 2;                                            % Global Equidistant Nodes d_0 = 4; x_m = zeros(m); for i=1:m x_m(i)=(i-1)/(m-1); end

% Basis Function Vector b_i = sym(ones(m,1)); for i=1:m for j=1:m b_i(i)=(x-1)^(i); end end

% Construct K and F Kff=ones(m,m); Ff=ones(m,1); for i=1:m for j=1:m Kff(i,j)=int(diff(b_i(i))*(2+3*x)*diff(b_i(j)),0,1); end Ff(i)=int(b_i(i)*5*x,0,1) + subs((12+18*x)*b_i(i),x,0); end

d = zeros(m,1); Kff            % Lazy way of displaying Kff Ff             % Lazy way of displaying Ff d = Kff\Ff;     % Solve for d i=1,2,...,m d = [d_0;d]    % Prepend d_0 b_i = [1;b_i]  % Prepend b_0

Uh = d'*b_i    % This come out simplified with fractions. % You can just look at b_i and d to write out Uh