欢迎来到天天文库
浏览记录
ID:47517397
大小:106.37 KB
页数:14页
时间:2020-01-12
《数值分析作业MATLAB》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、1.用二分法解方程x-lnx=2在区间【2,4】内的根方法:二分法算法:f=inline('x-2-log(x)');a=2;b=4;er=b-a;ya=f(a);er0=.00001;whileer>er0x0=.5*(a+b);y0=f(x0);ifya*y0<0b=x0;elsea=x0;ya=y0;enddisp([a,b]);er=b-a;k=k+1;end求解结果:>>answer1343.00003.50003.00003.25003.12503.25003.12503.18753.12503.15633.1406
2、3.15633.14063.14843.14453.14843.14453.14653.14553.14653.14603.14653.14603.14623.14613.14623.14623.14623.14623.14623.14623.14623.14623.1462最终结果为:3.14622.试编写MATLAB函数实现Newton插值,要求能输出插值多项式。对函数在区间[-5,5]上实现10次多项式插值。Matlab程序代码如下:%此函数实现y=1/(1+4*x^2)的n次Newton插值,n由调用函数时指定%函数输出
3、为插值结果的系数向量(行向量)和插值多项式算法:function[ty]=func5(n)x0=linspace(-5,5,n+1)';y0=1./(1.+4.*x0.^2);b=zeros(1,n+1);fori=1:n+1s=0;forj=1:it=1;fork=1:iifk~=jt=(x0(j)-x0(k))*t;end;end;s=s+y0(j)/t;end;b(i)=s;end;t=linspace(0,0,n+1);fori=1:ns=linspace(0,0,n+1);s(n+1-i:n+1)=b(i+1).*po
4、ly(x0(1:i));t=t+s;end;t(n+1)=t(n+1)+b(1);y=poly2sym(t);10次插值运行结果:[bY]=func5(10)b=Columns1through4-0.00000.00000.0027-0.0000Columns5through8-0.0514-0.00000.3920-0.0000Columns9through11-1.14330.00001.0000Y=-(7319042784910035*x^10)/147573952589676412928+x^9/184467440737
5、09551616+(256*x^8)/93425-x^7/1152921504606846976-(28947735013693*x^6)/562949953421312-(3*x^5)/72057594037927936+(36624*x^4)/93425-(5*x^3)/36028797018963968-(5148893614132311*x^2)/4503599627370496+(7*x)/36028797018963968+1b为插值多项式系数向量,Y为插值多项式。插值近似值:x1=linspace(-5,5,101
6、);x=x1(2:100);y=polyval(b,x)y=Columns1through122.70033.99944.35154.09743.49262.72371.92111.17150.52740.0154-0.3571-0.5960Columns13through24-0.7159-0.7368-0.6810-0.5709-0.4278-0.2704-0.11470.02700.14580.23600.29490.3227Columns25through360.32170.29580.25040.19150.12550
7、.0588-0.0027-0.0537-0.0900-0.1082-0.1062-0.0830Columns37through48-0.03900.02450.10520.20000.30500.41580.52800.63690.73790.82690.90020.9549Columns49through600.98861.00000.98860.95490.90020.82690.73790.63690.52800.41580.30500.2000Columns61through720.10520.0245-0.0390-0
8、.0830-0.1062-0.1082-0.0900-0.0537-0.00270.05880.12550.1915Columns73through840.25040.29580.32170.32270.29490.23600.14580.0270-0.1147
此文档下载收益归作者所有