搜档网
当前位置:搜档网 › MATLAB实验报告(8个实验)

MATLAB实验报告(8个实验)

MATLAB实验报告(8个实验)
MATLAB实验报告(8个实验)

四川师范大学MATLAB语言实验报告1

系级班年月日

实验名称:Intro, Expressions, Commands

姓名学号指导教师成绩1Objective

The objective of this lab is to familiarize you with the MATLAB program development environment and to develop your first programs in this environment.

2Using MATLAB

2.1Starting MATLAB

Logon 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) created

during the current MATLAB session and stored in memory.

●Command History (on the lower left side) logs commands entered in the

Command 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 Commands

You 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 ^3

You can see the variables a, b and c with their types and sizes on the Workspace

window, and can see the commands on the Command History window.

Spend a few minutes to practice defining array variables (i.e. vectors and matrices)

using

the 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 Help

There are several ways to get help on commands and functions in MATLAB. First of

all you can use the Help menu. You can also use the “?” button. Try to find

information on the plot function from the help index. Also try to get information on

the same function using the help command (i.e. type help plot). Finally, experiment

with the lookfor command. This command looks for other commands related to a

given keyword.

2.4 Some Useful Commands

Try the following commands and observe their results:

Which : Version and location info

Clear : Clears the workspace

Clc : Clears the command window

who, whos : Lists content of the workspace

3 Exercises

Please solve the following problems in MATLAB. Do not forget to keep a diary of

your 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 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.11

4Quitting MATLAB

Typing 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

姓名学号指导教师成绩1Objective

The objective of this lab is to familiarize you with the MATLAB script files (M-files), subarrays, relational and logical operators.

2Script Files

Script 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 current

directory to ‘TA’s suggest’.

3Subarrays

It 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 array

subscripts. The end function always returns the highest value taken on by a given

subscript. It is also possible to use subarrays on the left-hand side of an assignment

statement to change only some of the values in an array. If values are assigned to a

subarray, only those values are changed but if values are assigned to an array, the

entire contents of the array are replaced by the new values.

(1) Define the following 5 x 5 array arr1 in MATLAB.

????????????????----=2274235421209518

171651413215111012844563311arr

(2) Write a MATLAB statement to select a subset of arr1 and return the subarray

containing the values as shown.

??????=22745456311arr

arr11=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.

????????????????-=2257462335432112arr

arr2=arr1([1 5],:)';

4 Relational and Logical Operators

Relational and logical operators are the two types of operators that produce true/false

results in MATLAB programs. MATLAB interprets a zero value as false and any

nonzero value as true. Relational operators ( ==, =,>,>=,<,<=) are operators with two

operands that produce either a true (1) or a false (0) result, depending on the values of

the 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 same

size. Be careful not to confuse the equivalence relational operator ( == ) with the

assignment operator ( = ). Logic operators ( &, |, xor, ~ ) are operators with one or

two operands that yield a logical result such as 0 or 1. There are three binary logic

operators: AND (& ), OR ( |), and exclusive OR ( xor ); and one unary operator: NOT

( ~ ). In the hierarchy of operations, logic operators are evaluated after all

arithmetic and relational operators have been evaluated. The operator is evaluated

before 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 following

result.

????????????=110001110011110111115arr

arr5=arr4>0;

(3) Write an expression using arr4 and a relational operator to produce the following

result.

????????????=010000010000010000016arr

arr6=arr4==1;

(4) Write a MATLAB program which will generate an (n-1)x(n-1) matrix from a

given nxn matrix which will be equal to given matrix with first row and first

column deleted.

arr44=rand(5); arr444=arr35(2:end,2:end);

(5) Generalize your program above so that the program should ask the row and

column 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 MATLAB

Typing 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 语言实验报告3

系 级 班 年 月 日

实验名称:Branches and Loops, Logical Arrays.

姓名 学号 指导教师 成绩 1 Objective

The objective of this lab is to familiarize you with the MATLAB Branches and Loops,

Logical Arrays.

2 Exercises

Do not forget to add sufficient documentation and proper indentation to all programs

you write.

(1) Write a program that calculates follow equation with for and while loop, and write

a program without loop.

63

263022212+++==∑=Λi i K

% for loop

k1=0;

for ii=1:64

k1=k1+2^(ii-1);

end

% while loop

k2=0;

n=0;

while n>=0&n<64

k2=k2+2^n;

n=n+1;

end

% without loop

a=0:63;

b=2.^a;

K3=sum(b);

(2) Write a program that accepts a vector of integers as input and counts the number

of integers that are multiples of 3 in that vector. You can assume that the input

contains 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 121

Write a program that will accept an arbitrary number of input values and calculate

the rmsaverage of the numbers. The program should ask the user for the number

of 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

% Initialize

sum_x2=0;

% Get the number of points to input.

n=input('Enter number of points:');

% Loop to read input values

for ii=1:n

% Read in next value

x=input('Enter value:');

% Calculate square sums

sum_x2=sum_x2+x^2;

end

% Now calculate root mean square

root_ms=sqrt(sum_x2/n);

% Tell user

