matlab实验报告模板

合集下载

MATLAB实验报告

MATLAB实验报告

实验一MATLAB操作基础实验目的和要求:1、熟悉MATLAB的操作环境及基本操作方法。

2、掌握MATLAB的搜索路径及设置方法。

3、熟悉MATLAB帮助信息的查阅方法实验内容:1、建立自己的工作目录,再设置自己的工作目录设置到MA TLAB搜索路径下,再试验用help命令能否查询到自己的工作目录。

2、在MA TLAB的操作环境下验证课本;例1-1至例1-4,总结MATLAB的特点。

例1-1例1-2例1-3例1-43、利用帮助功能查询inv、plot、max、round等函数的功能。

4、完成下列操作:(1)在matlab命令窗口输入以下命令:x=0:pi/10:2*pi;y=sin(x);(2)在工作空间窗口选择变量y,再在工作空间窗口选择回绘图菜单命令或在工具栏中单击绘图命令按钮,绘制变量y的图形,并分析图形的含义。

5、访问mathworks公司的主页,查询有关MATLAB的产品信息。

主要教学环节的组织:教师讲授实验目的、开发环境界面、演示实验过程,然后同学上机练习。

思考题:1、如何启动与退出MA TLAB集成环境?启动:(1)在windows桌面,单击任务栏上的开始按钮,选择‘所有程序’菜单项,然后选择MA TLAB程序组中的MA TLABR2008b程序选项,即可启动MATLAB系统。

(2)在MA TLAB的安装路径中找到MA TLAB系统启动程序matlab.exe,然后运行它。

(3)在桌面上建立快捷方式后。

双击快捷方式图标,启动MA TLAB。

退出:(1)在MA TLAB主窗口file菜单中选择exitMATLAB命令。

(2)在MA TLAB命令窗口中输入exit或quit命令。

(3)单击MATLAB主窗口的关闭按钮。

2、简述MATLAB的主要功能。

MATLAB是一种应用于科学计算领域的数学软件,它主要包括数值计算和符号计算功能、绘图功能、编程语言功能以及应用工具箱的扩展功能。

3、如果一个MATLAB命令包含的字符很多,需要分成多行输入,该如何处理?使用‘;’隔开4、Help命令和lookfor命令有何区别?help是显示matlab内置的帮助信息一般是help 命令;而lookfor 关键词是通过关键词查找,“关键词”就是你要找的词语5、在MA TLAB环境下,建立了一个变量fac,同时又在当前目录下建立了一个m文件fac.m,如果需要运行fac.m文件,该如何处理?实验二MATLAB矩阵及运算实验目的和要求:1、掌握MATLAB数据对象的特点及运算规则2、掌握MATLAB建立矩阵的方法及矩阵处理的方法3、掌握MATLAB分析的方法实验内容:1.求下列表达式的值(1)(2)(3)(4)2.已知A=[-1,5,-4;0,7,8;3,61,7],B=[8,3,-1;2,5,3;-3,2,0] 求下列表达式的值:(1)A+6B和A^2-B+I(其中I为单位矩阵)。

MATLAB实验报告

MATLAB实验报告

MATLAB实验报告一、实验目的本次 MATLAB 实验旨在深入了解和掌握 MATLAB 软件的基本操作和应用,通过实际编程和数据处理,提高解决问题的能力,培养编程思维和逻辑分析能力。

二、实验环境本次实验使用的是 MATLAB R2020a 版本,运行在 Windows 10 操作系统上。

计算机配置为英特尔酷睿 i5 处理器,8GB 内存。

三、实验内容(一)矩阵运算1、矩阵的创建使用直接输入、函数生成和从外部文件导入等方式创建矩阵。

例如,通过`1 2 3; 4 5 6; 7 8 9` 直接输入创建一个 3 行 3 列的矩阵;使用`ones(3,3)`函数创建一个 3 行 3 列元素全为 1 的矩阵。

2、矩阵的基本运算包括矩阵的加减乘除、求逆、转置等。

例如,对于两个相同维度的矩阵`A` 和`B` ,可以进行加法运算`C = A + B` 。

3、矩阵的特征值和特征向量计算通过`eig` 函数计算矩阵的特征值和特征向量,加深对线性代数知识的理解和应用。

(二)函数编写1、自定义函数使用`function` 关键字定义自己的函数,例如编写一个计算两个数之和的函数`function s = add(a,b) s = a + b; end` 。

2、函数的调用在主程序中调用自定义函数,并传递参数进行计算。

3、函数的参数传递了解值传递和引用传递的区别,以及如何根据实际需求选择合适的参数传递方式。

(三)绘图功能1、二维图形绘制使用`plot` 函数绘制简单的折线图、曲线等,如`x = 0:01:2pi; y = sin(x); plot(x,y)`绘制正弦曲线。

2、图形的修饰通过设置坐标轴范围、标题、标签、线条颜色和样式等属性,使图形更加清晰和美观。

3、三维图形绘制尝试使用`mesh` 、`surf` 等函数绘制三维图形,如绘制一个球面`x,y,z = sphere(50); surf(x,y,z)`。

(四)数据处理与分析1、数据的读取和写入使用`load` 和`save` 函数从外部文件读取数据和将数据保存到文件中。

基于matlab的实验报告

基于matlab的实验报告

基于matlab的实验报告实验报告:基于MATLAB 的实验一、实验目的通过使用MATLAB 软件,掌握如何进行数据分析、图像处理、算法实现等一系列实验操作,提高实验者的实践能力和动手能力。

二、实验原理MATLAB 是一种在科学计算和技术开发领域广泛应用的计算机软件。

它能进行矩阵计算、绘制函数和数据图像、实现算法以及进行数据分析等。

通过掌握MATLAB 的使用,能够快速、高效地解决各种科学和工程问题。

三、实验内容1. 数据分析:使用MATLAB 的数据分析工具进行数据的导入、处理和分析。

2. 图像处理:利用MATLAB 的图像处理工具包对图像进行滤波、增强、分割等操作。

3. 算法实现:使用MATLAB 实现常用的算法,如排序、搜索、图像压缩等。

四、实验步骤1. 数据分析:(1)使用MATLAB 的读取数据函数将数据导入MATLAB 环境中。

(2)利用MATLAB 的数据处理函数进行数据清洗和预处理。

(3)使用MATLAB 的统计工具进行数据分析,如求平均值、标准差等。

(4)利用MATLAB 的绘图函数将分析结果可视化。

2. 图像处理:(1)使用MATLAB 的读取图像函数将图像导入MATLAB 环境中。

(2)利用MATLAB 的图像处理工具包进行滤波操作,如均值滤波、中值滤波等。

(3)使用MATLAB 的图像增强函数对图像进行锐化、变换等操作。

(4)利用MATLAB 的图像分割算法对图像进行分割。

3. 算法实现:(1)使用MATLAB 编写排序算法,如冒泡排序、快速排序等。

(2)使用MATLAB 编写搜索算法,如二分查找、线性搜索等。

(3)使用MATLAB 实现图像压缩算法,如离散余弦变换(DCT)。

五、实验结果实验中,我们使用MATLAB 完成了数据分析、图像处理和算法实现的一系列实验操作。

通过数据分析,我们成功导入了数据并对其进行了清洗和预处理,最后得到了数据的统计结果。

在图像处理方面,我们对图像进行了滤波、增强和分割等操作,最终得到了处理后的图像。

程序设计实验报告(matlab)

程序设计实验报告(matlab)

程序设计实验报告(matlab)实验一: 程序设计基础实验目的:初步掌握机器人编程语言Matlab。

实验内容:运用Matlab进行简单的程序设计。

实验方法:基于Matlab环境下的简单程序设计。

