1、5) 已知函数z=sin(xy), 计算 syms x y z;z=sin(x*y);D3z=diff(diff(z,x),y,2)D3z =- 2*x*sin(x*y) - x2*y*cos(x*y)3 用数值方法求定积分1) fun=inline(x.2.*sqrt(2.*x.2+3)f,n=quad(fun,1,5)f = 232.8057n = 212)fun=inline(x./sin(x.2)f,n=quadl(fun,pi/4,pi/3) 0.3254 184 已知数据x,y如下表,试求2次拟合多项式f(x),然后求x=0.05,0.25,0.45,0.65,0.85,1.05各
2、点的函数近似值,并绘出拟合曲线及求得的函数点。x0.00.10.20.30.40.50.60.70.80.91.0y-0.4471.9783.286.167.087.347.669.569.489.311.2 x=0:0.1:1;y=-0.447 1.978 3.28 6.16 7.08 7.34 7.66 9.56 9.48 9.3 11.2;a=polyfit(x,y,2)x1=0.05:0.2:1.05;y1=a(1)*x1.2+a(2)*x1+a(3);yfit=polyval(a,x);plot(x1,y1,or,x,yfit,-ga = -9.8108 20.1293 -0.031
3、75 求方程exsinx=0在区间-4,-3上的一个根。 fzero(exp(x)*sin(x),-4,-3) -3.14166 已知某函数的离散点列如下X-4-3-2-112340.972793.42343.81861.8415-0.15853-0.18141-2.5766-7.0272分别使用hermite插值、三次样条插值、三次方插值估算在x在2.5,1.5,0.5,-0.5,-1.5,-2.5的函数值,并在同一张图上绘制出三条曲线。 x=-4 -3 -2 -1 0 1 2 3 4;y= 0.97279 3.4234 3.8186 1.8415 0 -0.15853 -0.18141 -
4、2.5766 -7.0272;x1=-2.5:1:2.5;c1=interp1(x,y,x1,pehipc2=interp1(x,y,x1,splinc3=interp1(x,y,x1,cubicplot(x1,c1,o-r,x1,c2,*-g,x1,c3,:bHlegend(hermite插值,三次样条插值三次插值7 用经典的RK方法计算常微分方程:y=e-2t-2y 初值条件y(0)=0.1exp(-2*t)-2*ytt,y=ode45(fun,0,1,0.1)t = 0 0.0063 0.0126 0.0188 0.0251 0.0501 0.0751 0.1001 0.1251 0.1
5、501 0.1751 0.2001 0.2251 0.2501 0.2751 0.3001 0.3251 0.3501 0.3751 0.4001 0.4251 0.4501 0.4751 0.5001 0.5251 0.5501 0.5751 0.6001 0.6251 0.6501 0.6751 0.7001 0.7251 0.7501 0.7751 0.8001 0.8251 0.8501 0.8751 0.9001 0.9251 0.9438 0.9626 0.9813 1.0000 0.1000 0.1050 0.1098 0.1144 0.1190 0.1358 0.1507 0.
6、1638 0.1753 0.1852 0.1938 0.2011 0.2073 0.2123 0.2164 0.2195 0.2219 0.2235 0.2244 0.2247 0.2236 0.2224 0.2207 0.2187 0.2137 0.2108 0.2077 0.2044 0.2009 0.1973 0.1935 0.1896 0.1857 0.1817 0.1776 0.1735 0.1694 0.1653 0.1611 0.1581 0.1550 0.1519 0.14898 求二阶微分方程 初值条件为x(0)=1, x(0)=0function dy = fun(x,y)
7、dy = zeros(2,1);dy(1) = y(2);dy(2) = (1-y(1)2)*y(2)-y(1); x,y=ode45(fun,0,1,1 0)x = 0.0001 0.0002 0.0005 0.0007 0.0010 0.0012 0.0025 0.0037 0.0050 0.0062 0.0125 0.0313 0.0563 0.0813 0.1063 0.1313 0.1563 0.1813 0.2063 0.2313 0.2563 0.2813 0.3063 0.3313 0.3563 0.3813 0.4063 0.4313 0.4563 0.4813 0.5063
8、 0.5313 0.5563 0.5813 0.6063 0.6313 0.6563 0.6813 0.7063 0.7313 0.7563 0.7813 0.8063 0.8313 0.8563 0.8813 0.9063 0.9313 0.9485 0.9657 0.9828 1.0000 0 1.0000 -0.0001 1.0000 -0.0002 1.0000 -0.0005 1.0000 -0.0007 1.0000 -0.0010 1.0000 -0.0012 1.0000 -0.0025 1.0000 -0.0037 1.0000 -0.0050 1.0000 -0.0062
9、0.9999 -0.0125 0.9998 -0.0188 0.9997 -0.0251 0.9995 -0.0313 0.9984 -0.0563 0.9967 -0.0813 0.9943 -0.1062 0.9914 -0.1310 0.9878 -0.1559 0.9836 -0.1806 0.9788 -0.2053 0.9733 -0.2300 0.9673 -0.2546 0.9606 -0.2792 0.9533 -0.3037 0.9454 -0.3282 0.9369 -0.3527 0.9278 -0.3772 0.9180 -0.4018 0.9077 -0.4263
10、0.8967 -0.4509 0.8851 -0.4756 0.8729 -0.5003 0.8601 -0.5252 0.8467 -0.5502 0.8326 -0.5753 0.8179 -0.6006 0.8026 -0.6261 0.7866 -0.6519 0.7700 -0.6779 0.7527 -0.7042 0.7348 -0.7308 0.7162 -0.7578 0.6969 -0.7851 0.6769 -0.8128 0.6562 -0.8410 0.6349 -0.8696 0.6128 -0.8987 0.5899 -0.9283 0.5663 -0.9584
11、0.5497 -0.9795 0.5327 -1.0008 0.5153 -1.0224 0.4976 -1.04429 用三点公式和五点公式求F(x)=1/(1+x)2在x=1.1处的导数值。1.11.21.31.4F(x)0.25000.22680.20660.18900.1736function df=ThreePoint(func,x0,type,h)if nargin = 3 h = 0.1;else if (nargin = 4 & h = 0.0) disp(h不能为0! return; endendy0 = subs(sym(func), findsym(sym(func),x
12、0);y1 = subs(sym(func), findsym(sym(func),x0+h);y2 = subs(sym(func), findsym(sym(func),x0+2*h);y_1 = subs(sym(func), findsym(sym(func),x0-h);y_2 = subs(sym(func), findsym(sym(func),x0-2*h);switch type case 1,df = (-3*y0+4*y1-y2)/(2*h); %用第一个公式求导数 case 2,df = (3*y0-4*y_1+y_2)/(2*h); %用第二个公式求导数 case 3
13、,df = (y1-y_1)/(2*h); %用第三个公式求导数 function df=FivePoint(func,x0,type,h)y3 = subs(sym(func), findsym(sym(func),x0+3*h);y4 = subs(sym(func), findsym(sym(func),x0+4*h);y_3 = subs(sym(func), findsym(sym(func),x0-3*h);y_4 = subs(sym(func), findsym(sym(func),x0-4*h); case 1, df = (-25*y0+48*y1-36*y2+16*y3-
14、3*y4)/(12*h); case 2, df = (-3*y_1-10*y0+18*y1-6*y2+y3)/(12*h); case 3, df = (y_2-8*y_1+8*y1-y2)/(12*h); %用第三个公式求导数 case 4, df = (3*y1+10*y0-18*y_1+6*y_2-y_3)/(12*h); %用第四个公式求导数 case 5, df = (25*y0-48*y_1+36*y_2-16*y_3+3*y_4)/(12*h); %用第五个公式求导数 x =1.1;dy3=TherePoint(1/(1+x)2,x,1)dy5=FivePoint(10求(x3+x2+x+1)(1/3)-sqrt(x2+x+1)*log(exp(x)+x)/xlimit(y,inf)-1/6
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1