%%% Example of how the symbolic toolbox %%% can save you time evaluating integrals. syms t; int('t^2*exp(t)',-1,1) %definite integral on [-1,1] %%% computing f_3 = proj_W(f) when %%% W = space of all polynomials of degree <= 2 defined on [-1,1] %%% and f(x) = exp(x) G = [ 2 0 2/3 0 2/3 0 2/3 0 2/5]; %%% Gram matrix for non-orthogonal basis %%% {1, x, x^2} (computed previously by hand, %%% or with symbolic toolbox) syms e %%% choose this if you want an exact expression of c %e = exp(1); %%% choose this if you want plots b = [e - 1/e 2/e e - 5/e]; %%% b(i) = (f,phi_i), where phi_i(x) = x^(i-1) c = G\b x = linspace(-1,1,200)'; f3 = c(1)*ones(size(x)) + c(2)*x + c(3)*x.^2; plot(x,[exp(x),f3])