实验结果:成功掌握简单的程序设计和Matlab基本编程语法。

实验二:多项式拟合与插值实验目的:学习多项式拟合和插值的方法,并能进行相关计算。

实验内容:在Matlab环境下进行多项式拟合和插值的计算。

实验方法:结合Matlab的插值工具箱,进行相关的计算。

实验结果:深入理解多项式拟合和插值的实现原理,成功掌握Matlab的插值工具箱。

实验三:最小二乘法实验目的:了解最小二乘法的基本原理和算法,并能够通过Matlab进行计算。

实验内容:利用Matlab进行最小二乘法计算。

实验方法:基于Matlab的线性代数计算库,进行最小二乘法的计算。

实验结果:成功掌握最小二乘法的计算方法,并了解其在实际应用中的作用。

实验六:常微分方程实验目的:了解ODE的基本概念和解法,并通过Matlab进行计算。

实验内容:利用Matlab求解ODE的一阶微分方程组、变系数ODE、高阶ODE等问题。

实验方法:基于Matlab的ODE工具箱,进行ODE求解。

实验结果:深入理解ODE的基本概念和解法,掌握多种ODE求解方法,熟练掌握Matlab的ODE求解工具箱的使用方法。

总结在Matlab环境下进行程序设计实验,使我对Matlab有了更深刻的认识和了解,也使我对计算机科学在实践中的应用有了更加深入的了解。

通过这些实验的学习,我能够灵活应用Matlab进行各种计算和数值分析,同时也能够深入理解相关的数学原理和算法。

这些知识和技能对我未来的学习和工作都将有着重要的帮助。

matlab实验报告

matlab实验报告
(1)信号形式 ,利用plot命令绘制该信号在 区间内,且采样间隔为 的曲线。添加网格线,标题为“正弦信号曲线”,横坐标显示“x”,纵坐标显示“y”。
(2)将上述信号左平移或右平移 得到两个新信号y2和y3,利用hold命令在同一图中显示三条曲线并通过线型和颜色加以区分。
(3)利用subplot命令将y,y2和y3以子图的形式显示。
3.
实验结果及分析
1.(1)
t1 =
0.0780
实验结果及分析
(2)
t2 =
0.0780
实验结果及分析
(3)
t3 =
0
实验结果及分析
2.
实验
名称
实验四Matlab在通信系统中的应用
实验目的
1、练习通信原理中各种调制方法及简单通信系统的Matlab编程实现;
2、学习Matlab与Simulink的混合编程。
(2)y变成虚数后,重复上述运算。
(3)创建矩阵 ,并进行如下操作,取出矩阵A的前两行元素,生成一个新矩阵B。生成一个3*3的单位矩阵B,与矩阵A进行加、减、乘、除、相等、不相等运算。
(4)随机生成2个复数x1和x2,计算x3=x1÷x2,x3的实部real_x3、虚部image_x3、模abs_x3、幅角angle_x3,并把x1,x2,x3,real_x3,image_x3,abs_x3,angle_x3保存至文件complex_学号.mat。利用save命令保存数据为mat格式文件后,用clear命令清除工作空间中的变量,再利用load命令从文件读入数据。
2、流程控制语句相关操作。
(1)使用for语句及while语句求解1至100整数中奇数的和。
(2)求连续自然数的和,当和大于等于1000时,求最后一个自然数以及自然数的和。

初识MATLAB的实验报告

初识MATLAB的实验报告

初识MATLAB的实验报告1. 引言MATLAB(Matrix Laboratory)是一种高级的技术计算环境和编程语言。

它具有强大的矩阵计算能力和丰富的科学和工程绘图功能,被广泛应用于各个领域的科研与工程实践中。

本实验旨在初步了解MATLAB的基本语法和功能,通过实际操作加深对MATLAB编程的理解。

2. 实验目的1. 掌握MATLAB的安装和基本使用方法;2. 学习MATLAB中的常用数学函数和操作;3. 了解MATLAB绘图功能并能够绘制简单的图形。

