資源描述:
《matlab上機實驗報告二》由會員上傳分享,免費在線閱讀,更多相關內容在工程資料-天天文庫。
1、MATLAB上機實驗報告(二)學號:2015020902024姓名:蘭雪剛一.實驗題目1.對高階多項式20p(x)=(x_l)(x_2)???(x_20)=口(兀_£)k=編程求下面方程的解p(兀)+亦囚=0并繪圖演示方程的解與擾動量£的關系。2.對n二2,???,20,生成對應的Hilbert矩陣,計算矩陣的條件數(shù);通過先確定解獲得常向量b的方法,確定方程組H“(x)=b最后,用矩陣分解方法求解方程組,并分析計算結果。3.對函數(shù)11+257的Chebyshev點2(〃+1)(2R-1)龍編程進行Lagrange插值,并分析插值結果。二.實驗程序1-P=[VH;fo
2、ri=2:20%求多項式乘積%m的最高次幕為20,有21項n=[l,-i];p=conv(p,n);endm=zeros(l,21);holdonx=l:20;d=[-l,0,0.1,0.5,1];fori=l:5delt=d(i);m(2)=delt;y=(roots(p+m))';%求多項式的根plot(x,y/-o:'color:[i/5,i/20,i/10]);endtitle/方程p(x)=0的解與擾動量delt的關系Jlegend(,delt=-l,;delt=0,;delt=0.1,;delt=0.5,;delt=l,)2.clearallforn=2:
3、20h=hilb(n);fprintf('n=%-10dcond(Hn)00=%d',n,cond(h/inf,))%cond:求矩陣范數(shù)X=l:n;b=h*X*;[1u]=lu(h);x=u(lb);x=x‘;%lu分解%利用lu分解求線性英次方程組的根fprintf(*2)fori=l:nfprintf(%?8.2什X(i))endfprintf(*/=*)fori=l:nfprintf(%-8.2f:x(i))endend3.函數(shù):functiony=lagrange(X"x)n=length(X);m=length(x);fori=l:ms
4、=0;fork=l:n1=1;forj=l:nifj~=kl=l*(x(i)-X(j))/(X(k)-X(j));endends=l*Y(k)+s;endy(i)=s;endend主程序:clearallf=inline(,l./(l+25*x.A2)');g=inlineCcos((2*k-l)*pi/(2*(n+l))),;k,;n,);%創(chuàng)建局部函數(shù)x=linspace(?lj);n=length(x);y二f(x);plot(x,y);holdonaxis(卜1.1,1.1,02,1.1])forn=l:2:9;k=n+l;fori=l:kX(i)=g(i,n
5、);Y(i)=f(X(i));endy=lagrange(X^x);plot(XY'o')plot(x,y,’color:],n/10,n/15]);endtitlefChebyshev點的Lagrange插值(n=1:2:9)')legendCf(x)=l/(l+25xA2)';n越大,Ln(O)越接近f(0)')一.實驗結果Figure」Fi-eEditView3sertToo-SDesktopwindowHe-P8.50.40,00del-irJLde-^odag」ddt=0.5ddH65LOO-1.00cond(Hn)?>=2.700000e+012.002.
6、00cond(Hn)=7.480000e+022.003.002.003.00LOO=1.00cond(Hn)=2.837500e+042.003.004.002.003.004.00n=5cond(Hn)=9.436560e+05X'=1.002.003.004.005.00=LOO2.003.004.005.00n=6cond(Hn)°°=2.907028e+07X'=1.002.003.004.005.00&OO=1.002.003.004.005.006.00n=7cond(Hn)?9.851949e+08n-13ccnd(fti)^70334
7、861&824187136X^-l.OO2.001004.005.00x*-LOO2.003.004.481.3010.0011.0012.00-41.1162.2013.0010.80Tannni:fatrixisdosetosinfuluorbtdlyscaled.ResultsuybelnKcuiite.ROUD?9.7<4781e-li.X,=1-002.003.004.005.006.007.00X*=1.002.003.004.005.006.007.00n=8cond(Hn)8=3.:387279e+10:c=1.002.003.004