实验1数学实验
G 《数学实验》实验报告 实验 题目:实验一 MATLAB 程序设计基础 报告人:学号:1*** 姓名:
黄秀清 一、实验目的 1 .熟悉 MATLAB 软件的用户环境,掌握其一般目的命令和 MATLAB 矩阵操作与运算函数; 2.初步掌握 matlab 编程。
二、实验内容 1、熟悉 MATLAB 环境。
2、在 D 盘建立一个自己的文件夹,并将其加入到 MATLAB 的搜索路径中。
3、已知2 4 03-1 1-2-2 0A , 593B , Ax B ,求 A 的逆1A ,行列式 | | A,A 特征向量和 x。(求行列式函数 det(),特征向量函数 eig()).4、对以下问题编写 M 文件(1)写一个函数程序,输入一个任意的矩阵,输出阵的最大值及其所处的位置。
(2)编程求201!nn(3)设有一函数22ln(2 1), 1(),0 1sin2 cos , 0xx x xf x e xx x x ,分别用用函数文件和 inline()函数描述该数学函数 5、某商场对顾客所购买的商品实行打折销售,标准如下(商品价格用 price 来表示):
price<200 没有折扣 200≤price<500 3%折扣 500≤price<1000 5%折扣 1000≤price<2500 8%折扣 2500≤price<5000 10%折扣 5000≤price 14%折扣 用 switch 语句实现输入所售商品的价格,求其实际销售价格。
三、实验要求 问题 1,2 进行操作训练,其它问题要求各自编写一个 M 文件 四、问题求解与分析 出(针对每个问题给出 M 文件,给出结果和说明)
第 第 3 题 M 文件 A=[2 4 0;3-1 1;-2-2 0];B=[3;5;9];detA=det(A)eigA=eig(A)x=AB invA=inv(A)运行结果:
detA =-4 eigA = 3.8482-3.1755 0.3273 x =-10.5000 6.0000 42.5000 invA =-0.5000 0-1.0000 0.5000 0 0.5000 2.0000 1.0000 3.5000 第四题:
((1)M 文件 x=max(max(B))[R,C]=find(x==B)B=[3,4,4;5,6,7;9,9,8]
运行结果:
x = 9 R = 3 3 C = 1 2 B = 3 4 4 5 6 7 9 9 8((2)M 文件 sum(gamma(2:21))第二种:
sum=0;k=1;for i=1:20 k=k*i;sum=sum+k;end sum 运行结果 ans = 2.5613e+018((3)M 文件:
function(int x,int y)
input x: if(x>1)y=log(x.*x+2.*x+1);if(0 function y=f(x)if x>1 y=log(x.^2+2*x+1);elseif x>0&x<=1 y=exp(x);else y=sin(2*x)+cos(x.^2)end 2 function y=f(x)if x<=0 y=inline("sin(2*x)+cos(x.^2)","x");elseif x>1 y=inline("ln(x.^2+2*x+1)","x");else x>0&x<=1 y=inline("exp(x)","x");end 第二种: f=inline("log(x.^2+2*x+1)*(x>1)+exp(x)*(x>0&x<=1)+(sin(2*x)+cos(x.^2))*(x<0)","x")运行 结果: >> g=f([2])g = 7.3891 >> g=f([1])g = 2.7183 >> g=f([pi])g = 23.1407 >> g=f([0])g = 第五题: M 文件 price=input("input price:")switch(price/100)case {0,1} rate=0;case {2,3,4} rate=3/100;case num2cell(5:9)rate=5/100;case num2cell(10:24)rate=8/100;case num2cell(25:49)rate=10/100;otherwise rate=14/100;end price=price.*(1-rate) 运行结果: price1 input price:456 price = 456 price = 392.1600 五 :总结(实验的体会和 想法))
