MATLAB机考样题(带答案)
matlab试题及答案

matlab试题及答案# MATLAB试题及答案一、选择题1. MATLAB的基本数据单位是:A. 矩阵B. 向量C. 标量D. 数组答案:A2. 下列哪个命令可以用来绘制函数图形?A. `plot`B. `graph`C. `draw`D. `chart`答案:A3. MATLAB中,以下哪个是正确的矩阵转置操作?A. `transpose(A)`B. `A'`C. `A^T`D. `flip(A)`答案:B二、简答题1. 简述MATLAB中矩阵的基本操作。
答案:在MATLAB中,矩阵是最基本的数据结构,可以进行加、减、乘、除等基本运算。
矩阵的创建可以使用方括号`[]`,例如`A = [1 2;3 4]`。
矩阵的转置使用单引号`'`,例如`A'`。
矩阵的求逆使用`inv`函数,例如`inv(A)`。
2. MATLAB中如何实现循环结构?答案:MATLAB中实现循环结构主要有两种方式:`for`循环和`while`循环。
`for`循环用于已知迭代次数的情况,例如:```matlabfor i = 1:5disp(i);end````while`循环用于迭代次数未知的情况,例如:```matlabi = 1;while i <= 5disp(i);i = i + 1;end```三、计算题1. 给定矩阵A和B,请计算它们的乘积C,并求C的行列式。
A = [1 2; 3 4]B = [5 6; 7 8]答案:首先计算矩阵乘积C:```matlabC = A * B;```然后计算C的行列式:```matlabdetC = det(C);```结果为:```matlabC = [19 22; 43 50]detC = -16```2. 编写一个MATLAB函数,计算并返回一个向量的范数。
答案:```matlabfunction norm_value = vector_norm(v)norm_value = norm(v);end```四、编程题1. 编写一个MATLAB脚本,实现以下功能:- 随机生成一个3x3的矩阵。
matlab开卷考试题及答案

matlab开卷考试题及答案MATLAB开卷考试题及答案一、选择题(每题2分,共20分)1. MATLAB中用于创建一个3x3的单位矩阵的命令是:A. `eye(3)`B. `ones(3)`C. `zeros(3)`D. `identity(3)`答案:A2. 下列哪个函数用于计算矩阵的逆?A. `inv()`B. `det()`C. `eig()`D. `trace()`答案:A3. MATLAB中,用于绘制二维图形的函数是:A. `plot()`B. `surf()`C. `mesh()`D. `bar()`答案:A4. 如何在MATLAB中计算向量的范数?A. `norm()`B. `abs()`C. `length()`D. `size()`答案:A5. MATLAB中,用于创建一个随机数矩阵的函数是:A. `rand()`B. `randi()`C. `randn()`D. `randperm()`答案:A6. 下列哪个命令用于在MATLAB中求解线性方程组?A. `solve()`B. `fsolve()`C. `fzero()`D. `linsolve()`答案:A7. MATLAB中,用于计算矩阵的行列式的函数是:A. `det()`B. `trace()`C. `eig()`D. `inv()`答案:A8. 如何在MATLAB中创建一个全1的3x3矩阵?A. `ones(3,3)`B. `eye(3,3)`C. `zeros(3,3)`D. `rand(3,3)`答案:A9. MATLAB中,用于计算矩阵的特征值的函数是:A. `eig()`B. `eigs()`C. `svd()`D. `qr()`答案:A10. 下列哪个函数用于计算矩阵的奇异值分解?A. `eig()`B. `svd()`C. `qr()`D. `lu()`答案:B二、填空题(每题3分,共30分)1. MATLAB中,用于创建一个3x3的零矩阵的命令是 `____`。
Matlab考试题库带上答案

