文档库 最新最全的文档下载
当前位置:文档库 › 实验二 MATLAB基础知识(二)

实验二 MATLAB基础知识(二)

实验二 MATLAB基础知识(二)
实验二 MATLAB基础知识(二)

Experiment 1. Fundamental Knowledge of Matlab (II) 【Experimental Purposes】

1、熟悉并掌握MATLAB的工作环境。

2、运行简单命令,实现数组及矩阵的输入输出,了解在MATLAB下如何绘图。【Experimental Principle】

1. Vectors

Let's start off by creating something simple, like a vector. Enter each element of the vector (separated by a space) between brackets, and set it equal to a variable. For example, to create the vector a, enter into the MATLAB command window (you can "copy" and "paste" from your browser into MATLAB to make it easy):

a = [1 2 3 4 5 6 9 8 7]

MATLAB should return:

a =

1 2 3 4 5 6 9 8 7

To generate a series that does not use the default of incrementing by 1, specify an additional value with the colon operator (first:step:last). In between the starting and ending value is a step value that tells MATLAB how much to increment (or decrement, if step is negative) between each number it generates. To generate a vector with elements between 0 and 20, incrementing by 2(this method is frequently used to create a time vector), use

t = 0:2:20

t =

0 2 4 6 8 10 12 14 16 18 20

Manipulating vectors is almost as easy as creating them. First, suppose you would like to add 2 to each of the elements in vector 'a'. The equation for that looks like:

b = a + 2

b =

3 4 5 6 7 8 11 10 9

Now suppose, you would like to add two vectors together. If the two vectors are the same length, it is easy. Simply add the two as shown below:

c = a + b

c =

4 6 8 10 12 14 20 18 16

Subtraction of vectors of the same length works exactly the same way.

MATLAB sometimes stores such a list in a matrix with just one row, and other times in a matrix with just one column. In the first instance, such a 1-row matrix is called a row-vector; in the

second instance, such a 1-column matrix is called a column-vector. Either way, these are merely different ways for storing vectors, not different kinds of vectors.

2. Matrices and Arrays

The most basic MATLAB data structure is the matrix: a two-dimensional, rectangularly shaped data structure capable of storing multiple elements of data in an easily accessible format. These data elements can be numbers, characters, logical states of true or false, or even other MATLAB structure types. MATLAB uses these two-dimensional matrices to store single numbers and linear series of numbers as well. In these cases, the dimensions are 1-by-1 and 1-by-n respectively, where n is the length of the numeric series. MATLAB also supports data structures that have more than two dimensions. These data structures are referred to as arrays in the MATLAB documentation.

MATLAB is a matrix-based computing environment. All of the data that you enter into MATLAB is stored in the form of a matrix or a multidimensional array. Even a single numeric value like 100 is stored as a matrix (in this case, a matrix having dimensions 1-by-1):

A = 100;

Name Size Bytes Class

A 1x1 8 double array

Entering matrices into MATLAB is the same as entering a vector, except each row of elements is separated by a semicolon (;) or a return:

B = [1 2 3 4;5 6 7 8;9 10 11 12]

B =

1 2 3 4

5 6 7 8

9 10 11 12

B = [ 1 2 3 4

5 6 7 8

9 10 11 12]

B =

1 2 3 4

5 6 7 8

9 10 11 12

The square brackets operator constructs two-dimensional matrices only, (including 0-by-0, 1-by-1, and 1-by-n matrices).

Matrices in MATLAB can be manipulated in many ways. For one, you can find the transpose of a matrix using the apostrophe key:

C = B'

C =

1 5 9

2 6 10

3 7 11

4 8 12

It should be noted that if C had been complex, the apostrophe would have actually given the complex conjugate transpose. To get the transpose, use .' (the two commands are the same if the matix is not complex).

Now you can multiply the two matrices B and C together. Remember that order matters when multiplying matrices.

D = B * C

D =

30 70 110

70 174 278

110 278 446

D= C * B

D =

107 122 137 152

122 140 158 176

137 158 179 200

152 176 200 224

Another option for matrix manipulation is that you can multiply the corresponding elements of two matrices using the .* operator (the matrices must be the same size to do this).

E = [1 2;3 4]

F = [2 3;4 5]

G = E .* F

E =

1 2

3 4

F =

2 3

4 5

G =

2 6

12 20

If you have a square matrix, like E, you can also multiply it by itself as many times as you like by raising it to a given power.

E^3

ans =

37 54

81 118

If wanted to cube each element in the matrix, just use the element-by-element cubing.

E.^3

ans =

1 8

27 64

You can also find the inverse of a matrix:

X = inv(E)

X =

-2.0000 1.0000

1.5000 -0.5000

or its eigenvalues:

eig(E)

ans =

-0.3723

5.3723

There is even a function to find the coefficients of the characteristic polynomial of a matrix. The "poly" function creates a vector that includes the coefficients of the characteristic polynomial.

p = poly(E)

p =

1.0000 -5.0000 -

2.0000

Remember that the eigenvalues of a matrix are the same as the roots of its characteristic polynomial:

roots(p)

ans =

5.3723

-0.3723

3. Functions

To make life easier, MATLAB includes many standard functions. Each function is a block of code that accomplishes a specific task. MATLAB contains all of the standard functions such as sin, cos, log, exp, sqrt, as well as many others. Commonly used constants such as pi, and i or j for the square root of -1, are also incorporated into MATLAB.

sin(pi/4)

ans =

0.7071

To determine the usage of any function, type help [function name] at the MATLAB command window. MATLAB even allows you to write your own functions with the function command; follow the link to learn how to write your own functions and see a listing of the functions we created for this tutorial.

4. Plotting