3. 实验步骤3.1 MATLAB安装首先,在官方网站(3.2 MATLAB入门3.2.1 MATLAB语法MATLAB的语法类似于其他常见的编程语言,每个语句以分号结尾。

在MATLAB 中,可以直接进行基本的数学运算,例如加减乘除、指数、对数等。

通过以下代码可以计算两个变量的和并将结果打印出来:matlaba = 10;b = 20;sum = a + b;disp(sum);3.2.2 MATLAB变量在MATLAB中,可以创建和操作各种类型的变量,例如数值、字符串、矩阵等。

以下代码演示了如何创建一个矩阵:matlabmatrix = [1, 2, 3; 4, 5, 6; 7, 8, 9];disp(matrix);3.2.3 MATLAB函数MATLAB提供了许多内置的数学函数,可以直接调用。

以下代码演示了如何计算正弦函数值并打印结果:matlabx = pi/4;y = sin(x);disp(y);3.3 MATLAB绘图MATLAB具有强大的绘图功能,可以绘制各种图形,如曲线、散点图、柱状图等。

以下代码演示了如何绘制一个简单的正弦曲线:matlabx = linspace(0, 2*pi, 100);y = sin(x);plot(x, y);xlabel('x');ylabel('y');title('Sine Curve');4. 实验结果与分析在完成上述实验步骤后,我们成功安装了MATLAB,并学习了基本的语法、变量和函数的使用方法。

MATLAB实验报告(8个实验)

MATLAB实验报告(8个实验)

四川师范大学MATLAB语言实验报告1系级班年月日实验名称:Intro, Expressions, Commands姓名学号指导教师成绩1ObjectiveThe objective of this lab is to familiarize you with the MATLAB program development environment and to develop your first programs in this environment.2Using MATLAB2.1Starting MATLABLogon to your computer and start MATLAB by double-clicking on the icon on the desktop or by using the Start Programs menu. MATLAB Desktop window will appear on the screen.The desktop consists of several sub-windows. The most important ones are:●Command Window (on the right side of the Desktop) is used to do calculations,enter variables and run built-in and your own functions.●Workspace (on the upper left side) consists of the set of variables (arrays) createdduring the current MATLAB session and stored in memory.●Command History (on the lower left side) logs commands entered in theCommand Window. You can use this window to view previously run statements, and copy and execute selected statements.You can switch between the Launch Pad window and the Workspace window using the menu tabs under the sub-window on the upper left side. Similarly, you can switch between the Command History and Current Directory windows using the menu tabs under the sub-window on the lower left side.2.2Executing CommandsYou can type MATLAB commands at the command prompt “>>” on the Command Window.For example, you can type the formula cos(π/6)2sin(3π/8) as>>(cos(pi/6) ^ 2) * (sin(3 * pi/8))Try this command. After you finish typing, press enter. The command will be interpreted and the result will be displayed on the Command Window.Try the following by observing how the Workspace window changes:>> a = 2; (M ake note of the usage of “;”)>> b = 3;>> c = a ^ 4 ∗ b ∗ 5 + pi ^3You can see the variables a, b and c with their types and sizes on the Workspacewindow, and can see the commands on the Command History window.Spend a few minutes to practice defining array variables (i.e. vectors and matrices)usingthe square bracket (“[ ]”) and colon (“:”) operators, and zeros() and ones() functions.>> ar =[ 1 2 3 4 5 ];>> br =[ 1 2 3 ;4 5 6 ];>> cr = [1 : 3 : 15];• Set dr to first 3 elements of ar.dr=ar(1:3);• Set er to second row of br.er=br(2,:);• Set ar to [dr er]. Find the number of elements of ar.ar=[dr er]; length(ar)2.3 Getting HelpThere are several ways to get help on commands and functions in MATLAB. First ofall you can use the Help menu. You can also use the “?” button. Try to findinformation on the plot function from the help index. Also try to get information onthe same function using the help command (i.e. type help plot). Finally, experimentwith the lookfor command. This command looks for other commands related to agiven keyword.2.4 Some Useful CommandsTry the following commands and observe their results:Which : Version and location infoClear : Clears the workspaceClc : Clears the command windowwho, whos : Lists content of the workspace3 ExercisesPlease solve the following problems in MATLAB. Do not forget to keep a diary ofyour commands and their outputs.(1) Define the variables x y and z as 7.6, 5.5 and 8.1, respective ly, and evaluate:578.422.52⎪⎭⎫ ⎝⎛-x y xz(2) Compute the slope of the line that passes through the points (1,-2) and(5,8).(3) Quiz 1.1: 5(4)1.6 Exercises: 1.1, 1.4(5)2.15 Exercises: 2.6, 2.9, 2.114Quitting MATLABTyping quit on the command window will close the program. Do not forget to send your diary file and M-file to your TA.Do not forget to delete your files from the hard disk of the PC you used in the lab at the end of the lab session.四川师范大学MATLAB语言实验报告2系级班年月日实验名称:Programming, Relational and Logical Expressions姓名学号指导教师成绩1ObjectiveThe objective of this lab is to familiarize you with the MATLAB script files (M-files), subarrays, relational and logical operators.2Script FilesScript files are collections of MATLAB statements that are stored in a file. Instead of typing commands directly in the Command Window, a series of commands may be placed into a file and the entire file may be executed by typing its name in the Command Window. Such files are called script files that are also known as M-files because they have an extension of .m. When a script file is executed, the result is the same as it would be if all of the commands had been typed directly into the Command Window. All commands and script files executed in the Command Window share a common workspace, so they can all share variables in the workspace. Note that if two script files are executed successively, the second script file can use the variables created by the first script file. In this way, script files can communicate with other script files through the data left behind in the workspace. An Edit Window is used to create new M-files or to modify existing ones. The Edit Window is a programming text editor, with the features of MATLAB language highlighted in different colors. You can create a new M-file with the File/New/M-file selection and you can open an existing M-file with the File/Open selection from the desktop menu of MATLAB. (1)Create a new working directory under the current directory and change the currentdirectory to ‘TA’s suggest’.3SubarraysIt is possible to select and use subsets of MATLAB arrays. To select a subset of an array, just include a list of the elements to be selected in the parentheses after the array name. MATLAB has a special function named end that is used to create arraysubscripts. The end function always returns the highest value taken on by a givensubscript. It is also possible to use subarrays on the left-hand side of an assignmentstatement to change only some of the values in an array. If values are assigned to asubarray, only those values are changed but if values are assigned to an array, theentire contents of the array are replaced by the new values.(1) Define the following 5 x 5 array arr1 in MATLAB.⎥⎥⎥⎥⎥⎥⎦⎤⎢⎢⎢⎢⎢⎢⎣⎡----=2274235421209518171651413215111012844563311arr(2) Write a MATLAB statement to select a subset of arr1 and return the subarraycontaining the values as shown.⎥⎦⎤⎢⎣⎡=22745456311arrarr11=arr1([1,5],[2 4 5]);(3) Write two MATLAB statements to select the last row and last column of arr1,separately.arr12=arr1(5,:);或arr12=arr1(end,:); arr13=arr1(:,end);或 arr13=arr1(:,5);(4) Write MATLAB statements to obtain the following array from arr1.⎥⎥⎥⎥⎥⎥⎦⎤⎢⎢⎢⎢⎢⎢⎣⎡-=2257462335432112arrarr2=arr1([1 5],:)';4 Relational and Logical OperatorsRelational and logical operators are the two types of operators that produce true/falseresults in MATLAB programs. MATLAB interprets a zero value as false and anynonzero value as true. Relational operators ( ==, =,>,>=,<,<=) are operators with twooperands that produce either a true (1) or a false (0) result, depending on the values ofthe operands. Relational operators can be used to compare a scalar value with an array.They can also be used to compare two arrays or two strings only if they have the samesize. Be careful not to confuse the equivalence relational operator ( == ) with theassignment operator ( = ). Logic operators ( &, |, xor, ~ ) are operators with one ortwo operands that yield a logical result such as 0 or 1. There are three binary logicoperators: AND (& ), OR ( |), and exclusive OR ( xor ); and one unary operator: NOT( ~ ). In the hierarchy of operations, logic operators are evaluated after allarithmetic and relational operators have been evaluated. The operator is evaluatedbefore other logic operators.(1) Define the following 4 x 5 array arr4 in MATLAB.⎥⎥⎥⎥⎦⎤⎢⎢⎢⎢⎣⎡------=212343212343212543214arr(2) Write an expression using arr4 and a relational operator to produce the followingresult.⎥⎥⎥⎥⎦⎤⎢⎢⎢⎢⎣⎡=110001110011110111115arrarr5=arr4>0;(3) Write an expression using arr4 and a relational operator to produce the followingresult.⎥⎥⎥⎥⎦⎤⎢⎢⎢⎢⎣⎡=010000010000010000016arrarr6=arr4==1;(4) Write a MATLAB program which will generate an (n-1)x(n-1) matrix from agiven nxn matrix which will be equal to given matrix with first row and firstcolumn deleted.arr44=rand(5); arr444=arr35(2:end,2:end);(5) Generalize your program above so that the program should ask the row andcolumn numbers to be deleted and then generate new (n-1)x(n-1) matrix.n=input('input n:');matrixn=rand(n)delrow=input('input row numbers to be deleted:');delcolumn=input('input column numbers to be deleted:');matrixn_1=matrixn([1:delrow-1 delrow+1:end], [1:delcolumn-1 delcolumn+1:end])(6) Quiz 3.1 (P88)5 Quitting MATLABTyping quit on the command window will close the program. Do not forget to sendyour diary file and M-file to your TA.Do not forget to delete your files from the hard disk of the PC you used in the lab atthe end of the lab session.四川师范大学MATLAB 语言实验报告3系 级 班 年 月 日实验名称:Branches and Loops, Logical Arrays.姓名 学号 指导教师 成绩 1 ObjectiveThe objective of this lab is to familiarize you with the MATLAB Branches and Loops,Logical Arrays.2 ExercisesDo not forget to add sufficient documentation and proper indentation to all programsyou write.(1) Write a program that calculates follow equation with for and while loop, and writea program without loop.63263022212+++==∑=Λi i K% for loopk1=0;for ii=1:64k1=k1+2^(ii-1);end% while loopk2=0;n=0;while n>=0&n<64k2=k2+2^n;n=n+1;end% without loopa=0:63;b=2.^a;K3=sum(b);(2) Write a program that accepts a vector of integers as input and counts the numberof integers that are multiples of 3 in that vector. You can assume that the inputcontains only integer values. An example run of your program can be as follows:Enter a vector of integers: [ 1 3 2 8 0 5 6 ]The number of multiples of 3 is 2(3) The root mean square is a way for calculating a mean for a set of numbers. The rmsaverage of a series of numbers is given as:∑==N i i x N rmsaverage 121Write a program that will accept an arbitrary number of input values and calculatethe rmsaverage of the numbers. The program should ask the user for the numberof values to be entered. Test your program with 4 and 10 set of numbers.% The root mean square is a way for calculating a mean for a set of numbers% Initializesum_x2=0;% Get the number of points to input.n=input('Enter number of points:');% Loop to read input valuesfor ii=1:n% Read in next valuex=input('Enter value:');% Calculate square sumssum_x2=sum_x2+x^2;end% Now calculate root mean squareroot_ms=sqrt(sum_x2/n);% Tell userfprintf('The number of data points is: %d\n',n);fprintf('The root mean square of this data set is: %f\n',root_ms);(4) 3.8 exercises:3.5(5) 4.7Exercises: 4.1 4.23 Quitting MATLABTyping quit on the command window will close the program. Do not forget to sendyour M-file to your TA.Do not forget to delete your files from the hard disk of the PC you used in the lab at the end of the lab session.四川师范大学MATLAB语言实验报告4系级班年月日实验名称:MATLAB/SIMULINK package姓名学号指导教师成绩1Objective●To learn how to use MATLAB/SIMULINK package●To learn how to estimate performance parameters from time-domain data2SIMULINK BasicBasic steps(1)Click on the MATLAB button to start MATLAB.(2)Once MATLAB has started up, type simulink (SMALL LETTERS!) at theMATLAB prompt (>>) followed by a carriage return (press the return key). A SIMULINK window should appear shortly, with the following icons: Sources, Sinks, Discrete, Linear, Connections, Extras.(3)Next, go to the File menu in SIMULINK window and choose New in order tobegin building the block diagram representation of the system of interest.(4)Open one or more of the block libraries and drag the chosen blocks into the active.(5)After the blocks are placed, draw lines to connect their input and output ports bymoving the mouse over a port and drag using the left button. To make a line witha right angle in it, release the button where you want the corner, then click on theend of the line and drag to create next segment. To add a second line that runs off of an existing line click the right mouse on an existing line and drag it.(6)Save the system by selecting Save from the File menu.(7)Open the blocks by double-clicking and change some of their internal parameters.(8)Adjust some simulation parameters by selecting Parameters from the Simulationmenu. The most common parameter to change is Stop Time that defines the length of time the simulation will run.(9)Run the simulation by selecting Start from the Simulation menu. You can stop asimulation before completing by selecting Stop from the Simulation menu. (10)View the behavior of the system by attaching Scope blocks to the variables ofinterest, or by using To Workspace blocks to send data to the MATLAB workspace where you can plot the results using standard MATLAB commands.3Exercises(1)Your TA has shown you how to observe and print signals from the scope. Try thisout by printing out the input signal, which should be a -1V to 1V square wave with frequency 0.1 Hz. Note the peak-to-peak voltage difference of this signal.Note to write key blocks parameters.(2) Write a Simulink model to calculate the following differential equation,0)1(222=+--x dt dx x dt x d μInitialized 1)0(=x ,0)0(=dt dx 。

matlab实验报告1

matlab实验报告1

matlab实验报告1MATLAB实验报告1摘要:本实验使用MATLAB软件进行了一系列的实验,主要包括数据处理、图像处理和信号处理。

通过实验,我们掌握了MATLAB软件在科学计算和工程领域的应用,深入了解了MATLAB在数据处理、图像处理和信号处理方面的强大功能。

一、数据处理实验在数据处理实验中,我们使用MATLAB对一组实验数据进行了分析和处理。

首先,我们导入了实验数据并进行了数据清洗和预处理,然后利用MATLAB的统计分析工具对数据进行了描述性统计分析,包括均值、方差、标准差等指标的计算。

接着,我们利用MATLAB的绘图工具绘制了数据的直方图和散点图,直观地展现了数据的分布规律和相关性。

二、图像处理实验在图像处理实验中,我们使用MATLAB对一幅图像进行了处理和分析。

首先,我们读取了图像并进行了灰度化处理,然后利用MATLAB的图像滤波工具对图像进行了平滑和锐化处理,最后利用MATLAB的图像分割工具对图像进行了分割和特征提取。

通过实验,我们深入了解了MATLAB在图像处理领域的应用,掌握了图像处理的基本原理和方法。

三、信号处理实验在信号处理实验中,我们使用MATLAB对一组信号进行了处理和分析。

首先,我们生成了一组模拟信号并进行了频域分析,利用MATLAB的信号滤波工具对信号进行了滤波处理,然后利用MATLAB的频谱分析工具对信号的频谱特性进行了分析。

通过实验,我们深入了解了MATLAB在信号处理领域的应用,掌握了信号处理的基本原理和方法。

综上所述,本实验通过对MATLAB软件的应用实验,使我们对MATLAB在数据处理、图像处理和信号处理方面的功能有了更深入的了解,为我们今后在科学计算和工程领域的应用奠定了良好的基础。

MATLAB软件的强大功能和广泛应用前景,将为我们的学习和科研工作提供有力的支持和帮助。

MATLAB实验报告(8个实验)

MATLAB实验报告(8个实验)

MATLAB实验报告(8个实验)四川师范大学MATLAB语言实验报告1系级班年月日实验名称:Intro, Expressions, Commands姓名学号指导教师成绩1ObjectiveThe objective of this lab is to familiarize you with the MATLAB program development environment and to develop your first programs in this environment.2Using MATLAB2.1Starting MATLABLogon to your computer and start MATLAB by double-clicking on the icon on the desktop or by using the Start Programs menu. MATLAB Desktop window will appear on the screen.The desktop consists of several sub-windows. The most important ones are:●Command Window (on the right side of the Desktop) is used to do calculations,enter variables and run built-in and your own functions.●Workspace (on the upper left side) consists of the set of variables (arrays) createdduring the current MATLAB session and stored in memory.●Command History (on the lower left side) logs commands entered in theCommand Window. You can use this window to view previously run statements, and copy and execute selected statements.You can switch between the Launch Pad window and the Workspace window using the menu tabs under the sub-windowon the upper left side. Similarly, you can switch between the Command History and Current Directory windows using the menu tabs under the sub-window on the lower left side.2.2Executing CommandsYou can type MATLAB commands at the command prompt “>>” on the Command Window.For example, you can type the formula cos(π/6)2sin(3π/8) as >>(cos(pi/6) ^ 2) * (sin(3 * pi/8))Try this command. After you finish typing, press enter. The command will be interpreted and the result will be displayed on the Command Window.Try the following by observing how the Workspace window changes:>> a = 2; (M ake note of the us age of “;”)>> b = 3;>> c = a ^ 4 ? b ? 5 + pi ^3You can see the variables a, b and c with their types and sizes on the Workspacewindow, and can see the commands on the Command History window.Spend a few minutes to practice defining array variables (i.e. vectors and matrices)usingthe square bracket (“[ ]”) and colon (“:”) operators, and zeros() and ones() functions.>> ar =[ 1 2 3 4 5 ];>> br =[ 1 2 3 ;4 5 6 ];>> cr = [1 : 3 : 15];Set dr to ?rst 3 elements of ar.dr=ar(1:3);Set er to second row of br.er=br(2,:);Set ar to [dr er]. Find the number of elements of ar.ar=[dr er]; length(ar)2.3 Getting HelpThere are several ways to get help on commands and functions in MATLAB. First ofall you can use the Help menu. You can also use the “?” button. Try to findinformation on the plot function from the help index. Also try to get information onthe same function using the help command (i.e. type help plot). Finally, experimentwith the lookfor command. This command looks for other commands related to agiven keyword.2.4 Some Useful CommandsTry the following commands and observe their results:Which : Version and location infoClear : Clears the workspaceClc : Clears the command windowwho, whos : Lists content of the workspace3 ExercisesPlease solve the following problems in MATLAB. Do not forget to keep a diary ofyour commands and their outputs.(1) De?ne the variables x y and z as 7.6, 5.5 and 8.1, respective ly, and evaluate:578.422.52??? ??-x y xz(2) Compute the slope of the line that passes through thepoints (1,-2) and(5,8).(3) Quiz 1.1: 5(4)1.6 Exercises: 1.1, 1.4(5)2.15 Exercises: 2.6, 2.9, 2.114Quitting MATLABTyping quit on the command window will close the program. Do not forget to send your diary file and M-file to your TA.Do not forget to delete your ?les from the hard disk of the PC you used in the lab at the end of the lab session.四川师范大学MATLAB语言实验报告2系级班年月日实验名称:Programming, Relational and Logical Expressions 姓名学号指导教师成绩1ObjectiveThe objective of this lab is to familiarize you with the MATLAB script files (M-files), subarrays, relational and logical operators.2Script FilesScript files are collections of MATLAB statements that are stored in a file. Instead of typing commands directly in the Command Window, a series of commands may be placed into a file and the entire file may be executed by typing its name in the Command Window. Such files are called script files that are also known as M-files because they have an extension of .m. When a script file is executed, the result is the same as it would be if all of the commands had been typed directly into the Command Window. All commands and script files executed in the Command Window share a common workspace, so they can all share variables in the workspace. Note that if two script files are executed successively, the second script file can use the variables created by the first script file. In this way, script files can communicate with other script files through the data left behindin the workspace. An Edit Window is used to create new M-files or to modify existing ones. The Edit Window is a programming text editor, with the features of MATLAB language highlighted in different colors. You can create a new M-file with the File/New/M-file selection and you can open an existing M-file with the File/Open selection from the desktop menu of MATLAB.(1)Create a new working directory under the current directory and change the currentdirectory to …TA?s suggest?.3SubarraysIt is possible to select and use subsets of MATLAB arrays. To select a subset of an array, just include a list of the elements to be selected in the parentheses after the array name. MATLAB has a special function named end that is used to create arraysubscripts. The end function always returns the highest value taken on by a givensubscript. It is also possible to use subarrays on the left-hand side of an assignmentstatement to change only some of the values in an array. If values are assigned to asubarray, only those values are changed but if values are assigned to an array, theentire contents of the array are replaced by the new values.(1) Define the following 5 x 5 array arr1 in MATLAB.----=2274235421209518171651413215111012844563311arr(2) Write a MATLAB statement to select a subset of arr1 and return the subarraycontaining the values as shown.=22745456311arrarr11=arr1([1,5],[2 4 5]);(3) Write two MATLAB statements to select the last row and last column of arr1,separately.arr12=arr1(5,:);或arr12=arr1(end,:); arr13=arr1(:,end);或arr13=arr1(:,5);(4) Write MATLAB statements to obtain the following array from arr1.-=2257462335432112arrarr2=arr1([1 5],:)';4 Relational and Logical OperatorsRelational and logical operators are the two types of operators that produce true/falseresults in MATLAB programs. MATLAB interprets a zero value as false and anynonzero value as true. Relational operators ( ==, =,>,>=,<,<=) are operators with twooperands that produce either a true (1) or a false (0) result, depending on the values ofthe operands. Relational operators can be used to compare a scalar value with an array.They can also be used to compare two arrays or two strings only if they have the samesize. Be careful not to confuse the equivalence relational operator ( == ) with theassignment operator ( = ). Logic operators ( &, |, xor, ~ ) are operators with one ortwo operands that yield a logical result such as 0 or 1. There are three binary logicoperators: AND (& ), OR ( |), and exclusive OR ( xor ); and oneunary operator: NOT( ~). In the hierarchy of operations, logic operators are evaluated after allarithmetic and relational operators have been evaluated. The operator is evaluatedbefore other logic operators.(1) Define the following 4 x 5 array arr4 in MATLAB.------=212343212343212543214arr(2) Write an expression using arr4 and a relational operator to produce the followingresult.=110001110011110111115arrarr5=arr4>0;(3) Write an expression using arr4 and a relational operator to produce the followingresult.=010000010000010000016arrarr6=arr4==1;(4) Write a MATLAB program which will generate an (n-1)x(n-1) matrix from agiven nxn matrix which will be equal to given matrix with first row and firstcolumn deleted.arr44=rand(5); arr444=arr35(2:end,2:end);(5) Generalize your program above so that the program should ask the row andcolumn numbers to be deleted and then generate new (n-1)x(n-1) matrix.n=input('input n:');matrixn=rand(n)delrow=input('input row numbers to be deleted:');delcolumn=input('input column numbers to be deleted:');matrixn_1=matrixn([1:delrow-1 delrow+1:end], [1:delcolumn-1 delcolumn+1:end])(6) Quiz 3.1 (P88)5 Quitting MATLABTyping quit on the command window will close the program. Do not forget to sendyour diary file and M-file to your TA.Do not forget to delete your files from the hard disk of the PC you used in the lab atthe end of the lab session.四川师范大学MATLAB 语言实验报告3系级班年月日实验名称:Branches and Loops, Logical Arrays.姓名学号指导教师成绩 1 ObjectiveThe objective of this lab is to familiarize you with the MATLAB Branches and Loops,Logical Arrays.2 ExercisesDo not forget to add sufficient documentation and proper indentation to all programsyou write.(1) Write a program that calculates follow equation with for and while loop, and writea program without loop.63263022212+++==∑= i i K% for loopk1=0;for ii=1:64k1=k1+2^(ii-1);end% while loopk2=0;n=0;while n>=0&n<64k2=k2+2^n;n=n+1;end% without loopa=0:63;b=2.^a;K3=sum(b);(2) Write a program that accepts a vector of integers as input and counts the numberof integers that are multiples of 3 in that vector. You can assume that the inputcontains only integer values. An example run of your program can be as follows:Enter a vector of integers: [ 1 3 2 8 0 5 6 ]The number of multiples of 3 is 2(3) The root mean square is a way for calculating a mean fora set of numbers. The rmsaverage of a series of numbers is given as:∑==N i i xN rmsaverage 121Write a program that will accept an arbitrary number of input values and calculatethe rmsaverage of the numbers. The program should ask the user for the numberof values to be entered. Test your program with 4 and 10 set of numbers.% The root mean square is a way for calculating a mean for a set of numbers% Initializesum_x2=0;% Get the number of points to input.n=input('Enter number of points:');% Loop to read input valuesfor ii=1:n% Read in next valuex=input('Enter value:');% Calculate square sumssum_x2=sum_x2+x^2;end% Now calculate root mean squareroot_ms=sqrt(sum_x2/n);% Tell userfprintf('The number of data points is: %d\n',n);fprintf('The root mean square of this data set is: %f\n',root_ms);(4) 3.8 exercises:3.5(5) 4.7Exercises: 4.1 4.23 Quitting MATLABTyping quit on the command window will close the program. Do not forget to sendyour M-file to your TA.Do not forget to delete your files from the hard disk of the PC you used in the lab at the end of the lab session.四川师范大学MATLAB语言实验报告4系级班年月日实验名称:MATLAB/SIMULINK package姓名学号指导教师成绩1Objective●To learn how to use MATLAB/SIMULINK package●To learn how to estimate performance parameters from time-domain data2SIMULINK BasicBasic steps(1)Click on the MATLAB button to start MATLAB.(2)Once MATLAB has started up, type simulink (SMALL LETTERS!) at theMATLAB prompt (>>) followed by a carriage return (press the return key). A SIMULINK window should appear shortly, with the following icons: Sources, Sinks, Discrete, Linear, Connections, Extras.(3)Next, go to the File menu in SIMULINK window and choose New in order tobegin building the block diagram representation of the system of interest.(4)Open one or more of the block libraries and drag the chosen blocks into the active.(5)After the blocks are placed, draw lines to connect their input and output ports bymoving the mouse over a port and drag using the left button. To make a line witha right angle in it, release the button where you want thecorner, then click on theend of the line and drag to create next segment. To add a second line that runs off of an existing line click the right mouse on an existing line and drag it.(6)Save the system by selecting Save from the File menu.(7)Open the blocks by double-clicking and change some of their internal parameters.(8)Adjust some simulation parameters by selecting Parameters from the Simulationmenu. The most common parameter to change is Stop Time that defines the length of time the simulation will run.(9)Run the simulation by selecting Start from the Simulation menu. You can stop asimulation before completing by selecting Stop from the Simulation menu. (10)View the behavior of the system by attaching Scope blocks to the variables ofinterest, or by using To Workspace blocks to send data to the MATLAB workspace where you can plot the results using standard MATLAB commands.3Exercises(1)Your TA has shown you how to observe and print signals from the scope. Try thisout by printing out the input signal, which should be a -1V to 1V square wave with frequency 0.1 Hz. Note the peak-to-peak voltage difference of this signal.Note to write key blocks parameters.(2) Write a Simulink model to calculate the following differential equation,0)1(222=+--x dt dx x dt x d μInitialized 1)0(=x ,0)0(=dt dx 。

MATLAB实验报告绘图

MATLAB实验报告绘图
t=[54 21 35;
68 54 35;
45 25 12;
48 68 45;
68 54 69];
x=sum(t);
h=pie(x);
textobjs=findobj(h,'type','text');
str1=get(textobjs,{'string'});
val1=get(textobjs,{'extent'});
运行图像
4、采用模型 画一组椭圆
输入程序:th = [0:pi/50:2*pi]';
a = [0.5:.5:4.5];
X = cos(th)*a;
Y = sin(th)*sqrt(25-a.^2);
plot(X,Y),axis('equal'),xlabel('x'), ylabel('y')
title('A set of Ellipses')
oldext=cat(1,val1{:});
names={'商品一;'商品二';'商品三'};
str2=strcat(names,str1);
set(textobjs,{'string'},str2)
val2=get(textobjs,{'extent'});
newext=cat(1,val2{:});
xlable('sin(t)'),ylable('cos(t)'),zlable('t');
gridon;
输出图像
9、用MATLAB绘制饼图

(完整word)Matlab实验报告

(完整word)Matlab实验报告

实验一:Matlab操作环境熟悉一、实验目的1.初步了解Matlab操作环境.2.学习使用图形函数计算器命令funtool及其环境。

二、实验内容熟悉Matlab操作环境,认识命令窗口、内存工作区窗口、历史命令窗口;学会使用format 命令调整命令窗口的数据显示格式;学会使用变量和矩阵的输入,并进行简单的计算;学会使用who和whos命令查看内存变量信息;学会使用图形函数计算器funtool,并进行下列计算:1.单函数运算操作。

求下列函数的符号导数(1)y=sin(x);(2) y=(1+x)^3*(2-x);求下列函数的符号积分(1)y=cos(x);(2)y=1/(1+x^2);(3)y=1/sqrt(1—x^2);(4)y=(x1)/(x+1)/(x+2)求反函数(1)y=(x-1)/(2*x+3); (2) y=exp(x);(3) y=log(x+sqrt(1+x^2));代数式的化简(1)(x+1)*(x-1)*(x-2)/(x-3)/(x—4);(2)sin(x)^2+cos(x)^2;(3)x+sin(x)+2*x—3*cos(x)+4*x*sin(x);2.函数与参数的运算操作。

从y=x^2通过参数的选择去观察下列函数的图形变化(1)y1=(x+1)^2(2)y2=(x+2)^2(3) y3=2*x^2 (4) y4=x^2+2 (5) y5=x^4 (6) y6=x^2/2 3.两个函数之间的操作求和(1)sin(x)+cos(x) (2) 1+x+x^2+x^3+x^4+x^5乘积(1)exp(—x)*sin(x) (2) sin(x)*x商(1)sin(x)/cos(x); (2) x/(1+x^2); (3) 1/(x—1)/(x—2); 求复合函数(1)y=exp(u) u=sin(x) (2) y=sqrt(u) u=1+exp(x^2)(3) y=sin(u) u=asin(x) (4) y=sinh(u) u=-x实验二:MATLAB基本操作与用法一、实验目的1.掌握用MATLAB命令窗口进行简单数学运算。

matlab实验报告(实验4)

matlab实验报告(实验4)

学生实验报告开课学院及实验室: 机电学院2012年12月21日学院机电学院年级、专业、班姓名学号实验课程名称MATLAB程序设计成绩实验项目名称实验4: 数据和函数的可视化指导老师一、实验目的1、掌握MATLAB绘图的基本步骤和相关指令调用的先后顺序。

2、掌握MATLAB绘图指令的调用方法。

二、实验内容数学函数从形式上可以分为离散函数和连续函数。

MATLAB对这两种函数数据的可视化都提供了相应的指令。

仔细阅读教材【例5.1-1】的实现代码, 运行并保存结果;并改用stem函数, 画出【例5.1-1】的序列图。

仔细阅读教材【例5.1-2】的实现代码, 运行并保存结果;并分别使用描点和连折线方式, 画出连续函数y=xcosx的近似图形(采样点数自定, 要求画出的图尽量接近原连续函数的图)。

仔细阅读【例5.2-2】的实现代码, 理解plot指令画多条曲线的运用方法, 运行并保存结果;并使用plot函数和legend函数, 在同一个图形窗口上画出y=sint和y=sin(2t)在[0,2pi]区间上的图形, 并标出图例。

仔细阅读【例5.2-4】的实现代码, 理解图形标识选项的运用方法, 运行并保存结果;并修改代码, 把“sin(t)”字体改为正体, 大小改为20, “极大值”改为宋体。

阅读【例5.2-6】, 理解使用hold on指令画多幅图的方法, 运行并保存结果。

阅读【例5.2-8】, 理解使用subplot函数画多个子图的方法, 运行并保存结果。

(1)综合实验: 阅读以下关于通过绘制二阶系统阶跃响应综合演示图形标识的示例, 理解示例中所有图形标识指令的作用, 掌握各个图形标识指令的运用方法, 并在原指令上改动以实现以下功能:(2)把横坐标范围改为0至5pi, 纵坐标范围改为0至2;(3)把图中的横轴的刻度改为从0开始到4pi, 中间各点间隔为pi/2;纵轴刻度改为从0开始到1.5, 中间各点间隔为0.3;(4)把图中的α改为σ。

matlab 实验报告

matlab 实验报告

matlab 实验报告Matlab实验报告引言:Matlab是一种强大的数值计算和可视化软件,广泛应用于科学、工程和经济等领域。

本实验报告将介绍我在使用Matlab进行实验过程中的一些经验和结果。

实验一:矩阵运算在这个实验中,我使用Matlab进行了矩阵运算。

首先,我创建了一个3x3的矩阵A和一个3x1的矩阵B,并进行了矩阵相乘运算。

通过Matlab的矩阵乘法运算符*,我得到了一个3x1的结果矩阵C。

接着,我对矩阵C进行了转置操作,得到了一个1x3的矩阵D。

最后,我计算了矩阵C和矩阵D的点积,并将结果输出。

实验二:数据可视化在这个实验中,我使用Matlab进行了数据可视化。

我选择了一组实验数据,包括时间和温度两个变量。

首先,我将数据存储在一个矩阵中,并使用Matlab的plot函数将时间和温度之间的关系绘制成曲线图。

接着,我使用Matlab的xlabel、ylabel和title函数添加了横轴、纵轴和标题。

最后,我使用Matlab的legend函数添加了图例,以便更好地理解图表。

实验三:数值积分在这个实验中,我使用Matlab进行了数值积分。

我选择了一个函数f(x)进行积分计算。

首先,我使用Matlab的syms函数定义了符号变量x,并定义了函数f(x)。

接着,我使用Matlab的int函数对函数f(x)进行积分计算,并将结果输出。

为了验证结果的准确性,我还使用了Matlab的diff函数对积分结果进行了求导操作,并与原函数f(x)进行了比较。

实验四:信号处理在这个实验中,我使用Matlab进行了信号处理。

我选择了一个音频文件,并使用Matlab的audioread函数读取了该文件。

接着,我使用Matlab的fft函数对音频信号进行了傅里叶变换,并将结果绘制成频谱图。

为了进一步分析信号的特征,我还使用了Matlab的spectrogram函数绘制了信号的时频图。

通过对信号的频谱和时频图的观察,我可以更好地理解信号的频率和时域特性。

MATLAB实验报告_8

MATLAB实验报告_8

实验一基本操作和简单语句输入一、实验环境计算机MATLAB软件二、实验目的1.熟悉MA TLAB的命令窗口。

2、掌握MATLAB的一些基本操作, 能够进行一般的数值计算。

3.实现语句的重调和修改。

三、实验内容与步骤1.启动MA TLAB2.观察MA TLAB窗口的各个组成部分(1)了解菜单栏各窗口项的功能, 用鼠标打开MA TLAB的各个菜单, 在状态栏里显示当前鼠标所指的菜单项的含义。

(2)用鼠标指向常用工具栏的每个工具按钮, 了解各工具按钮的含义。

3.命令窗口的打开和关闭(1)查看菜单窗口中有哪些菜单命令。

(2)在命令窗口中输入命令a=3;b=4;y=a*b+a/b, 然后回车, 查看命令显示结果。

>> a=3;b=4;y=a*b+a/b,y =12.7500(3)利用MA TLAB中编辑命令时常用的按键功能, 调用上一个语句, 对它进行修改(如把分号改成逗号, 看运行结果), 并把运行结果复制到word中保存。

>> a=3,b=4,y=a*b+a/b,a =3b =4y =12.7500(4)关闭命令窗口。

(5)打开命令窗口。

4.使用MA TLAB帮助熟悉MATLAB的帮助系统, 通过帮助系统了解有关内容。

5、在命令窗口中输入demo, 将出现MA TLAB的演示窗, 通过演示窗, 对MATLAB的功能进行一次浏览。

四、练习1.计算y=x^3+(x-0.98)^2/(x+1.25)^3-5*(x+1/x), x=2, x=3时的值。

>> x=2;y=x^3+(x-0.98)^2/(x+1.25)^3-5*(x+1/x)y =-4.4697>> x=3;y=x^3+(x-0.98)^2/(x+1.25)^3-5*(x+1/x)y =10.38652.计算cos(pi/3)-sqrt(9-sqrt(2))>> cos(pi/3)-sqrt(9-sqrt(2))ans =-2.25423.已知: a=3,A=4,b=a^2,B=b^2-1,c=a+A-2*B,C=a+B+2*c, 求: C>> a=3;A=4;b=a^2;B=b^2-1;c=a+A-2*B;C=a+B+2*cC =-2234.复数z1=1+3*i,z2=1+2*i,z3=2*exp((pi/6)*i),求z=(z1*z2)/z3>> z1=1+3*i;z2=1+2*i;z3=2*exp((pi/6)*i);z=(z1*z2)/z3z =-0.9151 + 3.4151i实验二矩阵和数组的操作一、实验环境计算机MATLAB软件二、实验目的1.掌握矩阵和数组的一般操作, 包括创建、保存、修改和调用等。

matlab实验一实验报告

matlab实验一实验报告

matlab实验一实验报告实验一:Matlab实验报告引言:Matlab是一种强大的数学软件工具,广泛应用于科学计算、数据分析和工程设计等领域。

本实验旨在通过使用Matlab解决实际问题,探索其功能和应用。

一、实验目的本次实验的主要目的是熟悉Matlab的基本操作和常用函数,了解其在科学计算中的应用。

二、实验内容1. 数值计算在Matlab中,我们可以进行各种数值计算,包括基本的加减乘除运算,以及更复杂的矩阵运算和方程求解。

通过编写相应的代码,我们可以实现这些功能。

例如,我们可以使用Matlab计算两个矩阵的乘积,并输出结果。

代码如下:```matlabA = [1 2; 3 4];B = [5 6; 7 8];C = A * B;disp(C);```2. 数据可视化Matlab还提供了强大的数据可视化功能,可以将数据以图表的形式展示出来,更直观地观察数据的规律和趋势。

例如,我们可以使用Matlab绘制一个简单的折线图,来展示某个物体在不同时间下的位置变化。

代码如下:```matlabt = 0:0.1:10;x = sin(t);plot(t, x);xlabel('Time');ylabel('Position');title('Position vs. Time');```3. 图像处理Matlab还可以进行图像处理,包括图像的读取、处理和保存等操作。

我们可以通过Matlab对图像进行增强、滤波、分割等处理,以及进行图像的压缩和重建。

例如,我们可以使用Matlab读取一张图片,并对其进行灰度化处理。

代码如下:```matlabimg = imread('image.jpg');gray_img = rgb2gray(img);imshow(gray_img);```三、实验结果与分析在本次实验中,我们成功完成了数值计算、数据可视化和图像处理等任务。

(完整word版)matlab实验报告

(完整word版)matlab实验报告

《通信系统仿真》实验报告姓名:杨仕浩专业:通信工程学号: 2014111347实验一 MATLAB环境的熟悉与基本运算一、实验目的:1.熟悉MATLAB开发环境2.掌握矩阵、变量、表达式的各种基本运算二、实验基本知识:1.熟悉MATLAB环境:MATLAB桌面和命令窗口、命令历史窗口、帮助信息浏览器、工作空间浏览器文件和搜索路径浏览器。

变量命名规则如下:(1)变量名可以由英语字母、数字和下划线组成(2)变量名应以英文字母开头(3)长度不大于31个(4)区分大小写MATLAB中设置了一些特殊的变量与常量,列于下表。

三、实验内容1、学习安装MATLAB软件。

2、学习使用help命令,例如在命令窗口输入help eye,然后根据帮助说明,学习使用指令eye(其它不会用的指令,依照此方法类推)3、学习使用clc、clear,观察command window、command history和workspace等窗口的变化结果。

4、初步程序的编写练习,新建M-file,保存(自己设定文件名,例如exerc1、exerc2、 exerc3……),学习使用MATLAB的基本运算符、数组寻访指令、标准数组生成函数和数组操作函数。

注意:每一次M-file的修改后,都要存盘。

练习A:(1) help rand,然后随机生成一个2×6的数组,观察command window、command history和workspace等窗口的变化结果。

(2)学习使用clc、clear,了解其功能和作用。

(3)输入C=1:2:20,则C(i)表示什么?其中i=1,2,3, (10)(4)输入A=[7 1 5;2 5 6;3 1 5],B=[1 1 1; 2 2 2; 3 3 3],在命令窗口中执行下列表达式,掌握其含义:A(2, 3) A(:,2) A(3,:) A(:,1:2:3) A(:,3).*B(:,2)A(:,3)*B(2,:) A*B A.*B A^2 A.^2 B/A B./A (5)二维数组的创建和寻访,创建一个二维数组(4×8)A,查询数组A 第2行、第3列的元素,查询数组A第2行的所有元素,查询数组A第6列的所有元素。

matlab实验一实验报告

matlab实验一实验报告

matlab实验一实验报告一、实验目的本次实验的主要目的是熟悉 MATLAB 软件的基本操作环境和编程语法,通过实际编写和运行简单的程序,初步掌握 MATLAB 在数值计算、图形绘制和数据处理方面的基本功能。

二、实验环境本次实验使用的是 MATLAB R2020a 版本,运行在 Windows 10 操作系统上。

计算机配置为:Intel Core i5 处理器,8GB 内存。

三、实验内容及步骤1、矩阵运算创建一个 3×3 的矩阵 A,元素分别为 1 到 9。

创建一个 3×3 的零矩阵 B。

计算 A+B 和 A×B 的结果。

在 MATLAB 中,我们可以使用以下代码实现:```matlabA = 1 2 3; 4 5 6; 7 8 9;B = zeros(3);C = A + B;D = A B;disp(C);disp(D);```2、数据类型转换定义一个整数变量 x 为 5。

将 x 转换为双精度浮点数。

将 x 转换为字符串类型。

代码如下:```matlabx = 5;y = double(x);z = num2str(x);disp(y);disp(z);```3、函数调用定义一个函数 fun,输入参数为 x,返回值为 x 的平方。

调用函数 fun,计算 3 的平方。

函数定义及调用代码:```matlabfunction y = fun(x)y = x^2;endresult = fun(3);disp(result);```4、图形绘制绘制函数 y = sin(x)在区间0, 2π上的图像。

使用以下代码实现:```matlabx = 0:001:2pi;y = sin(x);plot(x, y);```四、实验结果1、矩阵运算A+B 的结果为:```matlab1 2 34 5 67 8 9```A×B 的结果为:```matlab0 0 00 0 00 0 0```2、数据类型转换将整数 5 转换为双精度浮点数,结果为 50000。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

主题:投资组合问题指导教师: 阮小娥老师制作时间:2010.12—2011.01学院:机械学院小组成员:机自07 赵磊80机自07 周策81机自07 邹业兵82目录一、引言:........................................................................................................... 错误!未定义书签。

二、实验问题: ................................................................................................ 错误!未定义书签。

三、问题分析 .................................................................................................... 错误!未定义书签。

(1)、已知和股票有关的一些概念(实验所涉及的理论知识):....... 错误!未定义书签。

(2)、数学建模: .................................................................................... 错误!未定义书签。

数学模型: ........................................................................................ 错误!未定义书签。

(3)、求解方法: .................................................................................... 错误!未定义书签。

四、程序设计: ................................................................................................ 错误!未定义书签。

第一步: .................................................................................................... 错误!未定义书签。

第二、三、四步: .................................................................................... 错误!未定义书签。

第五步: .................................................................................................... 错误!未定义书签。

五、程序运行结果(实验结果)为: ............................................................ 错误!未定义书签。

第一步: .................................................................................................... 错误!未定义书签。

A股49个周末的收盘价的变化情况............................................... 错误!未定义书签。

B股49个周末的收盘价的变化情况............................................... 错误!未定义书签。

C股49个周末的收盘价的变化情况............................................... 错误!未定义书签。

第二、三、四步: .................................................................................... 错误!未定义书签。

第五步: .................................................................................................... 错误!未定义书签。

六、问题的进一步拓展与实验 ........................................................................ 错误!未定义书签。

实验过程 .................................................................................................... 错误!未定义书签。

1:条件假设 ...................................................................................... 错误!未定义书签。

2:建立模型 ...................................................................................... 错误!未定义书签。

3:模型求解 ...................................................................................... 错误!未定义书签。

程序设计 ............................................................................................ 错误!未定义书签。

程序运行结果 .................................................................................... 错误!未定义书签。

七、实验的总结与体会: ................................................................................ 错误!未定义书签。

赵磊: ................................................................................................ 错误!未定义书签。

周策: ................................................................................................ 错误!未定义书签。

邹业兵: ............................................................................................ 错误!未定义书签。

一、引言:现在社会,随着社会的发展和生产力的提升,人们的生活水平日益提高。

人们不仅仅满足于吃饱穿暖,人们对财富的追求也愈来愈强烈,此时股票作为社会化大生产的产物,股票至今已有将近似400年的历史,它的发展与人类经济的发展可以说是和谐统一的,而它集惊险刺激和可能存在的巨额经济效益的特点更是牢牢的牵住了现代人的心,毕竟,在已经不愁衣食的前提下,谁不想像股神巴菲特一样,动动脑筋便收拢全世界的财富呢?所以,研究股票自然而然就成了现代人生活中极为重要的一部分。

二、实验问题:企业(或政府)或个人进行投资的目的是为了取得利润,在现代市场经济中,由于投资环境瞬息万变,任何一项投资的收益总是不能确定的,也就是说具有一定的风险,如何度量收益和风险呢?下面给出一个实际问题进行分析:表9-1给出3只股票(A、B、C股)49个周末的收盘价,(1) 分别计算这三只股票的周收益率的时间序列,平均收益率和他们收益率分布的方差; (2)允许卖空的条件下给出这3只股票风险最小的投资策略。

三、问题分析(1)、已知和股票有关的一些概念(实验所涉及的理论知识):记At P 为证券A 在第t 周末的价格,定义11---=At At At P P P rAt 为证券A 当周的证券收益率,由于投资初期不可能知道将来的收益率,因此收益率是一个随机变量,At A A A r r r r ........3,2,1为证券A 在某一时间段内收益率分布,且定义该收益率分布的均值Tr E A ∑==T1t Atr)(为证券A 的期望收益率,并用该收益率分布的方差Tr E rTt AtAt A ∑=-=122))((σ度量该证券A 期望收益的偏差称为风险,同样可以计算证券B 的期望收益率)(B r E 及方差2B σ两证券收益率分布间的协方差为协方差给出了证券A 和证券B 收益率分布相互影响的程度,协方差的大小依赖于收益所的 单位,相关系数BA AB BA B A AB r r σσσσσρ==),cov(反映了证券A 和证券B 投资比率分为多少时风险比率最小,受益最大,这就是证券A 和证券B 的投资组合问题。

(2)、数学建模:用决策变量X1,X2,X3分别表示投资股票A ,B ,C 的投资比率,记股票A ,B ,C 的投资比率,记股票A ,B ,C 的收益率分别为Ea 、Eb 、Ec ,根据题意, Ea 、Eb 、Ec 是随机变量,投资的总收益率为 S=X1*Ea+X2*Eb+X3*Ec也是随机变量,用E 和D 分别表示随机变量的数学期望和方差,则有 (以下结果是经过第一、二、三、四步操作所得)Ea = 0.0036, Eb= 0.0121, Ec= 0.0073 Da = 5.4449e-004, Db= 0.0036, Dc= 0.0016Dab=3.8817e-005、 Dac= 5.6361e-004、 Dbc= 1.5600e-004; 由概率论知识可知covAC=Dac*Da^0.5*Dc^0.5 covAB=Dab*Da^0.5*Db^0.5 covBC=Dbc*Db^0.5*Dc^0.5投资的总期望收益率为:y=E=x1*Ea+x2*Eb+x3*Ec用总收益的方差衡量投资风险是,投资总收益的方差为:Z=D(x1*Ea+x2*Eb+x3*Ec)=Da*x1^2+Db*x2^2+Dc*x3^2+2covAB*x1*x2+2covAC*x1*x3+2covBC*x2*x3由于x1、x2、x3分别表示投资股票A、B、C的投资比例,所以x1+x2+x3=1数学模型:Minz(x1,x2,x3)=5.4449e-004*x1^2+0.0036*x2^2+0.0016*x3^2+11.8000e-008*x1*x2+7.2e-0088x1x3+18.39e-008*x2*x3 x1+x2+x3=1(3)、求解方法:第一步:画出A、B、C三只股票49个周末收盘价的变化情况的图像(便于分析问题);第二步:求出A、B、C三只股票49个周末收盘价的期望收益率Ea、Eb、Ec ;第三步:求出A、B、C三只股票49个周末收盘价的方差Da、Db、Dc ;第四步:求出A、B、C三只股票收益率分布直间的协方差:Dab、Dac、Dbc;第五步:求出投资风险最小和此时的收益率。

相关文档
最新文档