fprintf('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.2

3 Quitting MATLAB

Typing quit on the command window will close the program. Do not forget to send

your 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 data

2SIMULINK Basic

Basic steps

(1)Click on the MATLAB button to start MATLAB.

(2)Once MATLAB has started up, type simulink (SMALL LETTERS!) at the

MATLAB 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 to

begin 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 by

moving the mouse over a port and drag using the left button. To make a line with

a right angle in it, release the button where you want the corner, then click on the

end 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 Simulation

menu. 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 a

simulation before completing by selecting Stop from the Simulation menu. (10)View the behavior of the system by attaching Scope blocks to the variables of

interest, 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 this

out 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 。

(3) An open-loop control system is as following:

11

)(+=

s s P Set the controller gain K=10. Simulate the system and examine the step response

of the closed loop system using an input step size of 2.0 (change the step size by

double-clicking on the Step Fcn block). View the controller output u and output y by

Scope blocks, and plot output vs. time in MATLAB workspace.

Use a Transfer Fcn block for the plant. To design the controller, use a Gain block

for the proportional control block, and a Step Fcn block for the input. Tie Scope

blocks to the controller output (plant input) and plant output. In order to bring the

variables into the MATLAB workspace, tie To Workspace blocks to time from the

Clock block, and the output y. Make the step occur at t=1.0 second. Double click To

Workspace block, and set “Save format” to “Array”.

Library:

Step – Sources

Gain – Math

Transfer Fcn – Continuous

Scope – Sinks

To Workspace – Sinks

Clock – Sources

4 Quitting MATLAB

Typing quit on the command window will close the program. Do not forget to send

your 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 语言实验报告5

系 级 班 年 月 日

实验名称:plotting

Controller Plant

姓名学号指导教师成绩1Objective

●Learn how to use MATLAB 2D plots

●learn how to use Matlab demos

●learn how to use 3D surface plots

●have fun

22D Plotting and rand/round functions.

(1)Create a 10 x 10 random matrix with value [0, 1] using rand. Call this matrix z.

(2)Compute and plot sum of all columns. This should result in one plot line. The x

axis should be column number, and the y axis is the sum of each single column.

(3)Apply round to the matrix, and then plot the sum of the resulting matrix.

(4)Apply ceil to the matrix, and then plot the sum of the resulting matrix.

(5)Apply floor to the matrix, and then plot the sum of the resulting matrix.

Put all of these plots on the same graph (there will be a total of four lines), with each line a different color and/or pattern. Make sure to create a legend identifying each line. Also put a title and axes labels on the graph.

Save this script to copy to the TA at the end of the lab.

3Matlab demos – 2D Plotting, 3D Surface Plotting.

Now let's learn how to plot. At the same time, we're going to learn how to use Matlab demos. You can use Matlab demos whenever you want to learn more about a particular feature.

Find the demo under MATLAB --> Graphics -->2-D Plots and 3-D Plots. Read the description and click on "Run this demo". Play with the different options, and look at the code used to generate each plot (in the mini command window as part of the demo). You want to be able to use what you've learned from this demo. Try plotting one style of graph on your own, by putting it in a script file and executing the commands.

43D Surface Plotting.

In the demo you looked at above, a demo function called "peaks" was used to get the data for the 3D surface plot. This matrix stores the z values (height values) for the x and y dimensions. When you plot it, if you do not specify x and y values, it makes assumptions about the values of the x and y axes (namely, they start at 1 and go up by 1 for the entire length of the matrix). We are going to make our own 3D surface plot, but using our own data.

Using the 10x10 random matrix you generated at the beginning of the lab, make a 3D surface plot. If your matrix with random values is named "z", you can create this plot by using the command "surf(z)".

Change the shading and the colormap of this plot, and store the commands in an m-file to copy the TA at the end.

Now, let's say we don't like the default setting of the x and y axes as 1:10. We want our x values to be 16 to 25, and our y values to be 111 to 120,.We can't just use these x=16:25 and y=111:120 values in surf directly. Now use meshgrid to create the x and y matrices appropriate to use in surf(x,y,z) for the plot with the stated desired axes. Plot this data on a new figure, and save the code to copy TA at the end of the lab.

5More fun with 3D surface plots.

Use this data:

[X,Y] = meshgrid(-8:.5:8);

R = sqrt(X.^2 + Y.^2) + eps;

Z = sin(R)./R;

mesh(X,Y,Z) %similar to surf

What will happen if you plot the same thing, but change "Z" to "-Z" ? Convince yourself of what will happen when you do this, and then try it out.

Save this in a script and then manipulate the plot to make it have a smooth (non-gridded) surface colored differently than it is now.

6Quitting MATLAB

Note: Pay attention to the underlined text - you will have to copy these things to TA at the end of the lab.

Typing quit on the command window will close the program.

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语言实验报告6

系级班年月日

实验名称:User-Defined functions, and Input & Output functions

姓名学号指导教师成绩1Objective

The objective of this lab is to familiarize you with the MATLAB User-Defined functions, and Input & Output functions.

2User-Defined functions

(1) Random Numbers

a. Write a function that generates a random integer in the range [a, b] given by the user.

Hint: The rand function of MATLAB generates a floating point number between 0

and 1.

b. Write another function that uses the function you wrote in part (a) and returns n

random integers in the range [a, b] where n, a and b are all given by the user.

(Repeated integers in the output are allowed.)

(2) Word Scrambler

Write a function called mix_word that gets a word and returns a word that contains

the same characters, but arbitrarily mixed. Upper-case characters will be changed into

lower-case.

Hint: Strings in MATLAB are actually char-vectors, i.e. for s='CS111' the e.g. second

element is given by s(2)=='S'. A string can be converted into lower case by function

lower, e.g. s_low=lower(s) results in s_low='cs111'. Function randperm Random

permutation. randperm (n) is a random permutation of the integers from 1 to n. For example, randperm(6) might be [2 4 5 6 1 3].

An example run of your program can be as follows:

>> words = mix _word( 'CS111' );

>> disp( words );

11c1s

3 Output functions

Suppose that you have M amount of money in an interest-bearing account at a bank

(M stands for the present value). If the bank pays you interest on the money at a rate

of P percent per year and compounds the interest monthly, the amount of money that you will have in the bank after n months is given by the equation:

n

P M F ??? ??+=12001

Where F is the future value of the account and P/12 is the monthly percentage interest

rate.

Write a program that gets the initial amount of money and the interest rate from the

user, and calculates and writes out a table showing the future value of the account

balance every month for the next 4 years. The table should be written to an output file

called interest.txt. Be sure to properly label the columns of your table.

Hint: You can use the fprintf function to write text to a file.

4 Input functions

a. W rite a function that computes the distance between two points (x1; y1) and (x2; y2)

in the Cartesian coordinate system.

b.Write another function that gets a point (x0; y0) and the name of a file that contains

a list of points (each row of the file contains one point where the first column

contains the x-coordinates and the second column contains the y-coordinates), and

returns which point in the file is closest to the input point (x0; y0).

Hint 1: Use the function that you wrote in part (a) in the solution of part (b).

Hint 2: You can use a text editor, such as Notepad, to create the file that contains the

point data, and use MATLAB's textread function to read the points from that file.

Check the description of textread from the textbook and MATLAB help.

An example run of your program can be as follows:

>> p = find_closest( 1, 0, 'points.txt' );

>> disp(p);

4

>> p = find_closest( -1, 4, 'points.txt' );

>> disp(p);

2

where the file points.txt contains:

-1 2

0 3

2 -2

1 1

2 1

5 Quitting MATLAB

Typing 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 语言实验报告7

系 级 班 年 月 日

实验名称:Convolution and FFT computation

姓名 学号 指导教师 成绩 1 Objective

The objective of this lab is to familiarize you convolution and fft computation with

the MATLAB

2 Convolution computation

The conv function of MATLAB can support convolution and polynomial

mutiplication operation.Write a program that compute convolution between input

signal and system impulse response.Your program should give the figure of input

signal,system,output signal.Example of input signal and system impulse response is :

System:)3()2(5.2)1(5.2)()(-+-+-+=n n n n n h δδδδ

Input signal:)