It is also easy to create plots in MATLAB. Suppose you wanted to plot a sine wave as a function of time. First make a time vector (the semicolon after each statement tells MATLAB we don't want to see all the values) and then compute the sin value at each time.

t=0:0.25:7;

y = sin(t);

plot(t,y)

The plot contains approximately one period of a sine wave. Basic

plotting is very easy in MATLAB, and the plot command has

extensive add-on capabilities. I would recommend you visit the

plotting page to learn more about it.

5. Polynomials

In MATLAB, a polynomial is represented by a vector. To create a polynomial in MATLAB, simply enter each coefficient of the polynomial into the vector in descending order. For instance, let's say you have the following polynomial:

432

31529s s s s +--+ To enter this into MATLAB, just enter it as a vector in the following manner

x = [1 3 -15 -2 9]

x =

1 3 -15 -

2 9

MATLAB can interpret a vector of length n+1 as an nth order polynomial. Thus, if your

polynomial is missing any coefficients, you must enter zeros in the appropriate place in the vector. For example,

4

1s + would be represented in MA TLAB as:

y = [1 0 0 0 1]

You can find the value of a polynomial using the polyval function. For example, to find the value of the above polynomial at s=2,

z = polyval([1 0 0 0 1],2)

z =

17

You can also extract the roots of a polynomial. This is useful when you have a high-order polynomial such as

432

31529s s s s +--+ Finding the roots would be as easy as entering the following command;

roots([1 3 -15 -2 9])

ans =

-5.5745

2.5836

-0.7951

0.7860

Let's say you want to multiply two polynomials together. The product of two polynomials is found by taking the convolution of their coefficients. MATLAB's function conv that will do this for you.

x = [1 2];

y = [1 4 8];

z = conv(x,y)

z =

1 6 16 16

Dividing two polynomials is just as easy. The deconv function will return the remainder as well as the result. Let's divide z by y and see if we get x.

[xx, R] = deconv(z,y)

xx =

1 2

R =

0 0 0 0

As you can see, this is just the polynomial/vector x from before. If y had not gone into z evenly, the remainder vector would have been something other than zero.

If you want to add two polynomials together which have the same order, a simple z=x+y will work (the vectors x and y must have the same length). In the general case, the user-defined function, polyadd can be used. To use polyadd, copy the function into an m-file, and then use it just as you would any other function in the MATLAB toolbox. Assuming you had the polyadd function stored as a m-file, and you wanted to add the two uneven polynomials, x and y, you could accomplish this by entering the command:

z = polyadd(x,y)

x =

1 2

y =

1 4 8

z =

1 5 10

【Experiment contents and procedure】

1、运行简单命令,实现数组及矩阵的输入输出;

2、运行特殊矩阵的输入及输出;

MATLAB has a number of functions that create different kinds of matrices. Some create specialized matrices like the Hankel or Vandermonde matrix. The functions shown in the table below create matrices for more general use.

However, you can easily build basic arrays of any numeric type using the ones, zeros, and eye functions.

A = magic(5)

A =

17 24 1 8 15

23 5 7 14 16

4 6 13 20 22

10 12 19 21 3

11 18 25 2 9

Note that the elements of each row, each column, and each main diagonal add up to the same value: 65.

3、进行简单的MATLAB绘图;

4、多项式的输入及输出。

【Experimental report】

1、综述MATLAB基本输入输出命令的功能;

2、简述在MATLAB下如何输出图形,如何查询未知函数。

3、选择课本中的实例,实现单位阶跃响应及时域分析。

MATLAB实验报告(1-4)

信号与系统MATLAB第一次实验报告 一、实验目的 1.熟悉MATLAB软件并会简单的使用运算和简单二维图的绘制。 2.学会运用MATLAB表示常用连续时间信号的方法 3.观察并熟悉一些信号的波形和特性。 4.学会运用MATLAB进行连续信号时移、反折和尺度变换。 5.学会运用MATLAB进行连续时间微分、积分运算。 6.学会运用MATLAB进行连续信号相加、相乘运算。 7.学会运用MATLAB进行连续信号的奇偶分解。 二、实验任务 将实验书中的例题和解析看懂,并在MATLAB软件中练习例题,最终将作业完成。 三、实验内容 1.MATLAB软件基本运算入门。 1). MATLAB软件的数值计算: 算数运算 向量运算:1.向量元素要用”[ ]”括起来,元素之间可用空格、逗号分隔生成行向量,用分号分隔生成列向量。2.x=x0:step:xn.其中x0位初始值,step表示步长或者增量,xn为结束值。 矩阵运算:1.矩阵”[ ]”括起来;矩阵每一行的各个元素必须用”,”或者空格分开; 矩阵的不同行之间必须用分号”;”或者ENTER分开。2.矩阵的加法或者减法运算是将矩阵的对应元素分别进行加法或者减法的运算。3.常用的点运算包括”.*”、”./”、”.\”、”.^”等等。

举例:计算一个函数并绘制出在对应区间上对应的值。 2).MATLAB软件的符号运算:定义符号变量的语句格式为”syms 变量名” 2.MATLAB软件简单二维图形绘制 1).函数y=f(x)关于变量x的曲线绘制用语:>>plot(x,y) 2).输出多个图像表顺序:例如m和n表示在一个窗口中显示m行n列个图像,p 表示第p个区域,表达为subplot(mnp)或者subplot(m,n,p) 3).表示输出表格横轴纵轴表达范围:axis([xmax,xmin,ymax,ymin]) 4).标上横轴纵轴的字母:xlabel(‘x’),ylabel(‘y’) 5).命名图像就在subplot写在同一行或者在下一个subplot前:title(‘……’) 6).输出:grid on 举例1:

MATLAB数学实验第二版答案(胡良剑)