一、辨析题(共2小题,每题 5 分,共计 10 分)二、问答题(共3小题,每题 5 分,共计 15 分)三、计算题(共7小题,每题 5 分,共计 35 分)四、编程题(共4小题,每题 10 分,共计 40 分)填空题(计算部分)1、标点符号; _______可以使命令行不显示运算结果,%——用来表示该行为注释行。
2、x为0~4pi,步长为0.1pi的向量,使用命令_______创建。
x=0:0.1*pi:4*pi3、输入矩阵A=,使用全下标方式用A(2,2) 取出元素“-5”,使用单下标方式用_______取出元素“-5”。
A(5)4、符号表达式sin(2*a+t)+m中独立的符号变量为_______。
t5、M脚本文件和M函数文件的主要区别是M脚本文件没有函数定义和M函数文件有函数定义_______。
6. 设x是一维数组,x的倒数第3个元素表示为_______;设y为二维数组,要删除y的第34行和48列,可使用命令_______; _______;x(_end-2_)y(34,:)=[]y(:,48)=[]7. 将变量x以Ascii文本格式存储到文件fname.txt,应使用命令_________ _;save _x8. 在while 表达式, 语句体, End 循环语句中,表达式的值__ __时表示循环条件为真,语句体将被执行,否则跳出该循环语句;非零9.要从键盘读入一个字符串并赋值给变量x,且给出提示“Who is she?”,应使用命令_________;x=input(‘Who is she?’,’s’)_10.设A=和B=和C=均为m*n矩阵,且存在于WorkSpace 中,要产生矩阵D=,可用命令________ _,计算可用命令________;D=(A-C)/B.^Cdet(inv(A’*B)11. 在MATLAB命令窗口中的“>>”标志为MATLAB的_______提示符,“│”标志为_______提示符。
Matlab试题和答案

M a t l a b试题和答案(总7页)--本页仅作为文档封面,使用时请直接删除即可----内页可以根据需求调整合适字体及大小--Matlab 上机考试试题考试要求:1、从10道题目中随机抽取3道独立完成,时间1小时。
(输入randperm (10),取前三个数)2、每个题目兴建一个.m的文件,命名方式ks+N.m(N为题号),然后将所选三个题目放入一个文件夹,文件名为学号+姓名。
考试完成后将文件夹通过FTP 提交。
3、考试完成后要写一份报告,内容包括以下:(建一个.Doc的文档,文件名为学号+姓名)(1)题号,题目;(2)运行结果及其分析;(3)图也要粘贴在文档中。
4、查阅资料写一篇2000字左右的关于matlab在电子信息中的应用的小论文或综述,也可以具体的写matlab在电子信息中某一个方面或某一个点的应用。
(打印或手写都可,打印版要交电子文档)5、所有要交的东西在1月3号之前必须交齐。
(由学习委员统一收齐交给我,电子文档也拷到学习委员处,统一拷给我)。
所交项目包括:考试报告打印版,小论文打印版(两个装订在一起,考试报告在上,小论文在下,最好做一个统一的封皮),考试报告doc文档,小论文doc文档。
Matlab 上机考试试题1.求下列联立方程的解3x+4y-7z-12w=45x-7y+4z+ 2w=-3X +8z- 5w=9-6x+5y-2z+10w=-8(1)求系数矩阵的秩; (2)求出方程组的解。
2.在[-10,10;-10,10]范围内画出函数2222 sinyx yx z++=的三维图形。
3.试画出系统321()221H s s s s =+++的零极点分布图,判断系统是否稳定,同时求其单位冲激响应和频率响应(幅频特性和相频特性)。
4. 将一个屏幕分4幅,选择合适的步长在右上幅与左下幅绘制出下列函数的图形。
(1)]22[)cos(ππ,,-∈x x (曲线图); (2)4)y 2,-4x (-242),(2222≤≤≤≤+=;y x y x f (曲面图)。
matlab上机考试题及答案

matlab上机考试题及答案1. 题目:编写一个MATLAB函数,计算并返回一个向量中所有元素的平方和。
答案:函数定义如下:```matlabfunction sumOfSquares = calculateSumOfSquares(vector)sumOfSquares = sum(vector.^2);end```2. 题目:使用MATLAB的内置函数,找出一个矩阵中的最大元素及其位置。
答案:可以使用`max`函数来找出矩阵中的最大元素,同时使用`find`函数来获取其位置。
示例代码如下:```matlabA = [1, 2, 3; 4, 5, 6; 7, 8, 9];[maxValue, linearIndex] = max(A(:));[row, col] = ind2sub(size(A), linearIndex);```3. 题目:给定一个向量,使用MATLAB编写代码,实现向量元素的逆序排列。
答案:可以使用`flip`函数来实现向量的逆序排列。
示例代码如下:```matlabvector = [1, 2, 3, 4, 5];reversedVector = flip(vector);```4. 题目:编写一个MATLAB脚本,计算并绘制一个正弦波的图像。
答案:可以使用`sin`函数生成正弦波数据,并使用`plot`函数绘制图像。
示例代码如下:```matlabx = linspace(0, 2*pi, 100);y = sin(x);plot(x, y);xlabel('x');ylabel('sin(x)');title('Sine Wave');```5. 题目:给定一个3x3的矩阵,使用MATLAB编写代码,计算其行列式。
答案:可以使用`det`函数来计算矩阵的行列式。
示例代码如下:```matlabmatrix = [1, 2, 3; 4, 5, 6; 7, 8, 9];determinant = det(matrix);```结束语:以上是MATLAB上机考试的题目及答案,希望能够帮助大家更好地掌握MATLAB的编程技巧和函数使用。
matlab试题及答案开卷

matlab试题及答案开卷1. MATLAB基础操作在MATLAB中,如何创建一个名为“myMatrix”的3x3矩阵,其元素从1到9按顺序排列?答案:在MATLAB中,可以使用以下命令创建名为“myMatrix”的3x3矩阵:```matlabmyMatrix = [1 2 3; 4 5 6; 7 8 9];```或者使用内置函数`magic`:```matlabmyMatrix = magic(3);```2. 矩阵运算给定两个矩阵A和B,其中A = [2 3; 4 5],B = [6 7; 8 9],计算A+B的结果。
答案:在MATLAB中,可以使用加号`+`来计算两个矩阵的和:```matlabA = [2 3; 4 5];B = [6 7; 8 9];C = A + B;```计算结果C为:```matlabC = [8 10; 12 14];```3. 向量操作创建一个从0到1的等差数列,步长为0.1。
答案:在MATLAB中,可以使用`linspace`函数或`:`操作符来创建等差数列:```matlabv = 0:0.1:1;```或者使用`linspace`函数:```matlabv = linspace(0, 1, 11);```两种方法都将得到一个包含11个元素的向量,从0开始,到1结束,步长为0.1。
4. 条件语句编写一个MATLAB脚本,判断一个给定的数n是否为素数。
答案:可以通过以下MATLAB脚本来判断一个数n是否为素数:```matlabfunction isPrime = isPrimeNumber(n)if n <= 1isPrime = false;elsefor i = 2:sqrt(n)if mod(n, i) == 0isPrime = false;return;endendisPrime = true;endend```调用此函数时,传入一个数值n,函数将返回一个布尔值,表示n 是否为素数。
matlab试题及答案

matlab试题及答案一、单项选择题(每题2分,共10分)1. MATLAB中用于创建向量的命令是:A. vectorB. arrayC. linspaceD. colon答案:D2. 在MATLAB中,以下哪个函数用于计算矩阵的行列式?A. detB. rankC. invD. eig答案:A3. MATLAB中用于进行矩阵转置的运算符是:A. 'B. .C. ^D. !答案:A4. 若A是一个3x3的矩阵,执行命令A(2,:)=0;后,矩阵A的第二行将变为:A. [0 0 0]B. [1 0 0]C. [0 1 0]D. [0 0 1]答案:A5. MATLAB中,以下哪个函数用于绘制三维曲面图?A. plotB. surfC. barD. hist答案:B二、填空题(每题3分,共15分)1. MATLAB中,使用________命令可以清除所有变量。
答案:clear2. 若要在MATLAB中创建一个从0到1的100个元素的向量,可以使用命令________。
答案:linspace(0,1,100)3. MATLAB中,使用________函数可以计算矩阵的特征值。
答案:eig4. 在MATLAB中,________函数用于计算两个矩阵的点乘。
答案:dot5. 若要在MATLAB中绘制一个圆,可以使用________函数。
答案:plot三、简答题(每题5分,共20分)1. 请解释MATLAB中矩阵索引的概念。
答案:在MATLAB中,矩阵索引指的是通过行号和列号来访问矩阵中特定元素的过程。
例如,A(2,3)表示访问矩阵A的第二行第三列的元素。
2. MATLAB中如何实现矩阵的元素乘法?答案:在MATLAB中,矩阵的元素乘法可以通过使用点乘运算符(.*)来实现。
例如,C = A .* B,其中A和B是相同大小的矩阵。
3. 请说明MATLAB中如何使用循环结构。
答案:MATLAB中可以使用for循环和while循环两种循环结构。
Matlab上机题库及详细答案

case num2cell(25:49) %价格大于等于2500但小于5000
Байду номын сангаасrate=10/100;
otherwise %价格大于等于5000
rate=14/100;
end
price=price*(1-rate) %输出商品实际销售价格
例19已知,当n=100时,求的值。
解:程序如下:
y=0;n=100;for i=1:n;y=y+1/(2*i-1);End
例20:一个三位整数各位数字的立方和等于该数本身则称该数为水仙花数。输出全部水仙花数
解:for m=100:999
m1=fix(m/100);m2=rem(fix(m/10),10);m3=rem(m,10);
if m==m1*m1*m1+m2*m2*m2+m3*m3*m3;disp(m);end
D=diag(1:5);D*A %用D左乘A,对A的每行乘以一个指定常数
例15:输入x,y的值,并将它们的值互换后输出。
程序如下:
x=input('Input x please.');y=input('Input y please.');z=x;x=y;y=z;
disp(x);disp(y);
例16::求一元二次方程ax2 +bx+c=0的根。
switch fix(price/100)
case {0,1} %价格小于200
rate=0;
case {2,3,4} %价格大于等于200但小于500
rate=3/100;
case num2cell(5:9) %价格大于等于500但小于1000
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
MATLAB 机考样题:(1)Generate and plot sequence121[]2cos() [][4]8x n n and x n x n π==-, with 20n 20-≤≤.n1=-20:20;x1=2*cos(pi/8*n1);n2=n1-4;x2=2*cos(pi/8*n2);subplot(2,1,1);plot(n1,x1);subplot(212);plot(n2,x2); (2)Write a MATLAB program to compute and plot the impulse response of a causal finite-dimensional discrete-time system characterized by a difference equation of the following form:3]-x[n 86.0 2]-1.32x[n 1]-0.34x[n x[n]8.13]-0.72y[n -2]-0.5y[n 1]-0.3y[n y[n]--+=++N=input('请输入你要求的点数N=');num=[1.8 0.34 -1.32 -0.86];den=[1 0.3 0.5 -0.72]; x=[1 zeros(1,N-1)];(单位冲击)y=filter(num,den,x);plot(0:N-1,y);(3)Write a MATLAB program to compute and display the poles and zeros , to compute and display the second-order factored form , and to generate the pole-zero plot of a z-transform that is a ratio of two polynomials in z -1. Using this program to analyze the following G(z):3213211768.018.052.115.1082.2393.61.8)(-------+++-+=z z z z z z z Hnum=[8.1 6.93 -23.82 10.5];den=[1 1.52 0.18 -0.1768];sos=tf2sos(num,den) %tf2sos 表示为1/z 的升幂zplane(num,den)(4)Try to give a program to evaluate the following DTFT in the range πω≤≤0 :ωωωωωωωω4324321245535952)(j j j j j j j j e e e e e e e e z G --------++++++++=%由于用freqz 计算频点至少是2个,所以至少输入两个频点w1=input('请输入你要计算的频点w1=');w2=input('请输入你要计算的频点w2=');w=[w1 w2];num=[2 5 9 5 3];den=[5 45 2 1 1];h=freqz(num,den,w)(6)Write a MATLAB program to compute and plot the magnitude response of a causal LTI discrete-time system with a transfer function given by2127.05.01)1(15.0)(---+--=z z z z Hnum=0.15*[1 0 -1];den=[1 -0.5 0.7];[h,w]=freqz(num,den,512);plot(w/pi,abs(h)); (7)Consider the following FIR transfer function:123456()10.60.490.480.140.120.09H z z z z z z z ------=++---+Using MATLAB to determine its zero locations and plot its magnitude and phase response.h=[1 0.6 .49 -0.48 -0.14 -0.12 0.09];figure(1)zplane(h,1);[H,w]=freqz(h,1,512);figure(2)plot(w/pi,abs(H));figure(3)plot(w/pi,angle(H));(8)Given a signal ()4cos0.1x t t t π=+, when using a sampling frequency f T = 20KHz, plot the magnitude and phase spectrum of the sampled sequence(given length-64).fs=2e4;n=0:63;x=4*n/fs+cos(0.1*pi*n/fs);h=fft(x,1024);figure(1);plot(0:2/1023:2,abs(h));figure(2);plot(0:2/1023:2,angle(h));(9)design an IIR butterworth digital lowpass filter with the following specifications: sampling rate of 40kHz, passband edge frequency of 4kHz, stopband edge frequency of 8kHz, passband ripple of 0.5dB, and a minimum stopbandattenuation of 40dB,plot frequency-magnitude and check if your design fits the specification.fs=40;wp=4*2/fs; %wp<1,没有乘piws=8*2/fs; %ws<1,没有乘piap=0.5;as=40;[n,wn]=buttord(wp,ws,ap,as);[num,den]=butter(n,wn);[h,w]=freqz(num,den,512);figure(1);plot(w/pi,20*log10(abs(h)));axis([0 1 -50 0]);figure(2);subplot(2,1,1);plot(w/pi,20*log10(abs(h)))axis([0 wp -0.5 0]);title('通带纹波');subplot(2,1,2);plot(w/pi,20*log10(abs(h)));axis([ws 1 -50 -30]);title('阻带纹波');(10)Design a Hanning FIR lowpass filter meeting the following specifications: passband edge frequency=2kHz, stopband edge frequency=2.5kHz, passband ripple δp=0.005, stopband rippleδs=0.005, and sampling rate of 10kHz.Plot its gain and phase responses and check if it meets the specifications?ft=10;fp=2;fs=2.5;wp=2*pi*fp/ft;ws=2*pi*fs/ft;ds=0.005;ap=20*log10(1-ds)as=20*log10(ds)wc=(wp+ws)/2;dw=ws-wp;M=ceil(3.11*pi/dw);N=2*M;b=fir1(N,wc/pi,hann(N+1));[h,w]=freqz(b,1,512);figure(1);plot(w/pi,20*log10(abs(h)));axis([0 1 -50 0]);title('magitude response');figure(2);plot(w/pi,unwrap(angle(h)));title('phase response');figure(3);subplot(211);plot(w/pi,20*log10(abs(h)));axis([0 wp/pi ap 0]);title('通带纹波')subplot(212);plot(w/pi,20*log10(abs(h)));axis([ws/pi 1 as 0]);title('阻带纹波');%从图中可以看出,通带和阻带中纹波都不满足要求,所以不满足指标%as= -46.0206<43.9 所以不能用hanning 窗设计%应当用hamming 或blackman 窗设计(11)Writing a MATLAB program to compute 128-point DFT of the followingsequence, you must firstly use DFT definition (directly computing DFT) to compute and use MATLAB function to test the result. Plot the two results in one figure.n=0:31;k=1:128;x=sin(pi*n/4);Xk1=zeros(1,128);for t=1:128 for m=1:32Xk1(t)=Xk1(t)+x(m)*exp(-1i*2*pi*(t-1).*(m-1)/128);endendsubplot(2,1,1);plot(k,Xk1);Xk2=fft(x,128);subplot(2,1,2);plot(k,Xk2);(12)Using the function fir1 and window of Kaiser, design a linear-phase FIR lowpass filter meeting the following specifications: passband edge frequency=2kHz, stopband edge frequency=2.5kHz, passband ripple δp=0.005, stopband ripple δs=0.005, and sampling rate of 10kHz.Plot its gain and phase responses and check if it meets the specifications?Design a Type 1 Chebyshev IIR lowpass filter meeting the specifications as below: sampling rate of 12kHz, passband edge frequency of 2.1kHz, stopband edge frequency of 2.7kHz, passband []sin(4),031g n n n π=≤≤ripple of 0.6dB, and a minimum stopband attenuation of 45dB. Write down the exact expression for the transfer function generated. Does your design meet the specifications?Fp=2100;Fs=2700;Ft=12000;Rp=0.6;Rs=45;Wp=2*Fp/Ft;Ws=2*Fs/Ft;[N,Wn]=cheb1ord(Wp,Ws,Rp,Rs)[B,A]=cheby1(N,Rp,Wn)[h,w]=freqz(B,A,512);figure(1);plot(w/pi,20*log10(abs(h)));axis([0 1 -50 0]);figure(2);subplot(2,1,1);plot(w/pi,20*log10(abs(h)))axis([0 Wp -0.6 0]);title('通带纹波');subplot(2,1,2);plot(w/pi,20*log10(abs(h)));axis([Ws 1 -50 -30]);title('阻带纹波');(13)Using the function fir1 and window of Kaiser, design a linear-phase FIR lowpass filter meeting the following specifications: passband edge frequency=2kHz, stopband edge frequency=2.5kHz, passband ripple δp=0.005, stopband rippleδs=0.005, and sampling rate of 10kHz.Plot its gain and phase responses and check if it meets the specifications?[n,wn,beta,typ]=kaiserord([2000 2500],[1 0],[0.005 0.005],10000);b=fir1(n,wn,kaiser(n+1,beta),'noscale');[h,omega]=freqz(b,1,256);subplot(2,1,1);plot(omega/pi,20*log10(abs(h)));xlabel('\omega/\pi'); ylabel('Gain, dB');subplot(2,1,2)plot(omega/pi,angle(h));gridtitle('Phase Spectrum');xlabel('\omega/\pi'); ylabel('Phase, radians');(14)Given a signal when using a sampling frequency fT= 20KHz, plot the magnitude and phase spectrum of the sampled sequence(givenlength-64). ft=20000;n=1:64;x=sin(0.1*pi*n/ft)+2*cos(0.3*pi*5*n/ft)+3*sin(0.5*pi*n/ft); subplot(2,1,1);[h,w]=freqz(x,1,256);plot(w/pi,abs(h));title('Magnitude spectrum of the sampled samples');xlabel('\omega/\pi'); ylabel('Magnitude');subplot(2,1,2);plot(w/pi,angle(h));title('Phase spectrum of the sampled samples');xlabel('\omega/\pi'); ylabel('Phase');(15)Write a MATLAB program to compute the first L samples of the inverse of rational z-transforms where the value of L is provided by the user through the command input. Using this program to compute and plot the first 50 samples of the inverse of following G(z). Use the command stem for plotting the sequence generated by the inverse transform L=input('input the L=');r=[10/4 -8/2];p=[-1/4 -1/2];k=-2;[B,A]=residuez(r,p,k)[h t]=impz(B,A,L)stem(t,h);Writing a MATLAB program to compute the circular convolution of two length-N sequences via the DFT-based approach. Using this program to determine the following pair of sequences:g[n]={7, 4, -9, 0, 2, -5}, h[n]={1, -1, 2, 0, 10, 5} orAnd plot the result sequencex1=[7 4 -9 0 2 -5];x2=[1 -1 2 0 10 5];L=length(x1);y=zeros(1,L);x2tr = [x2(1) x2(L:-1:2)];for k = 1:L,sh = circshift(x2tr', k-1)';h = x1.*sh;y(k) = sum(h);enddisp(y);()sin(0.1)2cos(0.3)3sin(0.5)x t t t t πππ=++5.0||,284102)(113>+-++-=--z z z z Gn=0:length(x1)-1;stem(n,y);n=0:50;x=sin(5*pi*n/16);stem(n,x); %或者如下syms n1; %x1=x’x1=sin(5*pi*n1/16).^2; %y=x*x1y=symsum(x1,n1,0,50)y1=double(y)。