sin(2)(0nT n x Ω=,001.0=T ,500<≤n π1000=Ω

Hint:stem function of MATLAB is useful for plotting figure of discrete signal and

system.

3 Spectrum analysis using FFT

Write a spectrum analysis program for two kinds of sequence.The fft function of

MATLAB can be used for spectrum analysis of signal.Spectrum figure of given

sequence must be considered in program.Sequence is given below: (1)gauss sequence

?????≤≤=--others n e

n x q p n ,0150)(2

)

(, (2) attenuated sine sequence

???≤≤=-others n fn e n x n ,0150,2sin )(πα

4 Quitting MATLAB

Typing 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 语言实验报告8

系 级 班 年 月 日

实验名称:digital filter design

姓名 学号 指导教师 成绩 1 Objective

The objective of this lab is to familiarize you with the MATLAB digital filter design.

2 FIR filter design

Write a program that complete FIR filter design using window method.Program must

return magnitude-frequency and phase-frequency figure of filter you designed.Design

specification is listed below:

(1)design a linear phase FIR filter which approach ideal magnitude-frequency

characteristic:

???≤≤=else j H d ,04.00,1)(πωω,Its length is 8.

(2)design a linear phase bandpass filter.design specification is listed below: Length N=16

Passband frequency range:]0.5 3.0[ππ

3 IIR filter design

Write a program that complete IIR filter design using ButterWorth filter method. Program must return magnitude-frequecncy and phase-frequency figure of filter you designed.Design specification is listed below:

Sampling frequency:1 Hz

passband cutoff frequency:0.2Hz passband attenuation:1dB

stopband cutoff frequency:0.3Hz stopband attenuation:25dB

4 Filter Design&Analysis Tool

Design a digital filter using filter design&analysis tool in MATLAB which must deal with hereinafter signal processing task.

A signal is composed of three sine signal,their frequency is 5Hz,15Hz,30Hz separately.Please design a band-pass FIR filter which let 15Hz signal pass. Transition bandwidth is 6Hz,passband and stopband ripple is 0.01.Sampling frequency is 100Hz. 5 Quitting MATLAB

Typing 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与数值分析》第一次上机实验报告

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

一、实验名称 《MATLAB与数值分析》第一次上机实验 二、实验目的 1. 熟练掌握矩阵的生成、加、减、乘、除、转置、行列式、逆、范数等运算 操作。(用.m文件和Matlab函数编写一个对给定矩阵进行运算操作的程序) 2. 熟练掌握算术符号操作和基本运算操作,包括矩阵合并、向量合并、符号 转换、展开符号表达式、符号因式分解、符号表达式的化简、代数方程的符号解析解、特征多项式、函数的反函数、函数计算器、微积分、常微分方程的符号解、符号函数的画图等。(用.m文件编写进行符号因式分解和函数求反的程序) 3. 掌握Matlab函数的编写规范。 4、掌握Matlab常用的绘图处理操作,包括:基本平面图、图形注释命令、 三维曲线和面的填充、三维等高线等。(用.m文件编写在一个图形窗口上绘制正弦和余弦函数的图形,并给出充分的图形注释) 5. 熟练操作MATLAB软件平台,能利用M文件完成MATLAB的程序设计。 三、实验内容 1. 编程实现以下数列的图像,用户能输入不同的初始值以及系数。并以x, y为坐标显示图像 x(n+1) = a*x(n)-b*(y(n)-x(n)^2); y(n+1) = b*x(n)+a*(y(n)-x(n)^2) 2. 编程实现奥运5环图,允许用户输入环的直径。 3. 实现对输入任意长度向量元素的冒泡排序的升序排列。不允许使用sort 函数。 四、实验数据及结果分析 题目一: ①在Editor窗口编写函数代码如下:

matlab实验报告

数学实验报告 班级: 学号: 姓名: 实验序号:1 日期:年 月 日 实验名称:特殊函数与图形 ◆ 问题背景描述:绘图是数学中的一种重要手段,借助图形,可以使抽象的对象得到 明白直观的体现,如函数的性质等。同时,借助直观的图形,使初学者更容易接受新知识,激发学习兴趣。 ◆ 实验目的:本实验通过绘制一些特殊函数的图形,一方面展示这些函数的特点属性, 另一方面,就 Matlab 强大的作图功能作一个简单介绍。 实验原理与数学模型: 1、 球2222x y z R ++= ,x=Rsin φcos θ, y= Rsin φsin θ, z= cos φ, 0≤θ≤2π , 0≤φ≤π 环面 222222222()4(),(cos )cos ,x y z a r a x y x a r φθ+++-=+=- (cos )sin ,sin ,02,02y a r z r φθφφπθπ=-=≤≤≤≤ 2、 平面摆线:2 22 31150,(sin ),(1cos ),0233 x y x a t t y a t t π+-==-=-≤≤ 3、 空间螺线:(圆柱螺线)x=acost , y=asint , z=bt ;(圆锥螺线)22 cos ,sin ,x t t y t t z t === 4、 椭球面sin cos ,sin sin ,cos ,02,0x a y b z c φθφθφθπφπ===≤<≤≤ 双叶双曲面3 tan cos ,tan sin ,sec ,02,22 x a y b z c π φθφθφθπφπ===≤<- << 双曲抛物面2 sec ,tan 2 u x au y bu z θθ=== 实验所用软件及版本:mathematica(3.0) 主要内容(要点): 1、 作出下列三维图形(球、环面) 2、 作出下列的墨西哥帽子 3、 作出球面、椭球面、双叶双曲面,单叶双曲面的图形 4、 试画出田螺上的一根螺线 5、 作出如图的马鞍面

MATLAB实验报告50059

实验一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-4

3、利用帮助功能查询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命令包含的字符很多,需要分成多行输入,该如何处理?

matlab第一次实验报告

Matlab第一次实验报告 2012029010010 尹康 1. 编程实现以下数列的图像,用户能输入不同的初始值以及系数。并以x,y为坐标显示图像 x(n+1) = a*x(n)-b*(y(n)-x(n)^2); y(n+1) = b*x(n)+a*(y(n)-x(n)^2) 程序代码: n=input('input the number of pionts:'); a=input('input a:'); b=input('input b:'); x=[]; y=[]; x(1)=input('input x1:'); y(1)=input('input y1:'); %输入点数、初始值以及系数for i=2:n x(i)=a*x(i-1)-b*(y(i-1)-x(i-1)^2); y(i)=a*x(i-1)+b*(y(i-1)-x(i-1)^2); %根据已输入的数据进行迭代end figure;plot(x,y,'linewidth',2) axis equal %横纵坐标等比例 text(x(1),y(1),'1st point') %标记初始点 运行结果:

心得体会及改进:在输入某些数据时,所绘曲线可能是一条折线(如:n=5,a=b=x1=1,y1=2)甚至只有一个点(如:n=5,a=b=x1=y1=1),此时可能出现曲线与坐标轴重合或无法看到点的情况,为了更清晰地展现曲线,可以使线宽适当加宽并标记初始点。 2.编程实现奥运5环图,允许用户输入环的直径。 程序代码: 函数circle: %在指定的圆心坐标处,用指定颜色、宽度的线条绘出指定半径、圆心角的弧 function f=circle(r,x,y,color,linw,alp1,alp2) alp=linspace(alp1,alp2); X=r*cos(alp)+x; Y=r*sin(alp)+y; plot(X,Y,color,'linewidth',linw) end 主程序代码: r=input('input r:');

matlab实验报告

实验一小球做自由落体运动内容:一小球竖直方向做自由落体,并无损做往返运动。程序: theta=0:0.01:2*pi x=cos(theta) y=sin(theta) l=1 v=1 while l<10 for t=1:10 y=y+(-1)^l*v*t plot(x,y,[-1,1],[-56,2],'.') axis equal pause(0.1) end l=l+1 end 结果:

-50 -40 -30 -20 -10 收获:通过运用小球自由落体规律,及(-1)^n 来实现无损往 返运动! 实验二 旋转五角星 内容:一个五角星在圆内匀速旋转 程序:x=[2 2 2 2 2 2] y=[0 4/5*pi 8/5*pi 2/5*pi 6/5*pi 0] y1=2*sin(y) x1=2*cos(y) theta=0:4/5*pi:4*pi

x2=2*cos(theta) y2=2*sin(theta) plot(x,y,x1,y1,x2,y2) axis equal theta1=theta+pi/10 x2=2*cos(theta1) y2=2*sin(theta1) plot(x2,y2) axis equal theta=0:4/5*pi:4*pi for rot=pi/10:pi/10:2*pi x=2*cos(theta+rot) y=2*sin(theta+rot) plot(x,y) pause(0.1) end 结果:

-2 -1.5-1-0.500.51 1.52 -2-1.5-1-0.500.511.5 2 收获:通过theta1=theta+pi/10,我们可以实现五角星在圆内匀速 旋转! 实验三 转动的自行车 内容:一辆自行车在圆内匀速转动 程序:x=-4:0.08:4; y=sqrt(16-x.^2); theta1=-pi/2:0.01*pi:3*pi/2; x3=0.5*cos(theta1); y3=0.5*sin(theta1); theta=-pi/2+0.02*pi for k=1:100

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实验报告

实验一 Matlab基础知识 一、实验目的: 1.熟悉启动和退出Matlab的方法。 2.熟悉Matlab命令窗口的组成。 3.掌握建立矩阵的方法。 4.掌握Matlab各种表达式的书写规则以及常用函数的使 用。 二、实验内容: 1.求[100,999]之间能被21整除的数的个数。(rem) 2.建立一个字符串向量,删除其中的大写字母。(find) 3.输入矩阵,并找出其中大于或等于5的元素。(find) 4.不采用循环的形式求出和式 63 1 2i i= ∑ 的数值解。(sum) 三、实验步骤: ●求[100,199]之间能被21整除的数的个数。(rem) 1.开始→程序→Matlab 2.输入命令: ?m=100:999; ?p=rem(m,21); ?q=sum(p==0) ans=43 ●建立一个字符串向量,删除其中的大写字母。(find) 1.输入命令:

?k=input('’,’s’); Eie48458DHUEI4778 ?f=find(k>=’A’&k<=’Z’); f=9 10 11 12 13 ?k(f)=[ ] K=eie484584778 ●输入矩阵,并找出其中大于或等于5的元素。(find) 1.输入命令: ?h=[4 8 10;3 6 9; 5 7 3]; ?[i,j]=find(h>=5) i=3 j=1 1 2 2 2 3 2 1 3 2 3 ●不采用循环的形式求出和式的数值解。(sum) 1.输入命令: ?w=1:63; ?q=sum(2.^w) q=1.8447e+019

实验二 Matlab 基本程序 一、 实验目的: 1. 熟悉Matlab 的环境与工作空间。 2. 熟悉M 文件与M 函数的编写与应用。 3. 熟悉Matlab 的控制语句。 4. 掌握if,switch,for 等语句的使用。 二、 实验内容: 1. 根据y=1+1/3+1/5+……+1/(2n-1),编程求:y<5时最大n 值以及对应的y 值。 2. 编程完成,对输入的函数的百分制成绩进行等绩转换,90~100为优,80~89为良,70~79为中,60~69为及格。 3. 编写M 函数文件表示函数 ,并分别求x=12和56时的函数值。 4. 编程求分段函数 2226;03 56;0532 1;x x x x y x x x x x x x +-<≠=-+≤<≠≠-+且且及其它,并求输入x=[-5.0,-3.0,1.0,2.0,2.5,3.0,3.5]时的输出y 。 三、 实验步骤: 根据y=1+1/3+1/5+……+1/(2n-1),编程求:y<5时最大n 值以及对应的y 值。 1. 打开Matlab ,新建M 文件 2. 输入命令: 51022-+x

MATLAB实验报告

MATLAB程序设计语言 实 验 报 告 专业及班级:电子信息工程 姓名:王伟 学号:1107050322 日期 2013年6月20日

实验一 MATLAB 的基本使用 【一】 实验目的 1.了解MATALB 程序设计语言的基本特点,熟悉MATLAB 软件的运行环境; 2.掌握变量、函数等有关概念,掌握M 文件的创建、保存、打开的方法,初步具备将一般数学问题转化为对应计算机模型处理的能力; 3.掌握二维图形绘制的方法,并能用这些方法实现计算结果的可视化。 【二】 MATLAB 的基础知识 通过本课程的学习,应基本掌握以下的基础知识: 一. MATLAB 简介 二. MATLAB 的启动和退出 三. MATLAB 使用界面简介 四. 帮助信息的获取 五. MATLAB 的数值计算功能 六. 程序流程控制 七. M 文件 八. 函数文件 九. MATLAB 的可视化 【三】上机练习 1. 仔细预习第二部分内容,关于MATLAB 的基础知识。 2. 熟悉MATLAB 环境,将第二部分所有的例子在计算机上练习一遍 3. 已知矩阵???? ??????=??????????=123456789,987654321B A 。求A*B ,A .* B ,比较二者结果是否相同。并利用MATLAB 的内部函数求矩阵A 的大小、元素和、长度以 及最大值。 程序代码: >> A=[1 2 3;4 5 6;7 8 9]; >> B=[9 8 7;6 5 4;3 2 1]; >> A*B ans =

30 24 18 84 69 54 138 114 90 >> A.*B ans = 9 16 21 24 25 24 21 16 9 两者结果不同 >> [m,n]=size(A) m = 3 n = 3 >> b=sum(A) b = 12 15 18 >> a=length(A) a = 3 >>max(A) ans =

matlab实验报告

Matlab实验报告 实验二图像处理 一、实验目的 (1)通过应用MA TLAB语言编程实现对图像的处理,进一步熟悉MATLAB软件的编程及应用; (2)通过实验进一步掌握图像处理的基本技术和方法。 二、实验内容及代码 ㈠.应用MA TLAB语言编写显示一幅灰度图像、二值图像、索引图像及彩色图像的程序,并进行相互之间的转换 首先,在matlab页面中的current directory下打开存放图像的文件夹。 1.显示各种图像 ⑴显示彩色图像: ①代码:>> mousetif=imread('tif.TIF'); >> image(mousetif) 显示截图: ②代码:>> mousetif=imread('tif.TIF'); >> imshow(mousetif) 显示截图:

③代码:mousetif=imread('tif.TIF'); subimage(mousetif) 显示截图: 显示截图:

⑵显示二值图像 ①代码:>> I=imread('单色bmp.bmp'); >> imagesc(I,[0 2]) 显示截图: ②代码:>> I=imread('单色bmp.bmp');

>> imshow(I,2) 显示截图: ③代码:>> I=imread('单色bmp.bmp'); >> subimage(I) 显示截图:

⑶显示灰度图像 ①代码:>> I1=imread('256bmp.bmp'); >> imagesc(I1,[0,256]) 显示截图: 代码:>> I1=imread('256bmp.bmp'); >> colormap(gray); >> subplot(1,2,1); >> imagesc(I1,[0,256]); >> title('灰度级为[0 256]的mouse.bmp图'); >> subplot(1,2,2); >> imagesc(I1,[0,64]); >> colormap(gray); >> title('灰度级为[0 64]的mouse.bmp图'); 显示截图:

MATLAB全实验报告

《数学实验》报告 实验名称 Matlab 基础知识 学院 专业班级 姓名 学号 2014年 6月

一、【实验目的】 1.认识熟悉Matlab这一软件,并在此基础上学会基本操作。 2.掌握Matlab基本操作和常用命令。 3.了解Matlab常用函数,运算符和表达式。 4.掌握Matlab工作方式和M文件的相关知识。 5.学会Matlab中矩阵和数组的运算。 二、【实验任务】 P16 第4题 编写函数文件,计算 1! n k k = ∑,并求出当k=20时表达式的值。P27第2题 矩阵A= 123 456 789 ?? ?? ?? ?? ?? ,B= 468 556 322 ?? ?? ?? ?? ?? ,计算A*B,A.*B,并比较两者的区别。 P27第3题 已知矩阵A= 52 91 ?? ?? ?? ,B= 12 92 ?? ?? ?? ,做简单的关系运算A>B,A==B,AB)。 P34 第1题 用 111 1 4357 π =-+-+……公式求π的近似值,直到某一项的绝对值小于-6 10为止。 三、【实验程序】 P16 第4题 function sum=jiecheng(n) sum=0; y=1; for k=1:n for i=1:k y=y*i; end sum=sum+y; end sum P27第2题 >>A=[1 2 3;4 5 6;7 8 9] >>B=[4 6 8;5 5 6;3 2 2] >>A*B

P27第3题 >> A=[5 2;9 1];B=[1 2;9 2]; >>A>B >>A==B >>A> (A==B)&(A> (A==B)&(A>B) P34 第1题 t=1; pi=0; n=1; s=1; while abs(t)>=1e-6 pi=pi+t; n=n+2; s=-s; t=s/n; end pi=4*pi; 四、【实验结果】 P16 第4题 P27第2题

matlab实验报告

实验报告 2. The Branching statements 一、实验目的: 1.To grasp the use of the branching statements; 2.To grasp the top-down program design technique. 二、实验内容及要求: 1.实验内容: 1).编写 MATLAB 语句计算 y(t)的值 (Write the MATLAB program required to calculate y(t) from the equation) ???<+≥+-=0 530 53)(2 2t t t t t y 已知 t 从-5到 5 每隔0.5取一次值。运用循环和选择语句进行计算。 (for values of t between -5 and 5 in steps of 0.5. Use loops and branches to perform this calculation.) 2).用向量算法解决练习 1, 比较这两个方案的耗时。 (tic ,toc 的命令可以帮助你完成的时间计算,请使用'help'函数)。 Rewrite the program 1 using vectorization and compare the consuming time of these two programs. (tic, toc commands can help you to finish the time calculation, please use the …help ? function). 2.实验要求: 在报告中要体现top-down design technique, 对于 3 要写出完整的设计过程。 三、设计思路: 1.用循环和选择语句进行计算: 1).定义自变量t :t=-5:0.5:5; 2).用循环语句实现对自变量的遍历。 3).用选择语句实现对自变量的判断,选择。 4).将选择语句置入循环语句中,则实现在遍历中对数据的选择,从而实现程序的功能。 2. 用向量法实现: 1).定义自变量t :t=-5:0.5:5; 2).用 b=t>=0 语句,将t>=0得数据选择出,再通过向量运算y(b)=-3*t(b).^2 + 5; 得出结果。 3).用取反运算,选择出剩下的数据,在进行向量运算,得出结果。 四、实验程序和结果 1.实验程序 实验程序:创建m 文件:y_t.m