数学实验答案 Chapter 1 Page20,ex1 (5) 等于[exp(1),exp(2);exp(3),exp(4)] (7) 3=1*3, 8=2*4 (8) a为各列最小值,b为最小值所在的行号 (10) 1>=4,false, 2>=3,false, 3>=2, ture, 4>=1,ture (11) 答案表明:编址第2元素满足不等式(30>=20)和编址第4元素满足不等式(40>=10) (12) 答案表明:编址第2行第1列元素满足不等式(30>=20)和编址第2行第2列元素满足不等式(40>=10) Page20, ex2 (1)a, b, c的值尽管都是1,但数据类型分别为数值,字符,逻辑,注意a与c相等,但他们不等于b (2)double(fun)输出的分别是字符a,b,s,(,x,)的ASCII码 Page20,ex3 >> r=2;p=0.5;n=12; >> T=log(r)/n/log(1+0.01*p) Page20,ex4 >> x=-2:0.05:2;f=x.^4-2.^x; >> [fmin,min_index]=min(f) 最小值最小值点编址 >> x(min_index) ans = 0.6500 最小值点 >> [f1,x1_index]=min(abs(f)) 求近似根--绝对值最小的点 f1 = 0.0328 x1_index = 24 >> x(x1_index) ans = -0.8500 >> x(x1_index)=[];f=x.^4-2.^x; 删去绝对值最小的点以求函数绝对值次小的点 >> [f2,x2_index]=min(abs(f)) 求另一近似根--函数绝对值次小的点 f2 = 0.0630 x2_index = 65 >> x(x2_index) ans = 1.2500

Matlab实验第一次实验答案

实验一Matlab使用方法和程序设计 一、实验目的 1、掌握Matlab软件使用的基本方法; 2、熟悉Matlab的数据表示、基本运算和程序控制语句 3、熟悉Matlab绘图命令及基本绘图控制 4、熟悉Matlab程序设计的基本方法 二、实验内容: 1、帮助命令 使用help命令,查找sqrt(开方)函数的使用方法; 解:sqrt Square root Syntax B = sqrt(X) Description B = sqrt(X) returns the square root of each element of the array X. For the elements of X that are negative or complex, sqrt(X) produces complex results. Remarks See sqrtm for the matrix square root. Examples sqrt((-2:2)') ans = 0 + 1.4142i 0 + 1.0000i

1.0000 1.4142 2、矩阵运算 (1)矩阵的乘法 已知A=[1 2;3 4]; B=[5 5;7 8]; 求A^2*B 解:A=[1 2;3 4 ]; B=[5 5;7 8 ]; A^2*B (2)矩阵除法 已知A=[1 2 3;4 5 6;7 8 9]; B=[1 0 0;0 2 0;0 0 3]; A\B,A/B 解:A=[1 2 3;4 5 6;7 8 9 ]; B=[1 0 0;0 2 0;0 0 3 ]; A\B,A/B (3)矩阵的转置及共轭转置

MATLAB基础教程 薛山第二版 课后习题答案

《MATLAB及应用》实验指导书《MATLAB及应用》实验指导书 班级:T1243-7 姓名:柏元强 学号:20120430724 总评成绩: 汽车工程学院 电测与汽车数字应用中心

目录 实验04051001 MATLAB语言基础 (1) 实验04051002 MATLAB科学计算及绘图 (18) 实验04051003 MATLAB综合实例编程 (31)

实验04051001 MATLAB语言基础 1实验目的 1)熟悉MATLAB的运行环境 2)掌握MATLAB的矩阵和数组的运算 3)掌握MATLAB符号表达式的创建 4)熟悉符号方程的求解 2实验内容 第二章 1.创建double的变量,并进行计算。 (1)a=87,b=190,计算 a+b、a-b、a*b。 clear,clc a=double(87); b=double(190); a+b,a-b,a*b (2)创建 uint8 类型的变量,数值与(1)中相同,进行相同的计算。 clear,clc a=uint8(87); b=uint8(190); a+b,a-b,a*b 2.计算:

(1) () sin 60 (2) e3 (3) 3cos 4??π ??? clear,clc a=sind(60) b=exp(3) c=cos(3*pi/4) 3.设2u =,3v =,计算: (1) 4 log uv v (2) () 2 2 e u v v u +- (3) clear,clc u=2;v=3; a=(4*u*v)/log(v) b=((exp(u)+v)^2)/(v^2-u) c=(sqrt(u-3*v))/(u*v) 4.计算如下表达式: (1) ()() 3542i i -+ (2) () sin 28i - clear,clc (3-5*i)*(4+2*i) sin(2-8*i)

实验二 Matlab程序设计基本方法1

实验二Matlab程序设计基本方法 覃照乘自092 电气工程学院 一、实验目的: 1、熟悉MATLAB 程序编辑与设计环境 2、掌握各种编程语句语法规则及程序设计方法 3、函数文件的编写和设计 4、了解和熟悉跨空间变量传递和赋值 二、实验基本知识: ◆for循环结构 语法:for i=初值:增量:终值 语句1 …… 语句n end 说明:1.i=初值:终值,则增量为1。 2.初值、增量、终值可正可负,可以是整数,也可以是小数,只须符合数学逻辑。 ◆while 循环结构 语法:while 逻辑表达式 循环体语句 end 说明:1、whiIe结构依据逻辑表达式的值判断是否执行循环体语勾。若表达式的值为真,执行循环体语句一次、在反复执行时,每次都要进行判断。若表达 式的值为假,则程序执行end之后的语句。 2、为了避免因逻辑上的失误,而陷入死循环,建议在循环体语句的适当位 置加break语句、以便程序能正常执行。(执行循环体的次数不确定; 每一次执行循环体后,一定会改变while后面所跟关系式的值。) 3、while循环也可以嵌套、其结构如下:

