CS计算机代考程序代写 matlab clear all
clear all Npoints=50; alpha = 5; %BC1 y(x=-1)=5 beta = 3; %BC2 y(x=1)=3 %xpoints=linspace(-1,1,Npoints)’; [xpoints,w,P]=lglnodes(Npoints); xpoints=-xpoints; tpoints=(xpoints+3)/2; y = @(t) t+4./t.^2; yexact = y(tpoints); n=length(xpoints)-1; %order of polynomial D=DerivMatrix(xpoints,n); D2 = D*D; A=D2+diag(2./(xpoints+3))*D-diag(2./(xpoints+3).^2); Amatrix=A(2:end-1,2:end-1); Cvector=-alpha*A(2:end-1,1)-beta*A(2:end-1,end); sol = Amatrix\Cvector; yapprox = [alpha;sol;beta]; hold off plot(tpoints,yapprox,’bo’) hold on plot(tpoints,yexact,’k-‘) xlabel(‘t’);ylabel(‘y’); function D=DerivMatrix(x,n) D=zeros(n+1,n+1); for i=1:n+1 num(i)=1.0; for […]
CS计算机代考程序代写 matlab clear all Read More »