数学软件实验报告实验二

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

数学软件实验报告学院名称:理学院专业年级:姓名:学号:课程:数学软件实验报告日期:2014年10月25日实验二MATLAB的基本数值运算一.实验目的MATLAB具有非常强大的数值计算能力,对各种常量(包括一般常量和固定常量)、各种变量(包括数值变量、字符变量、单元形变量和结构变量)熟悉其用法,向量及其运算,矩阵及其运算,数组及其运算,多项式及其各种运算,线性方程组的求解,数值统计的基本函数及其应用,简单插值函数,简单优化函数,微分方程数值解的基本函数等。二.实验要求理解常量、变量、向量、矩阵、多项式等概念,掌握向量在MATLAB中的表示,熟练掌握矩阵及其运算,数组及其运算,多项式运算,线性方程组求解,了解数值统计的基本函数,简单插值函数,简单优化函数,微分方程数值解的基本函数等。三.实验内容实验一:第二节MATLAB基本数学运算一:简单矩阵的建立与矩阵元素(1)直接输入矩阵a=[123;456;789]a=123456789(2)通过语句或者函数产生矩阵b=sin(a)b=0.84150.90930.1411-0.7568-0.9589-0.27940.65700.98940.4121c=a+0.1*(1+b/2)c=1.14212.14553.10714.06225.05216.08607.13288.14959.1206d=ones(3)+eye(3)d=211121112(3)利用文件创建矩阵loadfilel.txtfilelfilel=123456789(4)从外部数据文件中装入已有矩阵loadfilel.txtx=[-1.3sqrt(3)(1+2+3)*4/5]x=-1.30001.73214.8000定义或修改某一元素loadfilel.txtx(5)=abs(x(1))x=-1.30001.73214.800001.3000小矩阵生成大矩阵loadfilel.txte=[a,b]e=1.00002.00003.00000.84150.90930.14114.00005.00006.0000-0.7568-0.9589-0.27947.00008.00009.00000.65700.98940.4121e=[a,d]e=123211456121789112大矩阵抽取元素变为小矩阵f=e(:,[2,5])f=2152812:常量,变量与表达式t='howaboutthischaracterstring't=howaboutthischaracterstringv='Ican''tfindthelitter'v=Ican'tfindthelitterA='Hello'A=HelloB=2*AB=1442022162162223:命令窗口常用的命令与标点符号的使用helpcdCDChangecurrentworkingdirectory.CDdirectory-specsetsthecurrentdirectorytotheonespecified.CD..movestothedirectoryabovethecurrentone.CD,byitself,printsoutthecurrentdirectory.WD=CDreturnsthecurrentdirectoryasastring.UsethefunctionalformofCD,suchasCD('directory-spec'),whenthedirectoryspecificationisstoredinastring.Seealsopwd.Overloadedmethods:ftp/cdReferencepageinHelpbrowserdoccd二:算数运算1:加减法运算a=[12;34];b=ones(2);c=a+bc=2345d=[123];e=a+d???Errorusing==plusMatrixdimensionsmustagree.c1=c-1c1=12342:乘除法运算f=a*bf=3377g=b*ag=4646h=pi*ah=3.14166.28329.424812.5664F=a.*cF=261220G=c.*aG=261220a=[123;426;749]b=[412]a*x=b???a=[123;426;749]b=[412]a*x=b|Error:UnexpectedMATLABexpression.四a=rand(3),b=rand(3),a=0.81470.91340.27850.90580.63240.54690.12700.09750.9575b=0.96490.95720.14190.15760.48540.42180.97060.80030.9157A1=a/bA1=0.75710.33560.03230.2462-0.43410.7590-0.94460.40931.0035A2=a\bA2=-2.5775-1.3591-0.06183.03652.0130-0.08631.04620.81100.9734A3=b\aA3=-1.8233-1.1435-0.21722.73672.19610.3685-0.3205-0.60060.9537A4=b/aA4=0.83060.3601-0.29911.0730-0.87950.63070.34420.69780.4577A5=(a'/b')'A5=-1.8233-1.1435-0.21722.73672.19610.3685-0.3205-0.60060.9537A6=a.\bA6=1.18431.04790.50950.17400.76760.77127.64338.20460.9564A7=a.\bA7=1.18431.04790.50950.17400.76760.77127.64338.20460.9564A8=1./A7A8=0.84440.95421.96285.74691.30281.29670.13080.12191.04563.乘幂运算g=[1234;5678;9101112]g=123456789101112g=[1234;5678;9101112];g.^2%对g中的元素求平方ans=149162536496481100121144h=[1111;2222;3333];g.^(h-1)%求以g元素为底,以h中相应元素减一为幂指数产生的矩阵ans=11115678811001211442.^g%以2为底,以中相应元素为幂指数产生的矩阵ans=2481632641282565121024204840964:转置运算x=[123;456;789]x=123456789y=x'y=147258369a=[1+2i2-3i;4+5i5-6i]a=1.0000+2.0000i2.0000-3.0000i4.0000+5.0000i5.0000-6.0000ib=a'b=1.0000-2.0000i4.0000-5.0000i2.0000+3.0000i5.0000+6.0000ib=a.'b=1.0000+2.0000i4.0000+5.0000i2.0000-3.0000i5.0000-6.0000iconj(a')ans=1.0000+2.0000i4.0000+5.0000i2.0000-3.0000i5.0000-6.0000i三:关系运算与逻辑运算1:关系运算a=[-124;548];b=[015;512];c=abc=0100112.逻辑运算(1)逻辑运算与(&)a=[-124;548];b=[015;512];c=a&bc=011111(2)逻辑运算与(|)c=a|bc=111111(3)逻辑非c=~ac=000000四:建立特殊数据组1.用特殊函数建立数组2.用小数组建大数组a=[12;34]a=1234b=[a,eye(2,3);ones(3,2),rand(3)]b=1.00002.00001.0000003.00004.000001.000001.00001.00000.79220.03570.67871.00001.00000.95950.84910.75771.00001.00000.65570.93400.74313.利用冒号建立数组x=1:5x=12345y=0:pi/4:piy=00.78541.57082.35623.1416z=6:-1:1z=654321a=0:0.2:1;b=exp(-a).*sin(a);[a',b']ans=000.20000.16270.40000.26100.60000.30990.80000.32231.00000.30964.空数组x=[]x=[]y=1:-3y=Emptymatrix:1-by-0a=[123;456]a=123456a(:,3)=[]a=1245实验四第一节1、由文件生成和保存矩阵clear%清除当前工作空间中的变量myfile%执行M文件A=34-11-91065074-161-47-16-82-45-612-8-36-78-118-49130who%查看工作空间中的变量Yourvariablesare:Aloadtxefile.txt%装入txtfile.txt文件whoYourvariablesare:Asavematfile%保存工作空间变量到matfile.mat文件中clearwholoadmatfilewhoYourvariablesare:Atxtfile%显示变量txtfile的内容2、由函数生成矩阵eye(5,6)ans=100000010000001000000100000010eye(5)ans=1000001000001000001000001ones(8)ans=1111111111111111111111111111111111111111111111111111111111111111zeros(4)ans=0000000000000000rand(3)ans=0.81470.91340.27850.90580.63240.54690.12700.09750.9575diag(4)ans=43、符号矩阵的创建exam=sym('[1,x/a,sin(x);y/x,1+1/y,tan(x/y);1=0,3+3,4*r]')???Errorusing==sym.symat198Errorusing==sym.symat165Errorusing==maplemex`;`unexpectedsymsxyzabcf=a*x^2+b*x+c;g=x*y*z;h=(f+g)*b/a;e1=sym('a*x^2+b*x+c=0');e2=sym('x*y*z=0');e3=sym('h=0');M=[123xfghye1e2e3z]M=[1,2,3,x][][2][2b(ax+xyz+bx+c)][ax+bx+c,zyx,--------------------------,y][a][][2][ax+bx+c=0,zyx=0,h=0,z]symsxycra=sin((c+(r-1)*3));b=exp(r+(c-1)*4);c=(c+(r-1)*3)*x+(r+(c-1)*4)*y;A=symmat(3,3,a)forC=1234、矩阵的修改A=rand(5)A=0.81470.09750.15760.14190.65570.90580.27850.97060.42180.03570.12700.54690.95720.91570.84910.91340.95750.48540.79220.93400.63240.96490.80030.95

1 / 24
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功