作者:夏云木子 1、
>> clear >> syms x
>> h=0.1;x0=1.0;x1=1.1;x2=1.2;f(x)=(1+x)^(-2); >> a=1/(2*h)*(-3*f(x0)+4*f(x1)-f(x2));fx0=vpa(a,4) >> b=1/(2*h)*(-f(x0)+f(x2));fx1=vpa(b,4)
>> c=1/(2*h)*(f(x0)-4*f(x1)+3*f(x2));fx2=vpa(c,4)
2、
>> clear
>> h=pi/1000;x=0:h:pi/2; >> format long e,y=sin(x); >> s=h*trapz(y)
改变节点: >> clear
>> h=pi/10000;x=0:h:pi/2; >> format long e,y=sin(x); >> s=h*trapz(y)
3、(1)符号法: >> clear >> syms x
>> s=int(sqrt(4-sin(x).^2),x,0,pi/2), vpa(s,5)
节点数增加,误差减小
复合矩形法:
>> format short,h=pi/1000;x=h:h:pi/2; >> y=sqrt(4-sin(x).^2); >> s=h*sum(y)
复合梯形法
>> format short,h=pi/1000;x=0:h:pi/2; >> y=sqrt(4-sin(x).^2); >> s=h*trapz(y)
“quad”指令
>> y='sqrt(4-sin(x).^2)';
>> format short,s=quad(y,0,pi/2)
(2)符号法: >> clear >> syms x
>> s=int(exp(-x.^2).*sqrt(1+x.^2),x,0,1);vpa(s,5)
复合矩形法:
>> format short,h=1/1000;x=h:h:1; >> y=exp(-x.^2).*sqrt(1+x.^2); >> s=h*sum(y)
复合梯形法:
>> format short,h=1/1000;x=0:h:1; >> y=exp(-x.^2).*sqrt(1+x.^2); >> s=h*trapz(y)
“quad”指令:
>> y='exp(-x.^2).*sqrt(1+x.^2)'; >> format short,quad(y,0,1)
(3)符号法 >> clear >> syms x
>> s=int(1/(1+x.^2),x,-4,4);vpa(s,5)
复合矩形法:
>> format short,h=1/1000;x=-4+h:h:4; >> y=1./(1+x.^2); >> s=h*sum(y)
复合梯形法:
>> format short,h=1/1000;x=-4:h:4; >> y=1./(1+x.^2); >> s=h*trapz(y)
“quan”指令:
>> y='1./(1+x.^2)';
>> format short,s=quad(y,-4,4)
(4)符号法:
>> clear >> syms x
>> s=int(x.^3-2*x.^2-3,x,0,1);vpa(s,5)
复合矩形法:
>> format short,h=1/1000;x=h:h:1; >> y=x.^3-2*x.^2-3; >> s=h*sum(y)
复合梯形法:
>> format short,h=1/1000;x=0:h:1; >> y=x.^3-2*x.^2-3; >> s=h*trapz(y)
“quad”指令:
>> y='x.^3-2*x.^2-3';
>> format short,s=quad(y,0,1)
(5)符号法: >> clear >> syms x
>> s=int(1/log(x),x,1.1,3);vpa(s,5)
复合矩形法:
>> format short,h=1/1000;x=1.1+h:h:3; >> y=1./log(x); >> s=h*sum(y)
复合梯形法:
>> format short,h=1/1000;x=1.1:h:3; >> y=1./log(x); >> s=h*trapz(y)
“quad”指令: >> y='1./log(x)';
>> format short,s=quad(y,1.1,3)
(6)符号法: >> clear >> syms x
>> s=int(sin(x).^2./x.^2+x.*exp(x)-4,x,1,3);vpa(s,5)
复合矩形法: >> format short,
>> format short,h=1/1000;x=1+h:h:3; >> y=sin(x).^2./x.^2+x.*exp(x)-4; >> s=h*sum(y)
复合梯形法:
>> format short,h=1/1000;x=1:h:3; >> y=sin(x).^2./x.^2+x.*exp(x)-4; >> s=h*trapz(y)
“quad”指令:
>> y='sin(x).^2./x.^2+x.*exp(x)-4'; >> format short,s=quad(y,1,3)
四、(1) >> clear
>> x=0.5:0.1:1.1;y=[0.4804 0.5669 0.6490 0.7262 0.7985 0.8658 0.9281]; >> s=0.1*trapz(y.^2)
(2) >> clear
>> x=0.5:0.1:1.1;y=[0.4804 0.5669 0.6490 0.7262 0.7985 0.8658 0.9281]; >> s=0.1*trapz(x.^2.*y)
五、(1)
>> y='log(1+x)./(1+x.^2)';
>> format short,s=quad(y,0.01,1)
(2) >> clear
>> y='x.*sin(x).^(-2)';
>> format short,s=quad(y,pi/4,pi/3)
(3)
>> syms x y
>> s=int(int(x.*y,x,y.^2,y+2),y,-1,2)