当前位置:文档之家› MATLAB第二次上机实验报告

MATLAB第二次上机实验报告

电子科技大学电子工程学院标准实验报告(实验)课程名称MATLAB与数值分析学生姓名:学号:指导教师:一、实验名称实验二 线性方程组求解和函数的数值逼近二、实验目的通过上机实验,使学生对病态问题、线性方程组求解和函数的数值逼近方法有一个初步的理解。

实验涉及的核心知识点:病态方程求解、矩阵分解和方程组求解、Lagrange 插值。

实验重点与难点:算法设计和MATLAB 编程三、实验内容1. 对高阶多项式()()()()()2011220k p x x x x x k ==---=-∏编程求下面方程的解()190p x x ε+=并绘图演示方程的解与扰动量ε的关系。

2. 对220n =,生成对应的Hilbert 矩阵,计算矩阵的条件数;通过先确定解获得常向量b 的方法,确定方程组()n H x b =最后,用矩阵分解方法求解方程组,并分析计算结果。

3. 对函数()21125f x x =+ []1,1x ∈-的Chebyshev 点()()21cos 21k k x n π⎛⎫-= ⎪ ⎪+⎝⎭,1,2,,1k n =+编程进行Lagrange 插值,并分析插值结果。

四、实验数据及结果分析1. 对高阶多项式()()()()()2011220k p x x x x x k ==---=-∏编程求下面方程的解()190p x x ε+=并绘图演示方程的解与扰动量ε的关系。

p=[1,-1]; for i=2:20 n=[1,-i];p=conv(p,n); % 求多项式乘积 endm=zeros(1,21); % m 的最高次幂为20,有21项 hold on x=1:20;d=[-1,0,0.1,0.5,1]; for i=1: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 的关系')legend('delt=-1','delt=0','delt=0.1','delt=0.5','delt=1')24681012141618200102030405060方程p(x)=0的解与扰动量delt 的关系delt=-1delt=0delt=0.1delt=0.5delt=12.对220n =,生成对应的Hilbert 矩阵,计算矩阵的条件数;通过先确定解获得常向量b 的方法,确定方程组()n H x b =最后,用矩阵分解方法求解方程组,并分析计算结果。

