您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 公司方案 > MATLAB软件与基础数学实验
MATLAB软件与基础数学实验SawH.Z实验1MATLAB基本特性与基本运算例1-1求[12+2×(7-4)]÷32的算术运算结果。clears=(12+2*(7-4))/3^2s=2例1-2计算5!,并把运算结果赋给变量yy=1;fori=1:5y=y*i;endy例1-3计算2开平方s=2^(0.5)s=1.4142例1-4计算2开平方并赋值给变量x(不显示)查看x的赋值情况a=2;x=a^(0.5);x例1-4设75,24ba,计算|)tan(||)||sin(|baba的值。a=(-24)/180*pi;b=75/180*pi;a1=abs(a);b1=abs(b);c=abs(a+b);s=sin(a1+b1)/(tan(c))^(0.5)例1-5设三角形三边长为2,3,4cba,求此三角形的面积。a=4;b=3;c=2;p=(a+b+c)/2;s=(p*(p-a)*(p-b)*(p-c))^(0.5)例1-7设101654321A,112311021B,计算||,,AABBA,1A。a=[1,2,3;4,5,6;1,0,1];b=[-1,2,0;1,1,3;2,1,1];x=a+b;y=a*b;z=norm(a);q=inv(a);x,y,z,q例1-8显示上例中矩阵A的第2行第3列元素,并对其进行修改.a=[1,2,3;4,5,6;1,0,1];x=a(2,3);a(2,3)=input('changeinto=')x,a例1-9分别画出函数xxycos2和xxzsin在区间[-6,6]上的图形。a=1;x=-1/6*pi:0.01:1/6*pi;y=(x.*x).*cos(x);z=sin(x)/x;plot(x,y,x,z);例1-10试求方程组432201624121X的解。a=[1,2,1;4,2,-6;-1,0,2];b=[2;3;4];x=inv(a)*b例1-11试求矩阵方程111321201624121X的解。a=[1,2,1;4,2,-6;-1,0,2];b=[1,2,3;1,1,1];x=b*inv(a)例1-12建立同时计算nbay)(1,nbay)(2的函数。即任给a,b,n三个数,返回y1,y2.a=input('a=');b=input('b=');n=input('n=');y1=(a+b)^n;y2=(a-b)^n;y1,y2例1-13设2211()6(0.3)0.01(0.9)0.04fxxx,试画出在[0,2]上的曲线段。%加坐标网格x=0:2;y=1./((x-0.3).^2+0.01)+1./((x-0.9).^2+0.04)-6;plot(x,y);gridon;例如:对于例题1-13中所定义的f(x),求其零点c.例如:求一元函数最小值(fminbnd命令)例如:求例题1-13中所定义f(x)在[0,1]上的定积分10)d(xxf.例1-14求二重积分]2,1[]1,0[dxy及三重积分]1,0[]1,0[]1,0[2)(dxdydzzxey。symsxyza1=int(y,int(x,x.*y,1,2),0,1);a2=int(z,int(y,int(x,x.*exp.^y+z.^2,0,1),0,1),0,1);a1,a2例1-15已知56523ttty,设该曲线在区间[0,x]上所围曲边梯形面积为s,试求当s分别为5,10时的x的值。分.f=inline('1/4*t^4-5/3*t^3+3*t^2+5*t-5');t=fzero(f,[0,5])t=0.7762clearf=inline('1/4*t^4-5/3*t^3+3*t^2+5*t-10');t=fzero(f,[0,10])t=1.5179例1-16利用MATLAB命令求解无理数的近似值。(1)用函数零点命令(fzero)求无理数e的近似值;(2)用定积分计算命令(trapz,quad,quadl)求无理数2ln的近似值。(提示:e=2.7182818284…,2ln=0.6931471806…)((1)clearf=inline('log(x)-1');x=fzero(f,2);e=vpa(x,10)e=2.718281828(2)trapz:clearx=0:0.01:1;y=1./(1+x);a=trapz(x,y);ln2=vpa(a,10)ln2=.6931534305quad:f=inline('1./(1+x)');a=quad(f,0,1);ln2=vpa(a,10)ln2=.6931471999quadl:a=quadl(f,0,1);ln2=vpa(a,10)ln2=.6931471861例1-17求极限hxhxhsin)sin(lim0。symsxhlimit((sin(x+h)-sin(x))/h,h,0)ans=cos(x)例1-18:设)sin(),(yyxyxfn,求.,,,222yxfyfyfxff=(x^n)*y+sin(y);symsxny;f=(x^n)*y+sin(y);dx=diff(f,x);dy=diff(f,y);dxdx=n*x^(n-1)*ydydy=cos(y)+x^ndy2=diff(f,y,2);dy2dy2=-sin(y)dxdy=diff(diff(f,x),y);dxdydxdy=n*x^(n-1)例1-19:求dxxxy21,dyxxyt021,dyxxydxx02101,.)(101010yxxdzzyxdydx►symsxyz%声明符号变量,注意变量间必须用空格分开级数求和(symsum)%求级数k131211(ans=inf即)%求级数)1(1321211kk(ans=1)%求级数kaaaa3332(ans=3/2*a)泰勒展开(taylor)►symsx►fy=1/(1+x+x^2)求fx对自变量x(默认)在x=0点(默认)泰勒展开前6项(默认)求fx对自变量x(默认)在x=1点泰勒展开式前8项symsxfy=1/(1+x+x^2)fy=1/(1+x+x^2)taylor(fy,x,0,6)ans=1-x+x^3-x^4taylor(fy,x,1,8)ans=1/73方程求根(solve)►fx=sym('a*x^2+b*x+c');%建立符号函数方程fx=0的符号解求方程fx=0关于变量b的符号解fx=sym('a*x^2+b*x+c');%建立符号函数solve(fx)ans=1/2/a*(-b+(b^2-4*a*c)^(1/2))1/2/a*(-b-(b^2-4*a*c)^(1/2))solve(fx,'b')ans=-(a*x^2+c)/x微分方程(组)求解(dsolve)求方程y'=5的通解,默认自变量为t求方程y'=x的通解,指定自变量为x求方程y''=1+y'满足y(0)=1,y'(0)=0的特解求方程组2xyyxx的通解,默认自变量为tdsolve('Dy=5','x')ans=5*x+C1dsolve('Dy=x','x')ans=1/2*x^2+C1dsolve('D2y=1+Dy','y(0)=1','Dy(0)=0')ans=exp(t)-t[x,y]=dsolve('Dx=x+y,Dy=2*x')x=-1/2*C1*exp(-t)+C2*exp(2*t)y=C1*exp(-t)+C2*exp(2*t)实验2MATLAB绘制二维、三维图形例2-1在子图形窗口中画出]2,0[上正弦、余弦曲线。x=0:pi/10:2*pi;y=sin(x);plot(x,y)y=cos(x);plot(x,y)例2-2画出]2,0[上正弦、余弦曲线并对线型加粗、点型加大,重新定置坐标系以及加注相关说明和注释。x=0:pi/10:2*pi;y=sin(x);a=plot(x,y,’-+’);set(a,'LineWidth',3.0)axis([07-23])title(‘tuxiang’);xlabel(‘xzhou’)ylabel(‘yzhou’)text(1,2,asd);例2-3分别在两个图形窗口画出填充一正方形和极坐标方程2cos2sin2r的图形。figure(1);x=[01100]y=[00110]fill(x,y,'x')figure(2);theta=[0:0.01:2-pi]r=2*sin(x*theta).*cos(2*theta);polar(theta,r);例2-4在[-2.5,2.5]上画出函数2xey的直方图和阶梯图。x=[-2.5:0.25:2.5];y=exp(-x.*x);stairs(x,y);bar(x,y)例2-4采用不同形式(直角坐标、参数、极坐标),画出单位圆122yx的图形。t=deg2rad(0:360);x=cos(t);y=sin(t);plot(x,y)x=0:pi/20:2*pi;plot(cos(x),sin(x))x=0:pi/20:pi*2;y=sin(x)+cos(x);polar(x,y)例2-5画出螺旋线:x=sin(t),y=cos(t),z=t,]10,0[t上一段曲线。t=0:pi/50:10*pi;y1=sin(t);y2=cos(t);plot3(y1,y2,t);例2-6画出矩形域[-1,1]×[-1,1]上旋转抛物面:22yxz。x=linspace(-1,1,100);y=x;[X,Y]=meshgrid(x,y);Z=X.^2+Y.^2;mesh(X,Y,Z)例2-7在圆形域122yx上绘制旋转抛物面:22yxz。x=linspace(-1,1,300);y=x;[X,Y]=meshgrid(x,y);Z=X.^2+Y.^2;i=find(Z1);Z(i)=NaN;mesh(X,Y,Z)例2-9画出2222sinyxyxz在5.7||,5.7||yx上的图形。x=7.5:0.5:7.5;y=x[X,Y]=meshgrid(x,y);u=sqrt(X.^2+Y.^2)+eps;Z=sin(u)./u;surf(X,Y,Z);例2-10有一组实验数据如下表所示,试绘图表示。时间123456789数据112.5113.5415.6015.9220.6424.5330.2450.0036.34数据29.8720.5432.2140.5048.3164.5172.3285.9889.77数据310.118.1414.1710.1440.5039.4560.1170.1340.90d1=[12.5113.5415.6015.9220.6424.5330.2450.0036.34];d2=[9.8720.5432.2140.5048.3164.5172.3285.9889.77];d3=[10.118.1414.1710.1440.5039.4560.1170.1340.90];plot(t,d1,’r+-’,t,d2,’kt:’,t,d3,’b*-’,’linewidth’,2,’markersize,8’);title(‘time&data’);xlable(‘time’);ylable(‘data’);axis([01001
本文标题:MATLAB软件与基础数学实验
链接地址:https://www.777doc.com/doc-2239352 .html