广州大学学生实验报告1 matlab 程序设计

广州大学学生实验报告 开课学院及实验室:机械与电气工程学院计算机楼 301室2014 年10 月30 日

2、MATLAB指令窗的基本操作 MATLAB指令窗给用户提供了最直接的交互界面,可用于输入和执行指令、显示指令运行结果、调试MATLAB程序等常用的MATLAB仿真计算功能。本实验掌握以下在指令窗执行的基本操作,达到熟悉使用指令窗的目的: (1)最简单的计算器使用方法:在MATLAB指令窗中,可按计算器的方式进行一般的数学计算,MATLAB的运算符的含义大致与常见的运算规则一致; (2)在指令窗中输入和生成矩阵:与一般的计算器不同,在MATLAB中可直接输入和生成矩阵。实际上,矩阵是MATLAB工作的基本元素。 (3)数值表述方法:在MATLAB中的大部分数值的表述方式与平常是相同的,需要注意的是在表示比较大的数时,MATLAB默认采用科学计数法显示; (4)变量命名规则:对于MATLAB变量命名规则,需要注意以下几点: a、变量名、函数名对字母大小写敏感 b、变量名的第一个字母必须是英文字母,后续可以是字母、数字、下划线 c、变量的有效时限:在变量定义赋值之后,会作为内存变量保存并显示在Workspace Browser中。因此,凡是显示在Workspace Browser中的变量 都是“有效”的,其后可以被调用,否则不能被调用。 d、对于像 等常用的数学常量,MATLAB定义了预定义变量与其对应,在使用时需多加留意。 e、复数和复数矩阵的表示方法。 (5)其他操作的操作要旨和操作技巧的运用。 3、计算结果的图形表示 计算结果可视化是MATLAB的主要组成部分,借助图形表现数据是十分常用的“数据表达手段”,尤其当数据量相当庞大时,因为图形可以表现数据内在联系和宏观特征。关于MATLAB绘图的基本方法在后续章节中详细讲述,本实验主要通过示例了解MATLAB绘图的基本功能。 4、Current Directory、路径设置器和文件管理 理解当前目录Current Directory和搜索路径的作用是正确使用MATLAB的关键环节。当前目录指的是当前MA TLAB工作的目录,MATLAB运行指令需要打开或者保存的文件,都首先在目录中查找或保存。搜索路径则是MATLAB工作时,需查找相应的文件、函数或变量所在的相关文件夹所在的路径。 在理解当前目录Current Directory和搜索路径的作用的基础上,也要掌握当前目录Current Directory和搜索路径的设置方法,这是正确使用MA TLAB 的必要步骤。 为了理解MATLAB当前目录Current Directory和搜索路径的作用,可以大致了解一下当用户从指令窗送入一个名为cow的指令后,MATLAB的“运作次序”: (1)MATLAB在内存中检查,看cow是不是变量;如果不是,进行下一步; (2)检查cow是不是内建函数;如果不是进行下一步; (3)在当前目录下,检查是否有名为cow的M文件存在;如果不是,进行下一步; (4)在MA TLAB搜索路径的其他目录下,检查是否有名为cow的M文件存在。

