1
1/3
1
x
cosxdx,会出现什么问题?分析原因,并求出正确的
解。
解:Matlab代码为 clear
x=-1:0.05:1;
y=x.^(1/3).*cos(x); s1=trapz(x,y)
fun5=@(x)x.^(1/3).*cos(x); s2=quad(fun5,-1,1)
int('x^(1/3)*cos(x)','x',-1,1)
s1 =
0.9036 + 0.5217i s2 =
0.9114 + 0.5262i
Warning: Explicit integral could not be found. ans =
int(x^(1/3)*cos(x), x = -1..1) ,原函数不存在,不能用int函数运算。
用梯形法和辛普森法计算数值积分时,由于对负数的开三次方运算结果为复数,所以导致结果错误且为复数;
显然被积函数为奇函数,在对称区间上的积分等于0,此时可以这样处理:
(1)重新定义被积函数 %fun5.m
function y=fun5(x) [m,n]=size(x); for k=1:m for l=1:n
y(k,l)=nthroot(x(k,l),3)*cos(x(k,l)); end end end
用辛普森法:
s=quad('fun5',-1,1)
s =
用梯形法 clear;
x=-1:0.01:1;
y=fun5(x); s=trapz(x,y)
s =
-1.3878e-017
6.(假收敛现象)考虑积分I(k) k
sinxdx,
(1)用解析法求I(k);
clear; syms x k;
Ik=int(abs(sin(x)),0,k*pi)
Warning: Explicit integral could not be found. Ik =
int(abs(sin(x)), x = 0..pi*k)
(2)分别用trapz,quad和quad8求I(4),I(6)和I(8),发现什么问题?
clear;
for k=4:2:8;
x=0:pi/1000:k*pi; y=abs(sin(x)); trapz(x,y) end
ans =
8.0000 ans =
12.0000 ans =
16.0000 for k=4:2:8
fun6=@(x)abs(sin(x)); quad(fun6,0,k*pi) end
ans =
8.0000 ans =
12.0000 ans =
16.0000
7.(Simpson积分法)编制一个定步长Simpson法数值积分程序.计算公式为
I Sh
n
3
(f1 4f2 2f3 4f4 2fn 1 4fn
其中n为偶数,h
b a
n
,fi f(a (i 1)h),i 1,2, ,n 1. 解:Matlab代码为 %fun7.m
function y=fun7(f_name,a,b,n) %f_name为被积函数 %[a,b]为积分区间
%n为偶数,用来确定步长h=(b-a)/n if mod(n,2)~=0
disp('n必须为偶数') return; end
if nargin<4 n=100; end
if nargin<3
disp('请输入积分区间') end
if nargin==0 disp('error') end
h=(b-a)/n; x=a:h:b; s=0;
for k=1:n+1
if k==1||k==(n+1) xishu=1;
elseif mod(k,2)==0 xishu=4; else
xishu=2; end
s=s+feval(f_name,x(k))*xishu; end
y=s*h/3; end
8.(广义积分)计算广义积分
exp( x2)
1tan(x)1, sinx 1 x4dx, 0xdx0 x2dx并验证公式
x2
exp( )sinx 2
dx 1,
xdx
2
.
解:Matlab代码为
clear; syms x
s1=vpa(int(exp(-x^2)/(1+x^4),-inf,inf),5) s2=quad(@(x)tan(x)./sqrt(x),0,1) s3=quad(@(x)sin(x)./sqrt(1-x.^2),0,1)
s4=vpa(int(exp(-x^2/2)/sqrt(2*pi),-inf,inf),5) s5=int(sin(x)./x,0+eps,inf)
s1 = 1.4348 s2 =
0.7968 s3 =
0.8933 s4 = 1.0 s5 =
pi/2 - sinint(1/4503599627370496)
实验五 二元函数的图形
【练习与思考】
1.
画出空间曲线z
在
30 x,y 30范围内的图形,并画出相应的等高
线。 clear;
x=-30:0.5:30;y=-30:0.5:30; [X,Y]=meshgrid(x,y);
Z=10*sin(sqrt(X.^2+Y.^2))./sqrt(1+X.^2+Y.^2); mesh(X,Y,Z)
2. 根据给定的参数方程,绘制下列曲面的图形。
a) 椭球面
x 3cosusinv,y 2cosucosv,z sinu
clear;
u=0:pi/50:2*pi; v=0:pi/50:pi;
[U,V]=meshgrid(u,v); x=3*cos(U).*sin(V); y=2*cos(U).*cos(V); z=sin(U); mesh(x,y,z)
b)
椭圆抛物面
x 3usinv,y 2ucosv,z 4u2
clear;
u=0:pi/50:pi/4; v=0:pi/50:2*pi;
[U,V]=meshgrid(u,v); x=3*U.*sin(V); y=2*U.*cos(V); z=4*U.^2; mesh(x,y,z) axis equal c) 单叶双曲面
x 3secusinv,y 2secucosv,z 4tanu
clear;
u=0:pi/15:pi; v=0:pi/15:2*pi;
[U,V]=meshgrid(u,v); x=3*sec(U).*sin(V); y=2*sec(U).*cos(V); z=4*tan(U); mesh(x,y,z) 2d)
u,y v,z
u v2
双曲抛物面x3
clear
u=-3:0.1:3;
[U,V]=meshgrid(u); x=U; y=V;
z=(U.^2-V.^2)/3; mesh(x,y,z)
clc;clear; x lnusinv,y lnucosv,z u
x1=[100 100 100 100 200 200 200 200 300 300 300 300 400 400 400
clear; 400]; u=1:0.1:5; x2=[100 200 300 400 100 200 300 400 100 200 300 400 100 200 300 v=0:pi/30:2*pi; 400]; [U,V]=meshgrid(u,v); y=[636 698 680 662 697 712 674 626 624 630 598 552 478 478 412 x=log(U).*sin(V); 334]'; y=log(U).*cos(V); x=[x1',x2']; z=U; x0=[1 1 1 1 1]; mesh(x,y,z) beta=lsqcurvefit('heigh',x0,x,y) axis equal %绘图:
f) 圆锥面x usinv,y ucosv,z u a1=100:5:400;
a2=a1;
[xx1,xx2]=meshgrid(a1,a2); clear;
Z=beta(1)+beta(2)*xx1+beta(3)*xx2+beta(4)*xx1.^2+beta(5)*xx2.^u=-5:0.1:5;
2; v=0:pi/30:2*pi;
mesh(xx1,xx2,Z) [U,V]=meshgrid(u,v);
x=(U).*sin(V);
y=(U).*cos(V);
Local minimum possible. z=U;
mesh(x,y,z)
lsqcurvefit stopped because the final change axis equal
in the sum of squares relative to
its initial value is less than the default g) 环面
value of the function tolerance.
x (3 0.4cosu)cosv,y (3 0.4cosu)sinv,z 0.4sinv clear; u=0:pi/30:2*pi; beta = v=u; Columns 1 through 5
538.4375 1.4901 0.6189 -0.0046 [U,V]=meshgrid(u,v);
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说医药卫生数学实验课后习题解答(4)在线全文阅读。
相关推荐: