function trychebyshev2(n,t0,t1)% use first n Chebyshev polinomial to approximate % t0:lower boundary; t1: upper boundary A=zeros(n,n); h=t0:(t1-t0)/n:t1; t=h(2:end); for j=1:n-1 for i=1:n A(j,i)=chebT(i,t(j))-chebQ(i,t(j)); % the differential equation is y'=y, y(0)=1 end end for i=1:n A(n,i)=chebT(i,0); end B=zeros(n,1); B(n)=1; x=linsolve(A,B); z=0:0.05:1; f1=0; for i=1:n f1=f1+x(i)*chebT(i,z); end f2=exp(z); plot(z,f1,'r',z,f2,'b');
function y=chebT(n,x) y=cos(n.*acos(x));
function y=chebQ(n,x) y=sin(n.*acos(x)).*n./sqrt(1-x.^2);