while逻辑表达式1 循环体语句1 while逻辑表达式2 循环体语句2 end 循环体语句3 end ◆if-else-end分支结构 if 表达式1 语句1 else if 表达式2(可选) 语句2 else(可选) 语句3 end end 说明:1.if结构是一个条件分支语句,若满足表达式的条件,则往下执行;若不满足,则跳出if结构。 2.else if表达式2与else为可选项,这两条语句可依据具体情况取舍。 3.注意:每一个if都对应一个end,即有几个if,记就应有几个end。 ◆switch-case结构 语法:switch表达式 case常量表达式1 语句组1 case常量表达式2 语句组2 …… otherwise 语句组n end

实验二 MATLAB程序设计 含实验报告

实验二 MATLAB 程序设计 一、 实验目的 1.掌握利用if 语句实现选择结构的方法。 2.掌握利用switch 语句实现多分支选择结构的方法。 3.掌握利用for 语句实现循环结构的方法。 4.掌握利用while 语句实现循环结构的方法。 5.掌握MATLAB 函数的编写及调试方法。 二、 实验的设备及条件 计算机一台(带有MATLAB7.0以上的软件环境)。 M 文件的编写: 启动MATLAB 后,点击File|New|M-File ,启动MATLAB 的程序编辑及调试器(Editor/Debugger ),编辑以下程序,点击File|Save 保存程序,注意文件名最好用英文字符。点击Debug|Run 运行程序,在命令窗口查看运行结果,程序如有错误则改正 三、 实验内容 1.编写求解方程02=++c bx ax 的根的函数(这个方程不一定为一元二次方程,因 c b a 、、的不同取值而定) ,这里应根据c b a 、、的不同取值分别处理,有输入参数提示,当0~,0,0===c b a 时应提示“为恒不等式!”。并输入几组典型值加以检验。 (提示:提示输入使用input 函数) 2.输入一个百分制成绩,要求输出成绩等级A+、A 、B 、C 、D 、E 。其中100分为A+,90分~99分为A ,80分~89分为B ,70分~79分为C ,60分~69分为D ,60分以下为E 。 要求:(1)用switch 语句实现。 (2)输入百分制成绩后要判断该成绩的合理性,对不合理的成绩应输出出错信息。 (提示:注意单元矩阵的用法) 3.数论中一个有趣的题目:任意一个正整数,若为偶数,则用2除之,若为奇数,则与3相乘再加上1。重复此过程,最终得到的结果为1。如: 2?1 3?10?5?16?8?4?2?1 6?3?10?5?16?8?4?2?1 运行下面的程序,按程序提示输入n=1,2,3,5,7等数来验证这一结论。 请为关键的Matlab 语句填写上相关注释,说明其含义或功能。 4. 的值,调用该函数后,

matlab实验二

实验2 MATLAB数值计算、符号运算功能 一、实验目的 1、掌握建立矩阵、矩阵分析与处理的方法。 2、掌握线性方程组的求解方法。 3、掌握数据统计和分析方法、多项式的常用运算。 4、掌握求数值导数和数值积分、常微分方程数值求解、非线性代数方程数值求解的方法。 5、掌握定义符号对象的方法、符号表达式的运算法则及符号矩阵运算、符号函数极限及导数、符号函数定积分和不定积分的方法。 二、预习要求 (1)复习4、5、6章所讲内容; (2)熟悉MATLAB中的数值计算和符号运算的实现方法和主要函数。 三、实验内容 1、已知 29618 20512 885 A -?? ?? =?? ?? - ?? ,求A的特征值及特征向量,并分析其数学意义。 >> A=[-29,6,18;20,5,12;-8,8,5]; >> [V,D]=eig(A) V = 0.7130 0.2803 0.2733 -0.6084 -0.7867 0.8725 0.3487 0.5501 0.4050 D = -25.3169 0 0 0 -10.5182 0 0 0 16.8351 V为A的特征向量,D为A的特征值,3个特征值是-25.3169、10.5182和16.8351。 >> A*V ans = -18.0503 -2.9487 4.6007 15.4017 8.2743 14.6886 -8.8273 -5.7857 6.8190 >> V*D

ans = -18.0503 -2.9487 4.6007 15.4017 8.2743 14.6886 -8.8273 -5.7857 6.8190 经过计算,A*V=V*D 。 2、 不用rot90函数,实现方阵左旋90°或右旋90°的功能。例如,原矩阵为A ,A 左旋后得到B ,右旋后得到C 。 147102581136912A ????=??????,101112789456123B ??????=??????,321654987121110B ??????=?????? 提示:先将A 转置,再作上下翻转,则完成左旋90°;如将A 转置后作左右翻转,则完成右旋转90°,可用flipud 、fliplr 函数。 >> a=[1 4 7 10;2 5 8 11;3 6 9 12] a= 1 4 7 10 2 5 8 11 3 6 9 12 >> B=rot90(a) B = 10 11 12 7 8 9 4 5 6 1 2 3 >>C= rot90(s,3) C= 3 2 1 6 5 4 9 8 7 12 11 10

昆明理工大学MATLAB实验指导书(第二次实验)

************************ MATLAB上机指导书 ************************ 昆明理工大学机电学院 彭用新 2015年3月