for n=2:20 h=hilb(n);fprintf('\n\nn=%-10dcond(Hn)∞=%d',n,cond(h,'inf'))%cond :求矩阵范数X=1:n; b=h*X';[l u]=lu(h); %lu 分解x=u\(l\b); %利用lu 分解求线性其次方程组的根 x=x';fprintf('\n X ’=') for i=1:nfprintf('%-8.2f',X(i)) endfprintf('\n x ’=') for i=1:nfprintf('%-8.2f',x(i)) end end输出结果如下:n=2 cond(Hn)∞=2.700000e+001 X ’=1.00 2.00 x ’=1.00 2.00n=3 cond(Hn)∞=7.480000e+002 X ’=1.00 2.00 3.00 x ’=1.00 2.00 3.00n=4 cond(Hn)∞=2.837500e+004 X ’=1.00 2.00 3.00 4.00 x ’=1.00 2.00 3.00 4.00n=5 cond(Hn)∞=9.436560e+005X ’=1.00 2.00 3.00 4.00 5.00 x ’=1.00 2.00 3.00 4.00 5.00n=6 cond(Hn)∞=2.907028e+007X’=1.00 2.00 3.00 4.00 5.00 6.00x’=1.00 2.00 3.00 4.00 5.00 6.00n=7 cond(Hn)∞=9.851949e+008X’=1.00 2.00 3.00 4.00 5.00 6.00 7.00x’=1.00 2.00 3.00 4.00 5.00 6.00 7.00n=8 cond(Hn)∞=3.387279e+010X’=1.00 2.00 3.00 4.00 5.00 6.00 7.00 8.00x’=1.00 2.00 3.00 4.00 5.00 6.00 7.00 8.00n=9 cond(Hn)∞=1.099652e+012X’=1.00 2.00 3.00 4.00 5.00 6.00 7.00 8.00 9.00x’=1.00 2.00 3.00 4.00 5.00 6.00 7.00 8.00 9.00n=10 cond(Hn)∞=3.535369e+013X’=1.00 2.00 3.00 4.00 5.00 6.00 7.00 8.00 9.00 10.00x’=1.00 2.00 3.00 4.00 5.00 6.00 7.00 8.00 9.00 10.00n=11 cond(Hn)∞=1.229476e+015X’=1.00 2.00 3.00 4.00 5.00 6.00 7.00 8.00 9.00 10.00 11.00x’=1.00 2.00 3.00 4.00 5.00 6.00 7.01 7.99 9.01 10.00 11.00 Warning: Matrix is close to singular or badly scaled.Results may be inaccurate. RCOND = 2.692153e-017.> In cond at 48In Untitled7 at 3n=12 cond(Hn)∞=3.714499e+016X’=1.00 2.00 3.00 4.00 5.00 6.00 7.00 8.00 9.00 10.00 11.00 12.00x’=1.00 2.00 3.00 4.00 5.03 5.87 7.34 7.38 9.72 9.48 11.22 11.96 Warning: Matrix is close to singular or badly scaled.Results may be inaccurate. RCOND = 2.739612e-018.> In cond at 48In Untitled7 at 3n=13 cond(Hn)∞=3.650152e+017X’=1.00 2.00 3.00 4.00 5.00 6.00 7.00 8.00 9.00 10.00 11.00 12.00 13.00x’=1.00 2.00 3.00 4.06 4.50 8.73 -2.56 30.28 -25.84 46.13 -12.84 21.06 11.49 Warning: Matrix is close to singular or badly scaled.Results may be inaccurate. RCOND = 2.448199e-019.> In cond at 48In Untitled7 at 3n=14 cond(Hn)∞=4.084635e+018Warning: Matrix is close to singular or badly scaled.Results may be inaccurate. RCOND = 4.455948e-017.> In Untitled7 at 7X’=1.00 2.00 3.00 4.00 5.00 6.00 7.00 8.00 9.00 10.00 11.00 12.00 13.00 14.00x’=1.00 2.00 2.97 4.44 2.03 15.85 -1.01 -51.32 265.98-505.38 620.05 -421.65 185.67 -15.62 Warning: Matrix is close to singular or badly scaled.Results may be inaccurate. RCOND = 1.024999e-018.> In cond at 48In Untitled7 at 3n=15 cond(Hn)∞=9.756108e+017X’=1.00 2.00 3.00 4.00 5.00 6.00 7.00 8.00 9.00 10.00 11.00 12.00 13.00 14.00 15.00x’=1.00 2.00 3.00 4.06 4.46 8.92 -2.48 25.12 0.44 -24.72 105.39 -105.03 95.41 -17.82 20.26 Warning: Matrix is close to singular or badly scaled.Results may be inaccurate. RCOND = 9.721674e-019.> In cond at 48In Untitled7 at 3n=16 cond(Hn)∞=1.028629e+018Warning: Matrix is close to singular or badly scaled.Results may be inaccurate. RCOND = 7.948463e-017.> In Untitled7 at 7X’=1.00 2.00 3.00 4.00 5.00 6.00 7.00 8.00 9.00 10.00 11.00 12.00 13.00 14.00 15.00 16.00x’=1.00 2.00 3.00 4.03 4.72 7.62 1.07 21.31 -5.46 0.61 73.43 -98.66 124.04 -53.40 38.17 12.52 Warning: Matrix is close to singular or badly scaled.Results may be inaccurate. RCOND = 1.305919e-018.> In cond at 48In Untitled7 at 3n=17 cond(Hn)∞=1.038063e+018Warning: Matrix is close to singular or badly scaled.Results may be inaccurate. RCOND = 1.798429e-016.> In Untitled7 at 7X’=1.00 2.00 3.00 4.00 5.00 6.00 7.00 8.00 9.00 10.00 11.00 12.00 13.00 14.00 15.00 16.00 17.00x’=1.00 2.00 2.99 4.10 4.13 10.17 -4.82 26.20 0.84 -8.49 39.86 6.13 2.66 5.80 41.30 -2.06 21.18 Warning: Matrix is close to singular or badly scaled.Results may be inaccurate. RCOND = 1.076656e-019.> In cond at 48In Untitled7 at 3n=18 cond(Hn)∞=9.288018e+018Warning: Matrix is close to singular or badly scaled.Results may be inaccurate. RCOND = 7.626119e-018.> In Untitled7 at 7X’=1.00 2.00 3.00 4.00 5.00 6.00 7.00 8.00 9.00 10.00 11.00 12.00 13.00 14.00 15.00 16.00 17.00 18.00x’=1.00 2.00 3.01 3.80 7.66 -12.72 83.21 -172.57 233.93-71.26 -41.44 -156.96 387.29 200.16 -1079.371233.14 -583.42 133.55 Warning: Matrix is close to singular or badly scaled.Results may be inaccurate. RCOND = 1.592243e-019.> In cond at 48In Untitled7 at 3n=19 cond(Hn)∞=6.280448e+018Warning: Matrix is close to singular or badly scaled.Results may be inaccurate. RCOND = 6.040620e-017.> In Untitled7 at 7X’=1.00 2.00 3.00 4.00 5.00 6.00 7.00 8.00 9.00 10.00 11.00 12.00 13.00 14.00 15.00 16.00 17.00 18.00 19.00x’=1.00 2.00 3.00 3.87 6.72 -6.04 56.65 -114.38 178.86-96.36 43.65 -153.15 318.14 62.48 -704.50 954.66 -554.42 187.88 -0.06 Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.155429e-019. > In cond at 48 In Untitled7 at 3n=20 cond(Hn)∞=8.654794e+018Warning: Matrix is close to singular or badly scaled.Results may be inaccurate. RCOND = 5.444860e-017. > In Untitled7 at 7X ’=1.00 2.00 3.00 4.00 5.00 6.00 7.00 8.00 9.00 10.00 11.00 12.00 13.00 14.00 15.00 16.00 17.00 18.00 19.00 20.00x ’=1.00 2.00 2.98 4.33 2.17 19.67 -30.09 54.42 25.37 -114.26 123.00 54.10 -75.28 -8.20 77.82 -85.30 307.17 -360.30 236.32 -26.913. 对函数()21125f x x =+ []1,1x ∈-的Chebyshev 点()()21cos 21k k x n π⎛⎫-= ⎪ ⎪+⎝⎭,1,2,,1k n =+编程进行Lagrange 插值,并分析插值结果。

相关主题