MATLAB第六次上机实验报告
- 格式:doc
- 大小:57.50 KB
- 文档页数:9
《数学实验》报告实验名称Matlab高等数学相关运算学院专业班级姓名学号2013年6月一、 【实验目的】1. 学会用Matlab 进行常微分方程的求解、随机试验和统计作图;2. 掌握相关运算处理的基本指令和参数设置 二、 【实验任务】 P168 习题24 求解微分方程yxx y cos sin ,=。
P168 习题27用数值方法求解析下列微分方程,用不同颜色和线形将y 和y ’画在同一个图形窗口里:t y y y 2-1-t ,,,=+初始时间:0t =0;终止时间:π=f t ;初始条件:2.0|1.0|00,====t t y y 。
P190 习题15描绘以下数组的频数直方图:6.8, 29.6,33.6,35.7, 36.9, 45.2, 54.8, 65.8, 43.4, 53.8, 63.7, 69.9, 70.7, 79.5, 97.9, 139.4, 157.0 P190 习题16若样本为85,86,78,90,96,82,80,74 求样本均值、标准差、中位数、极差和方差。
三、 【实验程序】 习题24:>>dsolve('Dy=x*sin(x)/cos(y)','x') 习题27:function xdot=exf(t,x) u=1-2*t;xdot=[0,1;1,-t]*x+[0,1]'*u;clf;t0=0;tf=pi;x0t=[0.1;0.2];[t,x]=ode23('exf',[t0,tf],x0t);y=x(:,1)Dy=x(:,2)plot(t,y,'r-', t,Dy,'b*')legend('y','Dy')xlabel('t轴')习题15:clf;load A.txt;figure(1)hist(A,5)figure(2)hist(A,10)figure(3)hist(A,20)习题16:B=[85 86 78 90 96 82 80 74];disp(' 样本均值标准差中位数极差方差') C=[mean(B),std(B),median(B),range(B),var(B)]四、【实验结果】习题24:习题27:习题15:习题16:五、【实验总结】通过这最后一次实验,我学习了怎么用Matlab作常微分方程的求解、概率论与数理统计的相关计算,感受到了Matlab软件的强大与方便。
(最新版)MATLAB实验报告实验一典型环节的MATLAB仿真一、实验目的1.熟悉MATLAB桌面和命令窗口,初步了解SIMULINK功能模块的使用方法。
2.通过观察典型环节在单位阶跃信号作用下的动态特性,加深对各典型环节响应曲线的理解。
3.定性了解各参数变化对典型环节动态特性的影响。
二、SIMULINK的使用MATLAB中SIMULINK是一个用来对动态系统进行建模、仿真和分析的软件包。
利用SIMULINK功能模块可以快速的建立控制系统的模型,进行仿真和调试。
1.运行MATLAB软件,在命令窗口栏“>>”提示符下键入simulink命令,按Enter 键或在工具栏单击按钮,即可进入如图1-1所示的SIMULINK仿真环境下。
2.选择File菜单下New下的Model命令,新建一个simulink 仿真环境常规模板。
3.在simulink仿真环境下,创建所需要的系统。
以图1-2所示的系统为例,说明基本设计步骤如下:1)进入线性系统模块库,构建传递函数。
点击simulink下的“Continuous”,再将右边窗口中“Transfer Fen”的图标用左键拖至新建的“untitled”窗口。
2)改变模块参数。
在simulink仿真环境“untitled”窗口中双击该图标,即可改变传递函数。
其中方括号内的数字分别为传递函数的分子、分母各次幂由高到低的系数,数字之间用空格隔开;设置完成后,选择OK,即完成该模块的设置。
3)建立其它传递函数模块。
按照上述方法,在不同的simulink 的模块库中,建立系统所需的传递函数模块。
例:比例环节用“Math”右边窗口“Gain”的图标。
4)选取阶跃信号输入函数。
用鼠标点击simulink下的“Source”,将右边窗口中“Step”图标用左键拖至新建的“untitled”窗口,形成一个阶跃函数输入模块。
5)选择输出方式。
用鼠标点击simulink下的“Sinks”,就进入输出方式模块库,通常选用“Scope”的示波器图标,将其用左键拖至新建的“untitled”窗口。
Matlab上机实习实习报告上周我们进行了本学期第二个实习部分-Matlab上机实习。
本次实习一星期,共做了四个部分。
分别是:一,Matlab基本操作;二,数值数组及其运算;三,Matlab图形绘制基础;四,SIMULINK仿真基础。
下面分别介绍个部分实习内容。
实习内容一Matlab基本操作1,实习目的:·掌握Matlab的启动和退出;·熟悉Matlab的命令窗口;·熟悉其他常用窗口和工具栏;2,对本软件有了初步认识后,接下来就开始指导书要求做一些训练了在指令窗中输入下面一段程序,功能是::画出衰减振荡曲线y=(e-t/3)sin3t及其他的包络线y0=(e-t/3)。
T的取值范围是[0,4 ]。
t=0:pi/50:4*pi;y0=exp(-t/3);y=exp(-t/3).*sin(3*t);plot(t,y,’-r’,t,y0,’:b’,t,-y0,’:b’)观察输出结果3,通过下拉菜单File:Preferences改变设置指令窗中的字体、颜色等。
如:数据显示格式的设置:Format short 小数点后四位(缺省情况),如显示p为3.1416。
Format long 小数点后十四位,如显示p为3.14159265358979。
Formant bank 小数点后两位,如显示p为3.14。
Format short e 小数点后四位科学记数法,如显示p为3.1416e+000。
Format long e 小数点后十四五位科学记数法,如显示p为3.141592653589793e+000。
在指令窗中键入y1=2*sin(0.3*pi)/(1+sqrt(5))然后利用回调指令计算y2=2*y1*cos(0.3*pi)/(1+sqrt(5))y1 =0.5000y2 =0.18164,了解软件中的一些功能和命令。
包括熟悉历史指令窗(Command History)、熟悉当前目录浏览器(Current Diretory)、熟悉工作空间浏览器(Workspace Browser),以及一些指令如: Clear 清除当前工作区中的所有变量Clc 清除指令窗中内容(未清除当前工作区中的变量)Clf 清除图形窗口Cd 设置当前工作目录Exit,quit 退出Matlab实习内容二数值数组及其运算1,实习目的·掌握一维数组的创建和寻访;·掌握二维数组的创建和寻访;·掌握的Matlab矩阵和数组的运算;·熟悉Matlab关系操作和逻辑操作;2,实习内容和步骤(1)常量与变量变量名区分字母大小写;变量名必须以字母打头,其后可以是任意字母,数字,或下划线的组合。
实验六MATLAB数据可视化实验者:祝松年级:机设092 学号:09405701002一、实验目的掌握 MATLAB 二维、三维图形绘制,掌握图形属性的设置和图形修饰;掌握图像文件的读取和显示。
二、实验内容(1) 二维图形绘制。
(2) 三维曲线和三维曲面绘制。
(3) 图像文件的读取和显示。
三、实验步骤1 .二维图形绘制(1) 二维图形绘制主要使用函数 plot 。
>>clear all;>> x=linspace(0,2*pi,100);>> y1=sin(x);>> plot(x,y)>> hold on % 保持原有的图形>> y2=cos(x)>> plot(x,y)注: hold on 用于保持图形窗口中原有的图形, hold off 解除保持。
(2) 函数 plot 的参数也可以是矩阵。
>>close all % 关闭所有图形窗口>>x=linspace(0,2*pi,100);>> y1=sin(x);>> y2=cos(x);>> A=[y1 ; y2]'; % 把矩阵转置>> B=[x ; x]'>> plot(B,A)(3) 选用绘图线形和颜色。
>> close all % 关闭所有图形窗口>> plot(x,y1,'g+',x,y2, 'r:')>> grid on % 添加网格线(4) 添加文字标注。
>> title(' 正弦曲线和余弦曲线 ')>> ylabel(' 幅度 ')>> xlabel(' 时间 ')>> legend('sin(x)', 'cos(x)')>> gtext('\leftarrowsinx') % 可用鼠标选择标注的位置,%\leftarrow 产生左箭头,‘\’为转义符(5) 修改坐标轴范围。
matlab实验报告总结电气工程学院自动化102班 2012年12月21日实验一 MATLAB环境的熟悉与基本运算一、实验目的1.熟悉MATLAB开发环境2.掌握矩阵、变量、表达式的各种基本运算二、实验基本知识1.熟悉MATLAB环境MATLAB桌面和命令窗口、命令历史窗口、帮助信息浏览器、工作空间浏览器、文件和搜索路径浏览器。
2.掌握MATLAB常用命令变量与运算符变量命名规则如下:变量名可以由英语字母、数字和下划线组成变量名应以英文字母开头长度不大于31个区分大小写MATLAB中设置了一些特殊的变量与常量,列于下表。
MATLAB运算符,通过下面几个表来说明MATLAB的各种常用运算符表2 MATLAB算术运算符表3 MATLAB关系运算符表4 MATLAB逻辑运算符表5 MATLAB特殊运算的一维、二维数组的寻访表6 子数组访问与赋值常用的相关指令格式的基本运算表7 两种运算指令形式和实质内涵的异同表的常用函数表8 标准数组生成函数表9 数组操作函数三、实验内容1、新建一个文件夹2、启动,将该文件夹添加到MATLAB路径管理器中。
3、保存,关闭对话框4、学习使用help命令,例如在命令窗口输入help eye,然后根据帮助说明,学习使用指令eye5、学习使用clc、clear,观察command window、command history和workspace等窗口的变化结果。
6、初步程序的编写练习,新建M-file,保存,学习使用MATLAB的基本运算符、数组寻访指令、标准数组生成函数和数组操作函数。
注意:每一次M-file的修改后,都要存盘。
练习A:help rand,然后随机生成一个2×6的数组,观察command window、command history和workspace等窗口的变化结果。
学习使用clc、clear,了解其功能和作用。
答:clc是清除命令窗体内容 clear是清除工作区间输入C=1:2:20,则C表示什么?其中i=1,2,3,?,10。
实验报告一、实验目的通过这些题目的训练,需要掌握静态数据成员以及静态成员函数的使用方法,友元函数的使用,以及掌握构造函数和析构函数,拷贝构造函数、内联成员函数、聚集的使用,熟练的使用类解决问题。
二、实验环境编译器:Visual c++6.0操作系统:Windows XP三、实验题目基础题1:题目:定义一个Cat类,拥有静态数据成员HowManyCats,记录Cat的个体数目;静态成员函数GetHowMany(),存取HowManyCats。
设计程序测试这个类,体会静态数据成员和静态成员函数的用法。
分析:定义一个名为Cat类,静态数据成员HowManyCats,记录Cat的个体数目,静态成员函数GetHowMany(),输入一只Cat的名字就让HowManyCats加1,调用静态成员函数GetHowMany()输出数目即可。
核心代码:#include<iostream>using namespace std;class Cat//定义一个Cat类{public:Cat(char Name)//定义一个构造函数,形参为Cat的名字{CatName=Name;HowManyCats++;}static void GetHowMany(){cout<<"the number of cats: "<<HowManyCats<<endl;}private:char CatName;static int HowManyCats;};int Cat::HowManyCats=0;//静态数据成员声明void main(){char _name;int W=0;{ cout<<"please input the name of one cat(一个字母):"<<endl;cin>>_name;W=1;Cat c(_name);cout<<"if you want to contiue to input cat,please input 0 or else input 1."<<endl;cin>>W;}while(W==0);Cat::GetHowMany();//静态成员函数调用}程序运行及截图:总结:掌握静态成员函数的定义与实现,以及静态数据成员的声明、定义和初始化方法,学会使用类解决实际问题。
学生实验报告一、实验目的1、掌握SIMULINK组件模块操作的基本方法;2、掌握常用连续系统模块的使用方法;3、掌握连续系统建模的基本方法;4、理解SIMULINK仿真的基本配置方法与内在运行机制。
二、实验原理Simulink是MATLAB的重要组成部分,提供建立系统模型、选择仿真参数和数值算法、启动仿真程序对该系统进行仿真、设置不同的输出方式来观察仿真结果等功能。
1、Simulink的基本模块Simulink的模块库提供了大量模块。
单击模块库浏览器中Simulink前面的“+”号,将看到Simulink模块库中包含的子模块库,单击所需要的子模块库,在右边的窗口中将看到相应的基本模块,选择所需基本模块,可用鼠标将其拖到模型编辑窗口。
同样,在模块库浏览器左侧的Simulink栏上单击鼠标右键,在弹出的快捷菜单中单击Open the ‘Simulink’ Libray 命令,将打开Simulink基本模块库窗口。
单击其中的子模块库图标,打开子模块库,找到仿真所需要的基本模块。
Simulink中几乎所有模块的参数都允许用户进行设置,只要双击要设置的模块或在模块上按鼠标右键并在弹出的快捷菜单中选择相应模块的参数设置命令就会弹出模块参数对话框。
该对话框分为两部分,上面一部分是模块功能说明,下面一部分用来进行模块参数设置。
同样,先选择要设置的模块,再在模型编辑窗口Edit菜单下选择相应模块的参数设置命令也可以打开模块参数对话框。
一个Simulink仿真模型的基本模块包括信源、信宿以及系统三个部分。
其中,信源可以是常数、正弦波、阶梯波等信号源,信宿可以是示波器、图形记录仪等,系统则是被研究系统的SIMULINK方框图。
系统、信源、信宿,可以从SIMULINK模块库中直接获得,也可以根据用户意愿用库中的模块构建而成。
2、连续系统的建模与仿真连续系统指的是可以用微分方程来描述的系统。
用于建模连续系统的模块:Simulink模块组中的Continous、Math以及Nonlinear模块库中。
《MATLAB程序设计与应用》实验指导书实验一 matlab 集成环境使用与运算基础1,先求下列表达式的值,然后显示matlab 工作空间的使用情况并保存全部变量。
(1)0122sin851z e =+程序:.>> z1=2*sin(85*pi/180)/(1+exp(2)) 结果: z1 =0.2375(2)22121(0.4552i z In x x +⎡⎤=+=⎢⎥-⎣⎦其中 程序:>> x=[2,1+2*i;-0.45,5];>> z2=0.5*log(x+sqrt(1+x*x)) 结果: z2 =0.7114 - 0.0253i 0.8968 + 0.3658i 0.2139 + 0.9343i 1.1541 - 0.0044i(3)0.3,9.2,8.2,...,8.2,9.2,0.3,23.0)3.0sin(23.03.03---=+++-=-a aIn a e e z a a 提示:利用冒号表达式生成a 向量,求各点函数值时用点乘运算。
程序:>> a=-3.0:0.1:30;>> z3=(exp(0.3*a)-exp(-0.3*a))/2.*sin((a+0.3)*pi/180)+log((0.3+a)/2) 结果: z3 =1.0e+003 *Columns 1 through 40.0003 + 0.0031i 0.0003 + 0.0031i 0.0003 + 0.0031i 0.0002 + 0.0031iColumns 5 through 80.0002 + 0.0031i 0.0001 + 0.0031i 0.0001 + 0.0031i 0.0000 + 0.0031i Columns 9 through 12-0.0000 + 0.0031i -0.0001 + 0.0031i -0.0001 + 0.0031i -0.0002 + 0.0031i Columns 13 through 16-0.0003 + 0.0031i -0.0003 + 0.0031i -0.0004 + 0.0031i -0.0005 + 0.0031i Columns 17 through 20-0.0006 + 0.0031i -0.0007 + 0.0031i -0.0008 + 0.0031i -0.0009 + 0.0031i Columns 21 through 24-0.0010 + 0.0031i -0.0012 + 0.0031i -0.0014 + 0.0031i -0.0016 + 0.0031i Columns 25 through 28-0.0019 + 0.0031i -0.0023 + 0.0031i -0.0030 + 0.0031i -0.0370 Columns 29 through 32-0.0030 -0.0023 -0.0019 -0.0016 Columns 33 through 36-0.0014 -0.0012 -0.0010 -0.0009 Columns 37 through 40-0.0008 -0.0007 -0.0006 -0.0005 Columns 41 through 44-0.0004 -0.0003 -0.0003 -0.0002 Columns 45 through 48-0.0001 -0.0001 -0.0000 0.0000 Columns 49 through 520.0001 0.0001 0.0002 0.0002 Columns 53 through 560.0003 0.0003 0.0003 0.0004 Columns 57 through 600.0004 0.0005 0.0005 0.0005 Columns 61 through 640.0006 0.0006 0.0006 0.0007 Columns 65 through 680.0007 0.0007 0.0008 0.0008 Columns 69 through 720.0008 0.0008 0.0009 0.0009 Columns 73 through 760.0009 0.0010 0.0010 0.0010 Columns 77 through 800.0011 0.0011 0.0011 0.0011 Columns 81 through 840.0012 0.0012 0.0012 0.0013 Columns 85 through 880.0013 0.0013 0.0013 0.0014 Columns 89 through 920.0014 0.0014 0.0015 0.0015 Columns 93 through 960.0015 0.0016 0.0016 0.0016 Columns 97 through 1000.0017 0.0017 0.0017 0.0018 Columns 101 through 1040.0018 0.0018 0.0019 0.0019 Columns 105 through 1080.0020 0.0020 0.0020 0.0021 Columns 109 through 1120.0021 0.0022 0.0022 0.0023 Columns 113 through 1160.0023 0.0024 0.0024 0.0025 Columns 117 through 1200.0025 0.0026 0.0026 0.0027 Columns 121 through 1240.0027 0.0028 0.0029 0.0029 Columns 125 through 1280.0030 0.0031 0.0031 0.0032 Columns 129 through 1320.0033 0.0034 0.0034 0.0035 Columns 133 through 1360.0036 0.0037 0.0038 0.0039 Columns 137 through 1400.0040 0.0041 0.0042 0.0043 Columns 141 through 1440.0044 0.0045 0.0046 0.0047 Columns 145 through 1480.0049 0.0050 0.0051 0.0053 Columns 149 through 1520.0054 0.0056 0.0057 0.0059 Columns 153 through 1560.0060 0.0062 0.0064 0.0066 Columns 157 through 1600.0068 0.0069 0.0071 0.0074 Columns 161 through 1640.0076 0.0078 0.0080 0.0083 Columns 165 through 1680.0085 0.0088 0.0090 0.0093 Columns 169 through 1720.0096 0.0099 0.0102 0.0105 Columns 173 through 1760.0108 0.0112 0.0115 0.0119 Columns 177 through 1800.0123 0.0127 0.0131 0.0135 Columns 181 through 1840.0139 0.0144 0.0148 0.0153 Columns 185 through 1880.0158 0.0163 0.0168 0.0174 Columns 189 through 1920.0180 0.0185 0.0191 0.0198 Columns 193 through 1960.0204 0.0211 0.0218 0.0225 Columns 197 through 2000.0233 0.0241 0.0249 0.0257 Columns 201 through 2040.0265 0.0274 0.0284 0.0293 Columns 205 through 2080.0303 0.0313 0.0324 0.0335 Columns 209 through 2120.0346 0.0358 0.0370 0.0382 Columns 213 through 2160.0395 0.0409 0.0423 0.0437 Columns 217 through 2200.0452 0.0467 0.0483 0.0500 Columns 221 through 2240.0517 0.0534 0.0552 0.0571 Columns 225 through 2280.0591 0.0611 0.0632 0.0654 Columns 229 through 2320.0676 0.0699 0.0723 0.0748 Columns 233 through 2360.0773 0.0800 0.0827 0.0856 Columns 237 through 2400.0885 0.0915 0.0947 0.0979 Columns 241 through 2440.1013 0.1047 0.1083 0.1121 Columns 245 through 2480.1159 0.1199 0.1240 0.1282 Columns 249 through 2520.1326 0.1372 0.1419 0.1467 Columns 253 through 2560.1518 0.1570 0.1624 0.1679 Columns 257 through 2600.1737 0.1796 0.1858 0.1921 Columns 261 through 2640.1987 0.2055 0.2125 0.2198 Columns 265 through 2680.2273 0.2351 0.2431 0.2514 Columns 269 through 2720.2600 0.2689 0.2781 0.2876 Columns 273 through 2760.2974 0.3076 0.3180 0.3289 Columns 277 through 2800.3401 0.3517 0.3637 0.3761 Columns 281 through 2840.3889 0.4021 0.4158 0.4299 Columns 285 through 2880.4446 0.4597 0.4753 0.4915 Columns 289 through 2920.5082 0.5254 0.5433 0.5617 Columns 293 through 2960.5807 0.6004 0.6208 0.6418 Columns 297 through 3000.6636 0.6861 0.7093 0.7333 Columns 301 through 3040.7581 0.7838 0.8103 0.8377 Columns 305 through 3080.8660 0.8952 0.9254 0.9567 Columns 309 through 3120.9890 1.0223 1.0568 1.0924 Columns 313 through 3161.1292 1.1673 1.2066 1.2472Columns 317 through 3201.2892 1.3326 1.3774 1.4237Columns 321 through 3241.4715 1.5210 1.5721 1.6249Columns 325 through 3281.6794 1.7357 1.7940 1.8541Columns 329 through 3311.9163 1.98052.0468(4)⎪⎩⎪⎨⎧=<≤<≤<≤+--=5.2:5.0:0,322110,121,2224t t t t t t t t z 其中提示:用逻辑表达式求分段函数值。
MATLAB上机实验一一、实验目的初步熟悉MATLAB 工作环境,熟悉命令窗口,学会使用帮助窗口查找帮助信息。
命令窗口二、实验内容(1) 熟悉MATLAB 平台的工作环境。
(2) 熟悉MATLAB 的5 个工作窗口。
(3) MATLAB 的优先搜索顺序。
三、实验步骤1. 熟悉MATLAB 的5 个基本窗口①Command Window (命令窗口)②Workspace (工作空间窗口)—③Command History (命令历史记录窗口)④Current Directory (当前目录窗口)⑤Help Window (帮助窗口)(1) 命令窗口(Command Window)。
在命令窗口中依次输入以下命令:>>x=1>> y=[1 2 34 5 67 8 9];>> z1=[1:10],z2=[1:2:5];>> w=linspace(1,10,10);>> t1=ones(3),t2=ones(1,3),t3=ones(3,1)>> t4=ones(3),t4=eye(4)x =1z1 =1 2 3 4 5 6 7 8 9 10 t1 =1 1 11 1 11 1t2 =1 1 1t3 =111t4 =1 1 11 1 11 1 1t4 =1 0 0 00 1 0 00 0 1 00 0 0 1思考题:①变量如何声明,变量名须遵守什么规则、是否区分大小写。
答:(1)变量声明1.局部变量每个函数都有自己的局部变量,这些变量只能在定义它的函数内部使用。
当函数运行时,局部变量保存在函数的工作空间中,一旦函数退出,这些局部变量将不复存在。
脚本(没有输入输出参数,由一系列MATLAB命令组成的M文件)没有单独的工作空间,只能共享调用者的工作空间。
当从命令行调用,脚本变量存在基本工作空间中;当从函数调用,脚本变量存在函数空间中。
2.全局变量在函数或基本工作空间内,用global声明的变量为全局变量。
《MATLAB 课程》课程实习报告(一) 实习日期:2016-9-13学院:数学与统计学院学院 专业:数学与应用数学 姓名:王子璇 学号:201413230061, 先求下列表达式的值,然后显示MATLAB 工作空间的使用情况,并保存全部变量。
(1)21185sin 2ez +=代码:>> z1=2*sin(85*pi/180)/(1+exp(2))截图:(3)()0.3,9.2,8.2,...,8.29.2,0.3,233.0ln 3.0sin 23.03.03---=+++-=-a a a e e z a a 提示:利用冒号表达式生成a 向量,求各点的函数值时用点乘运算。
代码:>> a=-3.0:0.1:3.0;>> z3=(exp(0.3*a)-exp(-0.3*a))/2.*sin(a+0.3)+log((0.3+a)/2)截图:(4)5.2:5.0:0其中,32,1221,110,2224=⎪⎩⎪⎨⎧<≤+-<≤-<≤=t t t t t t t t z提示:用逻辑表达式求分段函数值。
代码:>> t=0:0.5:2.5;>> z4=t.^2.*(t>=0&t<1)+(t.^2-1).*(t>=1&t<2)+(t.^2-2*t+1).*(t>=2&t<3)截图:2, 设有矩阵A 和B⎥⎥⎥⎥⎥⎥⎦⎤⎢⎢⎢⎢⎢⎢⎣⎡=25242322212019181716151413121110987654321A ,⎥⎥⎥⎥⎥⎥⎦⎤⎢⎢⎢⎢⎢⎢⎣⎡--=11134079423096171603B (1) 求它们的乘积C 。
(2) 将矩阵C 的右下角23⨯子矩阵赋给D 。
(3) 查看MATLAB 工作空间的使用情况。
代码:(1)>> A=[1 2 3 4 5;6 7 8 9 10;11 12 13 14 15;16 17 18 19 20;21 22 23 24 25]>> B=[3 0 16;17 -6 9;0 23 -4;9 7 0;4 13 11]>> C=A*B(2)>> F=size(C);>> D=C(F(1)-2:F(1),F(2)-1:F(2));>> whos截图:(1)(2)3,下面是一个线性方程组:⎥⎥⎥⎦⎤⎢⎢⎢⎣⎡=⎥⎥⎥⎦⎤⎢⎢⎢⎣⎡⎥⎥⎥⎦⎤⎢⎢⎢⎣⎡52.067.095.061141514111121321x x x(1) 求方程的解。
MATLAB第六次上机实验报告0210901班学号2009210811 姓名:李贤凤Quiz 3.1>> a=20;>> b=-2;>> c=0;>> d=1;>> a>bans =1>> b>dans =>> a>b&c>dans =>> a==bans =>> a&b>cans =>> ~~bans =1>> a=2;>> b=[1 -2;-0 10];>> c=[0 1;2 0];>> d=[-2 1 2;0 1 0];>> ~(a>b)ans =0 00 1>> a>c&b>cans =1 00 1>> c<=d??? Error using ==> <=Matrix dimensions must agree.>> a=2;>> b=3;>> c=10;>> d=0;>> a*b^2>a*cans =>> d|b>aans =1>> (d|b)>aans =>> a=20;>> b=-2;>> c=0;>> d='Test';>> isinf(a/b)ans =>> isinf(a/c)Warning: Divide by zero.(Type "warning off MATLAB:divideByZero" to suppress this warning.)ans =1>> a>b&ischar(d)ans =1>> isempty(c)ans =Quiz3.21.% Script file : Sqrt_x.m% Purpose:% This program is used to calculate the square root of a randem number% Record of revisions:% Date Programmer Description of change % === ======== ================ % 10/22/2010 lixianfeng Original code% Define variables :% x --x is a randem number% y --y is a function of the sqrt(x)% Prompt the user for the value xx=input('Enter the number of x:');% Calculate the function sqrt(x)if x>=0y=sqrt(x);fprintf('The square root of x is:%f',y);elsedisp('It is an error message about the square root function ');disp('The value of sqrt is 0');endexample:test aEnter the number of x:5The square root of x is: 2.236068Enter the number of x:-2It is an error message about the square root functionThe value of sqrt is 02. % Script file : Scores.m% Purpose:% This program is used to calculate the numerator / denominator% Record of revisions:% Date Programmer Description of change% ==== ========== =================== % 10/22/2010 Li xianfeng Original code% Define variables :% fun --fun is calculated as numerator / denominator% Prompt the user for the value numerator and denominatornumerator=input('Enter the numerator:');denominator=input('Enter the denominator:');% Calculate the function numerator / denominatorif abs(denominator)>=1.0E-300fun=numerator / denominator ;fprintf('The numerator / denominator is:%f',fun);elsedisp('Divide by 0 error ');endexample: >> test cEnter the numerator:4Enter the denominator:6The numerator / denominator is0.666667>> test cEnter the numerator:3Enter the denominator:-5E-400Divide by 0 error3. % Script file :cost.m% Purpose:% This program is used to calculate the cost per mile for a rented vehicle% Record of revisions:% Date Programmer Description of change% ==== ========== =================== % 10/22/2010 Li xianfeng Original code% Define variables :% d --d is the distance% aver --the average cost per mile% Prompt the user for the value distanced=input('Enter the distance:');% Calculate the functionif d>300disp('The cost per mile for a tented vehicleis $0.20 ');elseif d>100aver=(100*0.50+(d-100)*0.30)/d;disp(['The average cost per mile is ' num2str(aver)]);elseif d>=0disp('The average cost per mile is $0.50');elsedisp('The distance should be 0 or positive number ');endexample: Enter the distance:325The cost per mile for a tented vehicleis $0.20>> test3Enter the distance:158The average cost per mile is 0.42658>> test3Enter the distance:38The average cost per mile is $0.50>> test3Enter the distance:-23The distance should be 0 or positive number4. if volts>125disp('WARNING:High voltage on line.');if volts<105disp('WARNING:Low voltage on line.');elsedisp('Line voltage is within tolerances.');endAns:There is no …Input‟ sentence and the second “if” should be replaced by “elseif” or adda “end” at the end of program..5. color = 'yellow';switch (color)case 'red',disp('stop now!');case 'yellow',disp('prepare to stop.');case 'green',disp('proceed through intersection.');otherwise,disp('illegal color encountered.');endAns: prepare to stop.6. if temperature>100disp('human body temperature exceeded.');elseif temperature>37disp('boiling point of water exceeded.');endAns: Undefined function or variable 'temperature'.3.8 Exercises:3.1% Script file :tan(theta).m% Purpose:% This program is used to evaluate the tangent function% tan_theta=sin(theta)/cos(theta)% Record of revisions:% Date Programmer Description of change% ==== ========== ================% 10/22/2010 Li xianfeng Original code% Define variables :% theta --the angle% tan --the tangent function% sin --the tangent function% cos --the tangent function% Prompt the user for the value thetatheta=input('Enter the theta:');% Calculate the functionif cos(theta)<1e-20disp('error message');elsetan_theta=sin(theta)/cos(theta);disp(['The tan_theta is ' num2str(tan_theta)]);endexample: Enter the theta:5error message>> test3_1Enter the theta:0.05The tan_theta is 0.0500423.2 Ans:The logical order is wrong,the last”elseif” shoude be corrected by “else”and there lack aintput sentence.if temp>103.0disp('Temperature dangerously high');elseif temp>99.5disp('Temperature slightly high');elseif temp>97.5disp('Temperature normal');else temp<97.5disp('Temperature below normal');endexample: enter the Temperature:88temp =88Temperature below normalenter the Temperature:98temp =98Temperature normalenter the Temperature:101temp =101Temperature slightly highenter the Temperature:121temp =121Temperature dangerously high3.3 % Script file :cost.m% Purpose:% This program is used to calculate the cost of sending a package% Record of revisions:% Date Programmer Description of change% ==== ========== =================== % 10/22/2010 Li xianfeng Original code% Define variables :% weight --the weight of package% cost --the cost of sending a package% Prompt the user for the value weightweight=input('Enter the weight:');% Calculate the functionif weight>100disp('the package is not accepted!!!');elseif weight>70cost=10+3.75*68+(weight-70);disp(['The cost of sending a package is $' num2str(cost)]);elseif weight>2cost=10+3.75*(weight-2);disp(['The cost of sending a package is $' num2str(cost)]);elseif weight>0cost=10;disp('The cost of sending a package is $10.00' );elsedisp('the weight can‟t be a negative number.')end3.4 % Script file :funxy.m% Purpose:% This program is solving the function f(x,y) for a user-specified x and y% ,where f(x,y) is defined as:% -% | x+y x>=0 and y>=0% f(x,y)= | x+y^2 x>=0 and y<0% | x^2+y x<0 and y>=0% | x^2+y^2 x<0 and y<0% -% Record of revisions:% Date Programmer Description of change % ==== ========== =============== % 10/22/2010 LI xianfeng Original code% Define variables :% x --the first independent variable% y --the second independent variable% fun --resulting function% Prompt the user for the value xx=input('Enter the x coefficient:');y=input('Enter the y coefficient:');% Calculate the function fun(x,y) based on the signs of x and y.if x>=0 & y>=0fun=x+y;elseif x>=0 & y<0fun=x+y^2 ;elseif x<0 & y>=0fun=x^2+y;elsefun=x^2+y^2;endendend% write the value of the functiondisp(['the value of the function is ' num2str(fun)]);3.5 % Script file :lnx.m% Purpose:% This program is solving the function ln(1/(1-x)) for a user-specified x and y% Record of revisions:% Date Programmer Description of change% ==== ========== =================== % 10/22/2010 Li xianfeng Original code% Define variables :% x --the independent variable% y --the function of ln(1/(1-x))% ln --the natural logarithm,the logarithm to the base e.% Prompt the user for the value xx=input('Enter the x :');% Calculate the function ln(1/(1-x)) based upon the signs of x .if x<1y=log(1/(1-x));disp(['the value of ln(1/(1-x)) is;' num2str(y)]);elsedisp('the variable must be positive number.');endexample: Enter the x :-9the value of ln(1/(1-x)) is;-2.3026Enter the x :8the variable must be positive number。