实验三符号计算 一、操作部分:在命令窗口执行命令完成以下运算,记录运算结果。 1.findsym:帮助我们获取系统定义的自变量 f= sym('sin(a*x+b*y)'); findsym(f) 2.numden(获取分子分母), sym2poly,(获取多项式时系数)poly2sym(根据多项式系 数获得符号表达式) [n,d]=numden(sym('x*x+y')+sym('y^2')) p=sym('2*x^3+3*x^2+4'); sym2poly(p) x=[2,3,0,4]; poly2sym(x) 3. collect :合并同类项;expand:展开多项式;horner: 分解成嵌套形式;factor:因式 分解;simplify: 对表达式化简 syms x y; collect(x^2*y+y*x-x^2-2*x) collect((x+y)*(x^2+y^2+1), y) syms x y; expand((x-2)*(x-4)) syms x;horner(x^3-6*x^2+11*x-6) syms x;factor(x^3-6*x^2+11*x-6) syms x;simplify((x^2+5*x+6)/(x+2)) 4. finverse :求得符号函数的反函数。 syms x y; finverse(1/tan(x)) f= x^2+y; finverse(f,y) finverse(f) https://www.wendangku.net/doc/451428899.html,pose 求符号函数的复合函数 syms x y; f = 1/(1 + x^2); g = sin(y); compose(f,g) 6. subs :表达式替换。 syms a b;subs(a+b,a,4)

Matlab程序设计与应用第二版刘卫国课后实验答案

. 实验一: T1: %%第一小题 z1=2*sin(85*pi/180)/(1+exp(2)) %%第二小题 x=[2,1+2i;-0.45,5]; z2=1/2*log(x+sqrt(1+x.^2)); z2 %%第三小题 a=-3.0:0.1:3.0; z3=1/2*(exp(0.3*a)-exp(-0.3*a)).*sin(a+ 0.3)+log((0.3+a)/2) %%第四题 t=0:0.5:2.5 z4=(t>=0&t<1).*(t.^2)+(t>=1&t<2).*(t .^2-1)+(t>=2&t<3).*(t.^2-2*t+1) T2: A=[12,34,-4;34,7,87;3,65,7] B=[1,3,-1;2,0,3;3,-2,7] disp ('A+6*B='); disp(A+6*B); disp('A-B+I=');disp(A-B+eye(3)); disp('A*B='); disp(A*B); disp('A.*B='); disp(A.*B); disp('A^3='); disp(A^3); disp('A.^3='); disp(A.^3); disp('A/B='); disp(A/B); disp('B\A='); disp(B\A); disp('[A,B]='); disp([A,B]); disp('[A([1,3],:);B^2]='); disp([A([1,3],:);B^2]); T3: z=1:25; A=reshape(z,5,5)'; B=[3,0,16;17,-6,9;0,23,-4;9,7,0;4,13,11]; C=A*B

MATLAB实验报告实验二

实验二 MATLAB矩阵及其运算 学号:3121003104 姓名:刘艳琳专业:电子信息工程1班日期:2014.9.20 一实验目的 1、掌握Matlab数据对象的特点以及数据的运算规则。 2、掌握Matlab中建立矩阵的方法以及矩阵处理的方法。 3、掌握Matlab分析的方法。 二实验环境 PC_Windows 7旗舰版、MATLAB 7.10 三实验内容 4、1. (1)新建一个.m文件,验证书本第15页例2-1; (2)用命令方式查看和保存代码中的所有变量;

(3)用命令方式删除所有变量; (4)用命令方式载入变量z。 2. 将x=[4/3 1.2345e-6]在以下格式符下输出:短格式、短格式e方式、长格式、长格式e方式、银行格式、十六进制格式、+格式。 短格式 短格式e 长格式

长格式e方式 银行格式 十六进制格式 3.计算下列表达式的值 (1)w=sqrt(2)*(1+0.34245*10^(-6)) (2)x=(2*pi*a+(b+c)/(pi+a*b*c)-exp(2))/(tan(b+c)+a) a=3.5;b=5;c=-9.8; (3)y=2*pi*a^2*((1-pi/4)*b-(0.8333-pi/4)*a) a=3.32;b=-7.9; (4)z=0.5*exp(2*t)*log(t+sqrt(1+t*t)) t=[2,1-3i;5,-0.65];

4. 已知A=[1 2 3 4 5 ;6 7 8 9 10;11 12 13 14 15;16 17 18 19 20],对其进行如下操作:(1)输出A在[ 7, 10]范围内的全部元素; (2)取出A的第2,4行和第1,3,5列; (3)对矩阵A变换成向量B,B=[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20]; (4)删除A的第2,3,4行元素; (1) (2)

MATLAB第二次上机实验报告

电子科技大学电子工程学院标准实验报告(实验)课程名称MATLAB与数值分析 学生姓名: 学号: 指导教师:

一、实验名称 实验二 线性方程组求解和函数的数值逼近 二、实验目的 通过上机实验,使学生对病态问题、线性方程组求解和函数的数值逼近方法有一个初步的理解。 实验涉及的核心知识点:病态方程求解、矩阵分解和方程组求解、Lagrange 插值。 实验重点与难点:算法设计和MATLAB 编程 三、实验内容 1. 对高阶多项式 ()()() ()()20 1 1220k p x x x x x k ==---=-∏ 编程求下面方程的解 ()190p x x ε+= 并绘图演示方程的解与扰动量ε的关系。 2. 对2 20n =,生成对应的Hilbert 矩阵,计算矩阵的条件数;通过先确定解获得常向量 b 的方法,确定方程组 ()n H x b = 最后,用矩阵分解方法求解方程组,并分析计算结果。 3. 对函数 ()2 1 125f x x = + []1,1x ∈- 的Chebyshev 点 ()()21cos 21k k x n π ?? -= ? ?+? ? ,1,2,,1k n =+ 编程进行Lagrange 插值,并分析插值结果。 四、实验数据及结果分析 1. 对高阶多项式