浅析Matlab数学实验报告

数学实验报告 姓名: 班级: 学号: 第一次实验任务 过程: a=1+3i; b=2-i; 结果: a+b =3.0000 + 2.0000i a-b =-1.0000 + 4.0000i a*b = 5.0000 + 5.0000i a/b = -0.2000 + 1.4000i 过程: x=-4.5*pi/180; y=7.6*pi/180; 结果: sin(abs(x)+y)/sqrt(cos(abs(x+y))) =0.2098 心得:对于matlab 中的角度计算应转为弧度。 (1)过程: x=0:0.01:2*pi; y1=sin(x); y2=cos(x); y3=exp(x); y4=log(x); plot(x,y1,x,y2,x,y3,x,y4) plot(x,y1,x,y2,x,y3,x,y4) 结果: (2)过程:>> subplot(2,2,1) >> plot(x,y1) >> subplot(2,2,2) >> plot(x,y2) ./,,,,2,311b a b a b a b a i b i a ?-+-=+=计算、设有两个复数 6,7,5.4)

cos()sin(2=-=++y x y x y x ,其中、计算的图形。 下分别绘制)同一页面四个坐标系)同一坐标系下(、在( x y e y x y x y x ln ,,cos ,sin 213==== >> subplot(2,2,3) >> plot(x,y3) >> subplot(2.2.4) >> subplot(2,2,4) >> plot(x,y4) 结果: 心得:在matlab中,用subplot能够实现在同一页面输出多个坐标系的图像,应注意将它与hold on进行区别,后者为在同一坐标系中划出多条曲线。 5、随机生成一个3x3矩阵A及3x2矩阵B,计算(1)AB,(2)对B中每个元素平方后得到的矩阵C,(3)sinB,(4)A的行列式,(5)判断A是否可逆,若可逆,计算A的逆矩阵,(6)解矩阵方程AX=B,(7)矩阵A中第二行元素加1,其余元素不变,得到矩阵D,计算D。 过程:A=fix(rand(3,3).*10) ; B=fix(rand(3,3).*10);

MATLAB程序设计实验报告

MATLAB实验报告 一、实验名称 实验4图形绘制(1) 二、实验目的: 熟悉和掌握MA TLAB基本的二维图形绘制函数。 三、实验内容: 1.绘制简单的二维图形 2.一个坐标系绘制多幅图形 3.图形标识和坐标控制 4.交互式图形指令 四、回答问题: (本次实验未预留问题) 五、遇到的问题及解决: 遇到了求y=lnx时,输入“y=ln(x)”不被软件识别的问题,查看常用数学函数表后改为y=log(x)成功解决。 在求10x时不知道用什么函数,函数表里也查不到,在老师的点拨下用“y=10.^x”解决。 在绘图时发现默认线型不够明显,查表后使用尖三角、叉号代替默认线型。 六、体会: 本次实验我学会了利用MATLAB绘制图形的基本方法,以及相应的备注方法。 难点是了解各种函数的具体作用并熟练掌握。 体会是:多学多练,孰能生巧,日积月累,必有提高。

思考题: 1.在同一坐标系绘制t3,-t2,t2sint在[0,2π]内的曲线图。 x=0:pi/50:2*pi; y1=t.*t.*t; y2=-t.*t; y3=t.*t.*sin(t); plot(t,y1,'^k',t,y2,'.k',t,y3,'xk'); legend('\ity=t^3','\ity=-t^2','\itt^2*sint'); 2.在一幅图中画出4幅子图,分别绘制sin2x,tanx,lnx,10x的图形,并加上适当的图形注释。注意:把函数变成MATLAB对应的形式。 x=0:pi/50:2*pi; y1=sin(2*t); y2=tan(x); y3=log(x); y4=10.^x; subplot(2,2,1) plot(x,y1); legend('y=sin2x'); subplot(2,2,2) plot(x,y2) legend('y=tanx'); subplot(2,2,3) plot(x,y3)

MATLAB入门实验报告

MATLAB实验报告 题目:第一次实验报告 学生姓名: 学院: 专业班级: 学号: 年月

MATLAB第一次实验报告 ————入门第一次上机实验刘老师就MATLAB软件进行了 大致的讲解,并讲了如何建立M文件,定义函数数 组矩阵,如何绘图。先就老师讲解及自己学习的情 况做汇报。 一、建立M文件 <1>M文件建立方法: 1. 在MATLAB中,点:File→New →M-file 2. 在编辑窗口中输入程序内容 3. 点File →Save,存盘,M文件名必须与函数名 一致 <2>课上实例 例:定义函数f(x1,x2)=100(x2-x12)2+(1-x1)2 答:建立M文件:fun.m function f=fun(x) f=100*(x(2)-x(1)^2)^2+(1-x(1))^2 如此便可以直接使用函数fun.m 例如计算f(1,2), 只需在MATLAB命令窗口键入命

令: x=[1 2] fun(x) 得f = 100. <3>课下作业 题目:有一函数,写一程序,输入自变量的值,输出函数值. 解答:建立M文件:zuoye1.m function f=zuoye1(x,y) f=x^2+sin(x*y)+2*y 命令行输入x=1,y=1 zuoye1(x,y) 得ans = 3.8415 经验算答案正确,所以程序正确。

二、定义数组、矩阵 <1>说明 逗号或空格用于分隔某一行的元素,分号用于区分不同的行. 除了分号,在输入矩阵时,按Enter 键也表示开始新一行. 输入矩阵时,严格要求所有行有相同的列 <2>课后作业 题目:有一个4x5矩阵,编程求出其最大值及其所处的位置. 解答:a=round(10*rand (4,5)) [temp I]=max(a) [am II]=max(temp) p=[I(II) II] 运行得一随机矩阵 a = 7 7 7 3 7 0 8 2 0 3 8 7 7 1 10 9 4 0 8 0 temp =

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=(x-1)/(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)

matlab实验报告

Matlab实验报告 ——定积分的近似计算 学生姓名: 学号: 专业:数学与应用数学专业

数学实验报告 实验序号:1001114030 日期:2012年10月20日 班级应一姓名陈璐学号1001114030 实验名称:定积分的近似运算 问题背景描述: 利用牛顿—莱布尼茨公式虽然可以精确地计算定积分的值,但它仅适合于被积分函数的原函数能用初等函数表达出来的情形。如果这点办不到或不容易办到, 这就有必要考虑近似计算的方法。在定积分的很多应用问题中,被积函数甚至没 有解析表达式,可能只是一条实验记录曲线,或者是一组离散的采样值,这时只 能应用近似方法去计算相应的定积分。 实验目的: 本实验将主要研究定积分的三种近似计算算法:矩形法、梯形法、抛物线发。对于定积分的近似数值计算,Matlab有专门函数可用。 实验原理与数学模型: 1.sum(a):求数组a的和。 2.format long:长格式,即屏幕显示15位有效数字。 3.double():若输入的是字符则转化为相应的ASCII码;若输入的是整型数之则转化为 相应的实型数值。 4.quad():抛物线法求数值积分。格式:quad(fun,a,b)。此处的fun是函数,并且

为数值形式,所以使用*、/、^等运算时要在其前加上小数点。 5.trapz():梯形法求数值积分。格式:trapz(x,y)。其中x为带有步长的积分区间;y为数 值形式的运算。 6.fprintf(文件地址,格式,写入的变量):把数据写入指定文件。 7.syms 变量1变量2……:定义变量为符号。 8.sym('表达式'):将表达式定义为符号。 9.int(f,v,a,b):求f关于v积分,积分区间由a到b。 10.subs(f,'x',a):将a的值赋给符号表达式f中的x,并计算出值。若简单地使用subs (f),则将f的所有符号变量用可能的数值代入,并计算出值。 实验所用软件及版本:Matlab 7.0.1

MATLAB实验报告

中南民族大学 计算机科学学院 MATLAB实验报告 题目MATLAB实验 年级 2010 专业计算机科学与技术 指导教师李波 小组成员(姓名学号) 实验类型综合型 2014年4月22 日

一、实验安排 1.实验目的 1.掌握字符串的生成和操作,掌握单元数组的生成和操作,掌握结构体的生成和操作。 2.掌握MATLAB 的脚本文件及其编辑和调试方法,掌握MATLAB 程序设计和开发流程,掌握MATLAB 的关系运算,逻辑运算及函数操作,掌握MATLAB 流程控制语句。 3.掌握基本符号运算,掌握符号函数的绘制,掌握符号函数微积分的运算,掌握符号方程的求解方法,掌握符号积分变换,了解MAPLE 函数的调用方法,了解符号计算器的使用。 4.了解MATLAB 的图形窗口,掌握MATLAB 基本二维图形,三维图形的绘制,以及图形的绘制,如柱形图,饼状图,掌握图形注释的添加和管理,了解三维图形的视点控制及颜色,光照控制 5.了解Matlab 的图形对象及其属性,掌握MATLAB 图形对象属性的设置及其查询,掌握MATLAB 的图形对象句柄的访问及其操作。 2.实验内容 (1) 编写一个脚本,查找给定字符串中指定字符出现的次数和位 (2) 创建2x2单元数组,创建 2×2 单元数组,第 1、2 个元素为字符串,第 三个元素为整型变量,第四个元素为双精(double )类型,并将其用图形表示。 (3) 创建一个结构体,用于统计学生的情况,包括学生的姓名、学号、各科成 绩等。然后使用该结构体对一个班级的学生成绩进行管理,如计算总分、平均分、排列名次等。 (4) 在MATLAB 中使用一个循环确定:如果用户最初在一个银行帐户中存储 $10000,并且在每年的年终再存储$10000(银行每年支付6%的利息),那么账户上要积累$1000000要需要多长时间。 (5)设x 为符号变量,()421f x x x =++,()32458g x x x x =+++,试进行如下运算: (1)()()f x g x + (2)()()f x g x ? (3)求()g x 的反函数 (4)求g 以()f x 为自变量的复合函数

matlab7.0x课后习题答案

1、利用基本矩阵产生3*3和15*8的单位矩阵、全1矩阵、全0矩阵、均匀分布随机阵([-1,1]之间)、正态分布随机阵(均值为1,方差为4)。 解: A1=eye(3); A2=ones(3); A3=zeros(3); A4=2*rand(3)-1; A5=2*randn(3)+1; B1=eye(15,8); B2=ones(15,8); B3=zeros(15,8); B4=2*rand(15,8)-1; B5=2*randn(15,8)+1; 结果:由于数据是随机产生的,所以在没有给出运行结果。 2、利用diag等函数产生下列矩阵: a=[0 0 8;0 -7 5;2 3 0] b=[2 0 4;0 5 0;7 0 8] 然后利用reshape函数将它们变换成行向量。 解: 产生a的程序: b=diag([8 -7 2]); c=b+diag([5 3],-1); a=fliplr(c) 产生b的程序: s=[2 2 8]; t=[4 3 7]; v=diag(s); p=diag(t)+fliplr(v); b=fliplr(p) 运行结果: a = 0 0 8 0 -7 5 2 3 0 b = 2 0 4 0 5 0 7 0 8 利用reshape函数将它们变换成行向量:reshape(a,1,9) ans = 0 0 2 0 -7 3 8 5 0 3、产生一均匀分布在(-5,5)之间的随机阵(50*2),要求精确到小数点后一位。 解: A=5-round(100*rand(50,2))/10 部分数据结果: A = 2.4000 4.2000 -0.1000 2.7000 -4.6000 -3.3000

MATLAB实验报告(8个实验)

四川师范大学MATLAB语言实验报告1 系级班年月日 实验名称:Intro, Expressions, Commands 姓名学号指导教师成绩1Objective The objective of this lab is to familiarize you with the MATLAB program development environment and to develop your first programs in this environment. 2Using MATLAB 2.1Starting MATLAB Logon 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) created during the current MATLAB session and stored in memory. ●Command History (on the lower left side) logs commands entered in the Command 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 Commands You 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;

相关主题