()()() ()()20 1 1220k p x x x x x k ==---=-∏ 编程求下面方程的解 ()190p x x ε+= 并绘图演示方程的解与扰动量ε的关系。 p=[1,-1]; for i=2:20 n=[1,-i]; p=conv(p,n); % 求多项式乘积 end m=zeros(1,21); % m 的最高次幂为20,有21项 hold on x=1:20; d=[-1,0,0.1,0.5,1]; for i=1:5 delt=d(i); m(2)=delt; y=(roots(p+m))'; % 求多项式的根 plot(x,y,'-o','color',[i/5,i/20,i/10]); end title('方程p(x)=0的解与扰动量delt 的关系') legend('delt=-1','delt=0','delt=0.1','delt=0.5','delt=1') 2468101214161820 010 20 30 40 50 60 方程p(x)=0的解与扰动量delt 的关系 delt=-1delt=0delt=0.1delt=0.5delt=1

南邮MATLAB数学实验答案(全)

第一次练习 教学要求:熟练掌握Matlab 软件的基本命令和操作,会作二维、三维几何图形,能够用Matlab 软件解决微积分、线性代数与解析几何中的计算问题。 补充命令 vpa(x,n) 显示x 的n 位有效数字,教材102页 fplot(‘f(x)’,[a,b]) 函数作图命令,画出f(x)在区间[a,b]上的图形 在下面的题目中m 为你的学号的后3位(1-9班)或4位(10班以上) 1.1 计算30sin lim x mx mx x →-与3 sin lim x mx mx x →∞- syms x limit((902*x-sin(902*x))/x^3) ans = 366935404/3 limit((902*x-sin(902*x))/x^3,inf) ans = 0 1.2 cos 1000 x mx y e =,求''y syms x diff(exp(x)*cos(902*x/1000),2) ans = (46599*cos((451*x)/500)*exp(x))/250000 - (451*sin((451*x)/500)*exp(x))/250 1.3 计算 22 11 00 x y e dxdy +?? dblquad(@(x,y) exp(x.^2+y.^2),0,1,0,1) ans = 2.1394 1.4 计算4 2 2 4x dx m x +? syms x int(x^4/(902^2+4*x^2)) ans = (91733851*atan(x/451))/4 - (203401*x)/4 + x^3/12 1.5 (10)cos ,x y e mx y =求 syms x diff(exp(x)*cos(902*x),10) ans = -356485076957717053044344387763*cos(902*x)*exp(x)-3952323024277642494822005884*sin(902*x)*exp(x) 1.6 0x =的泰勒展式(最高次幂为4).

MATLAB实验二(修改)

实验二 信号的表示及其基本运算 一、实验目的 1、掌握连续信号及其MATLAB 实现方法; 2、掌握离散信号及其MA TLAB 实现方法 3、掌握离散信号的基本运算方法,以及MA TLAB 实现 4 熟悉应用MATLAB 实现求解系统响应的方法 4、了解离散傅里叶变换的MA TLAB 实现 5、了解IIR 数字滤波器设计 6、了解FIR 数字滤波器设计1 二、实验设备 计算机,Matlab 软件 三、实验内容 (一)、 连续信号及其MATLAB 实现 1、 单位冲激信号 ()0,0()1,0 t t t dt ε ε δδε-?=≠??=?>??? 例1.1:单位冲击信号的MATLAB 实现程序如下: t1=-4; t2=4; t0=0; dt=0.01; t=t1:dt:t2; n=length(t); x=zeros(1,n); x(1,(-t0-t1)/dt+1)=1/dt; stairs(t,x); axis([t1,t2,0,1.2/dt]); 2、 任意函数 ()()()f t f t d τδττ+∞ -∞ =-? 例1.2:用MA TLAB 画出如下表达式的脉冲序列 ()0.4(2)0.8(1) 1.2() 1.5(1) 1.0(2)0.7(3)f n n n n n n n δδδδδδ=-+-+++++++ 3 单位阶跃函数 1,0()0, t u t t ?≥?=?

t=-0.5:0.001:1; t0=0; u=stepfun(t,t0); plot(t,u) axis([-0.5 1 -0.2 1.2]) 4 斜坡函数 0()()g t B t t =- 例1.4:用MA TLAB 实现g(t)=3(t-1) clear all; t=0:0.01:3; B=3; t0=1; u=stepfun(t,t0); n=length(t); for i=1:n u(i)=B*u(i)*(t(i)-t0); end plot(t,u) axis([-0.2 3.1 -0.2 6.2]) 5 抽样信号 抽样信号Sa(t)=sin(t)/t 在MATLAB 中用 sinc 函数表示。 定义为 )/(sin )(πt c t Sa = t=-3*pi:pi/100:3*pi; ft=sinc(t/pi); plot(t,ft); grid on; axis([-10,10,-0.5,1.2]); %定义画图范围,横轴,纵轴 title('抽样信号') %定义图的标题名字 6 指数函数 ()at f t Ae = 例1.5:用MA TLAB 实现0.5()3t f t e = 7 正弦函数 2()cos( )t f t A T π?=+ 例1.6:用MA TLAB 实现正弦函数f(t)=3cos(10πt+1) 8 虚指数信号 例 虚指数信号 调用格式是f=exp((j*w)*t) t=0:0.01:15;

MATLAB程序设计及应用(第二版)课后实验答案

Matlab 课后实验题答案 实验一 MATLAB 运算基础 1. 先求下列表达式的值,然后显示MATLAB 工作空间的使用情况并保存全部变量。 (1) 0 12 2sin851z e =+ (2) 221 ln(1)2z x x = ++,其中2120.45 5i x +??=??-?? (3) 0.30.330.3sin(0.3)ln , 3.0, 2.9,,2.9,3.022a a e e a z a a --+= ++=-- (4) 22 42011 122123t t z t t t t t ?≤=0&t<1).*(t.^2)+(t>=1&t<2).*(t.^2-1)+(t>=2&t<3) .*(t.^2-2*t+1) 2. 已知:

1234413134787,2033657327A B --???? ????==???? ????-???? 求下列表达式的值: (1) A+6*B 和A-B+I (其中I 为单位矩阵) (2) A*B 和A.*B (3) A^3和A.^3 (4) A/B 及B\A (5) [A,B]和[A([1,3],:);B^2] 解: M 文件: A=[12 34 -4;34 7 87;3 65 7];B=[1 3 -1;2 0 3;3 -2 7]; A+6.*B A-B+eye(3) A*B A.*B A^3 A.^3 A/B B\A [A,B] [A([1,3],:);B^2] 3. 设有矩阵A 和B 1234 53 166789101769,11 121314150 23416171819209 7021222324254 1311A B ???? ????-??? ?????==-??? ? ???????????? (1) 求它们的乘积C 。 (2) 将矩阵C 的右下角3×2子矩阵赋给D 。 (3) 查看MATLAB 工作空间的使用情况。 解:. 运算结果: E=(reshape(1:1:25,5,5))';F=[3 0 16;17 -6 9;0 23 -4;9 7 0;4 13 11]; C= E*F H=C(3:5,2:3) C = 93 150 77

Matlab实验

MATLAB实验报告 学校:湖北文理学院 学院:物理与电子工程学院 专业:电子信息工程 学号: 2013128182 姓名:张冲 指导教师:宋立新

实验一 MATLAB环境的熟悉与基本运算 一、实验目的: 1.熟悉MATLAB开发环境 2.掌握矩阵、变量、表达式的各种基本运算 二、实验内容 1、学习使用help命令,例如在命令窗口输入help eye,然后根据帮助说明, 学习使用指令eye(其它不会用的指令,依照此方法类推) 2、学习使用clc、clear,观察command window、command history和workspace 等窗口的变化结果。 3、初步程序的编写练习,新建M-file,保存(自己设定文件名,例如exerc1、 exerc2、exerc3……),学习使用MATLAB的基本运算符。 三、练习 1)help rand,然后随机生成一个2×6的数组,观察command window、 command history和workspace等窗口的变化结果。 2)学习使用clc、clear,了解其功能和作用。 3)用逻辑表达式求下列分段函数的值 4)求[100,999]之间能被21整除的数的个数。(提示:rem,sum的用法) 四、实验结果 1)

2)clc:清除命令窗口所有内容,数值不变;clear:初始化变量的值。3) 4)

实验二 MATLAB数值运算 一、实验目的 1、掌握矩阵的基本运算 2、掌握矩阵的数组运算 二、实验内容 1)输入C=1:2:20,则C(i)表示什么?其中i=1,2,3, (10) 2)输入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 3)二维数组的创建和寻访,创建一个二维数组(4×8)A,查询数组A第2 行、第3列的元素,查询数组A第2行的所有元素,查询数组A第6列的所有 元素。 4)两种运算指令形式和实质内涵的比较。设有3个二维数组A 2×4,B 2×4 ,C 2×2 , 写出所有由2个数组参与的合法的数组运算和矩阵指令。 5)学习使用表4列的常用函数(通过help方法) 6)学习使用表5数组操作函数。 7)生成一个3行3列的随机矩阵,并逆时针旋转90°,左右翻转,上下翻转。 8)已知a=[1 2 3],b=[4 5 6],求a.\b和a./ b 9)用reshape指令生成下列矩阵,并取出方框内的数组元素。 三、实验结果 1)C(i)表示C中的第i个的数值;

第二次数学实验报告Matlab 二维曲线绘图

《数学实验》报告实验名称 Matlab 二维曲线绘图 2011年 5月

一、【实验目的】 学习Matlab 绘图的运用,学会制作二维曲线,三维图形的绘画。 二、【实验任务】 P79 第3,5,9题。 1,在同一图形窗口画三个子图…… 2,绘制圆锥螺线的图像并加各种标注…… 3,画三维曲面z=5-x^2-y^2与平面z=3的交线。 三、【实验程序】 1. >> clear >> x=-pi:pi/50:4*pi; y1=x.*cos(x); y2=x.*tan(1./x).*sin(x.^3); y3=exp(1./x).*sin(x); subplot(3,1,1) plot(x,y1,'r*'),grid on title('y1=xcosx') xlabel('x轴'),ylabel('y轴') axis([-pi pi -pi pi]) gtext('y1=xcosx'),legend('y1=xcosx') subplot(3,1,2),plot(x,y2,'b'),grid on title('y=xtan(1/x)sin(x^3)') gtext('y=xtan(1/x)sin(x^3)') legend('y=xtan(1/x)sin(x^3)') axis([pi 4*pi -2 2]) subplot(3,1,3),plot(x,y3,'y'),grid on title('y=exp(1/x)sinx') xlabel('x轴'),ylabel('y轴') gtext('y=exp(1/x)sinx') legend('y=exp(1/x)sinx') axis([1 8 -3 3]) 2. >> clear >> t=0:pi/50:20*pi; x=t.*cos(pi/6.*t); y=t.*sin(pi/6.*t); z=2.*t; plot3(x,y,z) title('圆锥螺线') xlabel('x轴'),ylabel('y轴'),zlabel('z轴') >> t=0:pi/50:20*pi; x=t.*cos(pi/6.*t);

MATLAB程序设计与应用(第二版)刘卫国主编_部分实验答案

实验六 2_1 clear; x=linspace(0,2*pi,101); y1=x.^2; y2=cos(2.*x); y3=y1.*y2; plot(x,y1,'b-',x,y2,'r:',x,y3,'g-.'); %y1蓝色实线,y2红色虚线,y3绿色点画线 2_2 subplot(2,2,1); %分四个子图(先画2行2列第1块) plot(x,y1); subplot(2,2,2); plot(x,y2), subplot(2,2,3); plot(x,y3);

2_3 () subplot(3,4,1); %y1的四种图形bar(x,y1); subplot(3,4,2); stairs(x,y1), subplot(3,4,3); stem(x,y1); subplot(3,4,4); fill(x,y1,'b'); subplot(3,4,5); %y2 bar(x,y2); %条形图subplot(3,4,6); stairs(x,y2), %阶梯图subplot(3,4,7); stem(x,y2); %杆图subplot(3,4,8);

fill(x,y2,'b'); %填充图,注意必须加填充颜色 subplot(3,4,9); %y3 bar(x,y3); subplot(3,4,10); stairs(x,y3), subplot(3,4,11); stem(x,y3); subplot(3,4,12); fill(x,y3,'b'); 3 clear; x=-5:0.1:5; if x<=0 y=(x+sqrt(pi)/exp(2)); else y=0.5.*log(x+sqrt(1+x.^2));

Matlab实验二

实验二DFS和DFT 实验任务 1、阅读并输入实验原理中介绍的例题程序,观察输出的图形曲线,理解每一条语句的含义。 2、已知一个信号序列的主值为x(n)=[0,1,2,3,2,1,0],显示两个周期的信号序列波形,要求: (1)用DFS求信号的幅度频谱和相位频谱,用图形表示; (2)求IDFS的图形,并与原信号进行比较。 N = 7; xn = [0,1,2,3,2,1,0]; xn = [xn xn]; n = 0:2*N-1; k = 0:2*N-1; Xk = xn*exp(-j*2*pi/N).^(n'*k); x = (Xk*exp(j*2*pi/N).^(n'*k))/(2*2*N); subplot(2,2,1),stem(n,xn); title('x(n)');axis([-2,2*N,1.1*min(xn),1.1*max(xn)]); subplot(2,2,2),stem(n,abs(x)); title('IDFS|X(k)|');axis([-2,2*N,1.1*min(xn),1.1*max(xn)]); subplot(2,2,3),stem(k,abs(Xk)); title('|X(k)|');axis([-2,2*N,1.1*min(abs(Xk)),1.1*max(abs(Xk))]); subplot(2,2,4),stem(k,angle(Xk)); title('arg|X(k)|');axis([-2,2*N,1.1*min(angle(Xk)),1.1*max(angle(Xk)) ]);

3、已知有限长序列x(n)=[7,6,5,4,3,2],求x(n)的DFT 和IDFT ,要求: (1) 画出DFT 对应的()X k 和()arg X k ????的图形。 (2)画出原信号与傅里叶逆变换IDFT[X(k)]图形进行比较 xn = [7 6 5 4 3 2]; N = length(xn); n = 0:N-1; k = 0:N-1; Xk = xn*exp(-j*2*pi/N).^(n'*k); x = (Xk*exp(j*2*pi/N).^(n'*k))/N; figure,subplot(2,2,1),stem(n,xn); title('x(n)'); subplot(2,2,2),stem(n,abs(x)); title('IDFT|X(k)|'); subplot(2,2,3),stem(k,abs(Xk)); title('|X(k)|'); subplot(2,2,4),stem(k,angle(Xk)); title('arg|X(k)|'); axis([0,N,1.1*min(angle(Xk)),1.1*max(angle(Xk))]) 4、一周期序列的主值x(n)=[7,6,5,4,3,2],求x(n)周期周期重复次数为3次时的DFS 。要求: (1)画出原主值和信号周期序列信号; (2)画出序列傅里叶变换对应的()X k %和()arg X k ????%的图形。 xn = [7 6 5 4 3 2];

matlab实验内容答案

实验报告说明: matlab 课程实验需撰写8个实验报告,每个实验报告内容写每次实验内容中标号呈黑体大号字显示的题目。 第一次实验内容: 实验一 MATLAB 运算基础 一、实验目的 1.熟悉启动和退出MA TLAB 的方法。 2.熟悉MA TLAB 命令窗口的组成。 3.掌握建立矩阵的方法。 4.掌握MA TLAB 各种表达式的书写规则以及常用函数的使用。 二、实验内容 1.先求下列表达式的值,然后显示MA TLAB 工作空间的使用情况并保存全部变量。 (1)2 2sin 8511z e ?= + (2 )12ln(2 z x =+ ,其中2120.45 5i +? ? =? ?-?? (3)0.30.33sin(0.3), 3.0, 2.9, 2.8,,2.8,2.9,3.02 a a e e z a a --= +=--- 提示:利用冒号表达式生成a 向量,求各点的函数值时用点乘运算。 (4)2 2 2 01 41 1221 23 t t z t t t t t ?≤

12344347873657A -????=??????,131203327B -???? =????-?? 求下列表达式的值: (1)A+6=B 和A-B+I(其中I 为单位矩阵)。 (2)A*B 和A.*B 。 (3)A^3和A^.3 。 (4)A/B 和B\A 。 (5)[A ,B]和[A([1,3],;);B^2] 。 3.设有矩阵A 和B 12345678910111213141516171819202122232425A ????????=????????, 30 161769 23497041311B ?? ?? -?? ??=-?? ????? ? (1) 求它们的乘积C 。 (2) 将矩阵C 的右下角3×2子矩阵赋给D (3) 查看MA TLAB 工作空间使用情况。 4.完成下列操作: (1)求[100,999]之间能被21整除的数的个数。 提示:先利用冒号表达式,再利用find 和length 函数。 (2)建立一个字符串向量,删除其中的大写字母。 提示:利用find 函数和空矩阵。 第二次实验内容: 实验三 选择结构程序设计 一、实验目的 1. 掌握建立和执行M 文件的方法。 2. 掌握利用if 语句实现选择结构的方法。 3. 掌握利用switch 语句实现多分支选择结构的方法。 4. 掌握try 语句的使用。 二 、实验内容

相关文档
相关文档 最新文档