Vous êtes sur la page 1sur 32

INDEX

S.No
1.

Practical
To learn how to do Arithmetic Operation in MATLAB To learn how to create and work with array of numbers and how to perform Arithmetic and Trigonometric Operation on them To learn how to plot a function of an independent variable in MATLAB To learn how to create script files for plotting a circle and work with the script file in MATLAB

Date

Sign

2.

3.

4.

INTRODUCTION TO MATLAB
MATLAB is a technical computing environment for high-performance numeric computation and visualization. MATLAB integrates numerical analysis, matrix computation, signal processing (via the Signal Processing Toolbox), and graphics into an easy-to-use environment where problems and solutions are expressed just as they are written mathematically, without much traditional programming. The name MATLAB stands for matrix laboratory. We will use MATLAB in ECE 360 in order to illustrate the concepts of digital signal processing with numerical examples. Each homework assignment will include some optional problems that require Matlab solutions. You will quickly realize that Matlab can often be used to check solutions to other problems as well. This is perfectly legitimate, but you still must turn in your analytical solutions for the pencil-and-paper problems. MATLAB is available in DECS labs on a UNIX, PC, and MAC platform. You can invoke MATLAB by double-clicking on the MATLAB-Icon (MAC,PC) or by typing matlab on the Unix command line. You will then get access to the MATLAB command line, denoted by ">>". This document is by no means a complete reference. There are tutorial and reference manuals for Matlab at the lib

Getting Help
Matlab is a versatile computing environment. However, to effectively utilize this tool, you need to learn the syntax. This document gives you the basic information you need to get started. Matlab has excellent on-line help available. To access this help, type in the command: >> help and press enter. This will provide you with a list of general areas where help is available. To get more information on this particular topic or any specific command or function you need to know about, type; >> help "topic-or-command" For example, your favorite help command in this class will probably soon become: >> help signal For help on a specific function, such as the plot command, type in the command or function name directly after the help command: >> help plot

If you have way too much time on your hands, you can run the command: >> demo This will give you a graphical interface that will let you explore the power of Matlab and show you how to do many of the operations you will be required to do in Matlab in this course

Variables
Variables are assigned values by typing in a mathematical expression >> a=4*log(2)/(8^(2.3)-sqrt(23)) giving an answer of a= 0.0242

Suppression of results
Appending a ";" to the end of the lie suppresses the display of the results. For example: >> a=4*log(2)/(8^(2.3)-sqrt(23)); will be followed by the command line. However, typing: >> a will display the value of the variable. For more information on operators, consult the command line help with: >> help ops

Complex Numbers
Matlab easily deals with complex numbers. To define a complex number, use either i or j. For example: >> c=2+i*7; >> d=(1+j*3)^3; both give complex numbers: c = 2.0000 + 7.0000I d = -26.0000 -18.0000i To access the real imaginary parts of complex numbers, use the commands real and imag. Consult command line help for more information.

Elementary Functions
Elementary functions are evaluated element wise: >> x=linspace(0,10*pi,200); >> y=sin(x);

>> plot(y) You can get a list of available functions with: >> help elfun

Control Flow in M-files


Matlab also provides the usual programming language for-end, if-else-break-end, and while-end. Check out the following line for example: >> for c=1:2:12; disp(c); end; See the command line help for more information. >> help lang Vectorizing Code

Definition of Vectors/Signals
Matlab provides various commands to generate vectors. A vector can be viewed as a "sequence of samples", i.e. a digital signal. Check out the following ones: >> x=[ 1 2 3 4 5 ] >> x=1:5 >> x=1:2:10 >> x=linspace(0,1,5) For more information on the ":"-operator type: >> help colon

Definition of Matrices
Matlab also provides various commands to generate matrices. Check out the following ones: >> A=[ 1 2 3 ; 4 5 6 ; 7 8 9 ] >> B=eye(3) >> C=ones(2,3) >> D=diag([1 5 6 8]) >> E=zeros(3,2) >> F=rand(1,5) >> G=randn(5,1) The last two commands will generate random vectors, i.e. "random signals".

Matrix Manipulation
The following commands are useful for matrix/vector manipulations. One can easily take the transpose of a matrix, flip the matrix from left to right or up and down, concatenate two matrices and so for the. Use the matrices defined above and type: >> P=A'

>> P=fliplr(A) >> P=flipud(A) >> Q=[ A D] >> R=[ A; B]

Operators
Since Matlab generally deals with matrices you have to be careful when using operators like "*" or "/". If you want these operators to operate in an element-by-element fashion, you have to denote this by a leading "."! Check out the following examples: >> x=1:5 >> y=y+x >> y=x.*x >> y=x-x >> y=x./(x+x) Note: "*" and "/" without "." are matrix multiplication and "matrix division" (special function of Matlab). For example: >> P=C*A A special case applies for scalar multiplication: >> y=2*x

Vectorization
Many tasks that may be implemented with loop structures can be more efficiently executed with vectorization..

EXAMPLE (Integrating a function)


We can implement this with a for-loop as shown below: % Generate a signal a=0:pi/12:4*pi; x=sin(a).^2; % Let's view the signal stem(a,x) xlabel('a');ylabel('x');title('signal') % now calculate the average signal value S=0; for k=1:length(x) S=S+x(k); end avg=S/length(x) Or, more efficiently, we can vectorize the calculation as shown below: % Generate a signal a=0:pi/12:4*pi;

x=sin(a).^2; % Let's view the signal stem(a,x) xlabel('a');ylabel('x');title('signal') % now calculate the average signal value avg=sum(x)/length(x)

Graphics
Graphical representation is an important part of visualizing and understanding signals. The easiest way to graphically display a signal is by using the plot command: >> s=[ 1 2 3 4 2 3 5 ]; >> plot(s) We can represent this data several other ways. A common way to represent discrete signals is with the stem command: >> stem(s) For a complete listing of 2D graphic tools, type: >> help plotxy For a more complete listing of graphic commands, type: >> help graphics All graphs should be clearly labeled as illustrated in the following example. EXAMPLE: Plot a discrete-time sinusoid, cos(w n+q ), where w =p /6 and q =p /6 >> w=pi/6;theta=pi/3;n=-15:15; >> x=cos(w*n+theta); >> stem(n,x) This plot should be labeled. To label it, use the commands: >> xlabel('n') >> ylabel('x(n)') >> title('Discrete-time sinusoid: cos(pi/6*n+pi/3)') The axes can be set arbitrarily using the axis command. The argument to the axis command is the vector [XMIN XMAX YMIN YMAX]. For the above example, >> axis([-16 16 -2 2]) would change the scale of the plot. The scale should be set so that all of the data can be conveniently seen. More than one plot can be placed on a page using the subplot command. For more information, type: >> help subplot Finally, to putting a grid on your plot may make things easier to read. To do this, type: >> grid

M-Files
Matlab is most useful when you write your own programs. You can use any regular ASCII text editor to do so. Simply open a file with the extension *.m (which is call an mfile) and edit line by line the sequence of commands you want to include in your program. Save the file and execute the program by typing the name of the file (without the .m) on your Matlab command line. EXAMPLE: Invoke a text editor (e.g. emacs on UNIX or notepad or the Matlab editor with debugger on PCs) and edit the following lines: % This is a program that generates a noisy signal x=linspace(0,10*pi,200); % compute the signal y=sin(x); % compute the noise z=0.3*rand(1,200); % add the noise y=y+z % plot the signal plot(y);grid title('Noisy Sinusoid') xlabel('x') ylabel('y') Save this program for example in a file named noisy.m. Now, make sure the current directory of Matlab is the directory where the file is located. You can access this directory by: (PC) >> cd M:\ECE360 (UNIX) >> cd ECE360 You can check the current directory and see a list of available *.m and *.mat files by executing the commands: >> pwd >> what Finally, execute your program with: >> noisy

User-Defined Functions
User defined functions work just like commands in Matlab. In fact, many of the commands are functions written by Matlab engineers. From the command line help: >> help function The function will work like a command from the command line if:

They contain existing commands and functions in the Matlab path The new function is put in a file whose name defines the name of the function

The top line defines the function syntax function [returned_variable_1, returned_variable_2, ]= function_name(arugments)

The variables defied are local and only available within the function.

EXAMPLE: saved in a file: stat.m function [mean,stdev] = stat(x) n = length(x); mean = sum(x) / n; stdev = sqrt(sum((x - mean).^2)/n); This function computes the average and the standard deviation of a vector fed to it in the argument x.

Printing
On a Unix workstation, type setenv PRINTER printername at the shell prompt before running Matlab. Once in Matlab, typing print will print out the latest viewed graph.

File Import/Export
We will generally use variables saved from the Matlab workspace with the save command. The file will be a "mat" file (*.mat) and is readable only by Matlab. To import the variables (as you will need to do for homework) use the command: >> load filename The file must be in Matlab's path (see the path command) or the current directory should be set to the directory containing the file. (see the M-File section.) Often, we need to import data from files. For a list of commands used for io, type: >> help iofun These low-level commands deal with ASCII files, etc.

PRACTICAL - 1

OBJECTIVE: TO LEARN HOW TO DO ARITHMETIC OPERATIONS IN MATLAB

WHAT WE ARE GOING TO LEARN IN THIS PRACTICAL?


1) How to find root of any number. 2) How to do simple calculations in arithmetic operations, logarithms and exponential, trigonometric functions and complex numbers . 3) How to assign values to variable. 4) How to quit MATLAB.

METHODS
1) We have used trigonometric functions (sin(x), cos(x)). 2) We have used exponential functions (exp(x)). 3) We have used logarithmic function(log(x), log10(x)). 4) We solved complex numbers . 4) We have done arithmetic operations.

CONCLUSION
1) It is easy to find root of any number. 2) Arithmetic operations are easy to solve.

OUTPUT:
(2^5)/(2^5-1) ans = 1.0323 >> 3*(sqrt(5)-1)/((sqrt(5)+1)^2)-1 ans = -0.6459 >> pi*((pi^(1/3)-1)^2) ans = 0.6781 exp(3) ans = 20.0855 >> log(exp(3)) ans = 3 >> log10(exp(3)) ans = 1.3029 >> exp(pi*sqrt(163)) ans = 2.6254e+017 >> sin(pi/6) ans = 0.5000

>> cos(pi) ans = -1 >> tan(pi/2) ans = 1.6331e+016 >> (sin(pi/6))^2+(cos(pi/6))^2 ans = 1 >> (cosh(32*pi))^2-(sinh(32*pi))^2 ans = 0 >> (1+3*i)/(1-3*i) ans = -0.8000 + 0.6000i >> exp(i*pi/4) ans = 0.7071 + 0.7071i

>> cos(pi/4)+i*sin(pi/4) ans = 0.7071 + 0.7071i >> exp(pi/2*i) ans = 0.0000 + 1.0000i

>> exp(pi/2i) ans = 0.0000 - 1.0000i

PRACTICAL- 2

OBJECTIVE: TO LEARN HOW TO CREATE AND WORK WITH ARRAY OF NUMBERS AND HOW TO PERFORM ARITHMETIC AND TRIGONOMETRIC OPERATIONS ON THEM

WHAT ARE WE GOING TO LEARN IN THIS PRACTICAL?


1) How to create row and column vectors. 2) How to create a vector of n numbers linearly (equally ) spaced between two given numbers a and b. 3) How to do simple calculation on vectors. 4) How to use square root, exponential , trigonometric functions and logarithms with array arguments. 5) How to do array operations.

METHODS:
1) To define an array we can use x = [1 2 3]. 2) We can add and subtract vectors of same size. 3) We can find sum of a geometric series (1+r^2 +r^3 +..+r^n) . 4) To find size of an array we can use size(m) where m is an array. 5) If we are provided with coordinates x=r*cos(theta) and y=r*sin(theta) and r(radius) and theta we can find radius of circle using r=(x*x+ y*y)^(.5).

CONCLUSIONS:
1) EASY TO FIND SIZE OF AN ARRAY. 2) EASY TO FIND SUM OF GEOMETRIC SERIES.

OUTPUT:
>> m=.5 m= 0.500 >> c=-2; >> x=[0,1.5,3,4,5,7,9,10] x= Columns 1 through 7 0 1.5000 3.0000 4.0000 5.0000 7.0000 9.0000

Column 8 10.0000 >> y=m*x+c y= Columns 1 through 7 -2.0000 -1.2500 -0.5000 Column 8 3.0000 >> t=[1:10] t= 1 2 3 4 5 6 7 8 9 10 0 0.5000 1.5000 2.5000

>> x=t.*sin(t) x= Columns 1 through 7 0.8415 1.8186 0.4234 -3.0272 -4.7946 -1.6765 4.5989

Columns 8 through 10 7.9149 3.7091 -5.4402

>> y=(t-1)./(t+1) y= Columns 1 through 7 0 0.3333 0.5000 0.6000 0.6667 0.7143 0.7500

Columns 8 through 10 0.7778 0.8000 0.8182

>> z=sin(t.^2)./(t.^2) z= Columns 1 through 7 0.8415 -0.1892 0.0458 -0.0180 -0.0053 -0.0275 -0.0195

Columns 8 through 10 0.0144 -0.0078 -0.0051 >> theta=[0;pi/4;pi/2;3*pi/4;pi;5*pi/4] theta =0 >> r=2; >> x=r*cos(theta); >> y=r*sin(theta); >> x.^2+y.^2 ans = 4 4 4 4 4 4 0.7854 1.5708 2.3562 3.1416 3.9270

>> x.^2+y.^2 ans = 4 4 4 4 4 4

>> n=0:10 n= 0 1 2 3 4 5 6 7 8 9 10

>> r=.5 r= 0.5000

>> x=r.^n

x =Columns 1 through 7 1.0000 0.5000 0.2500 0.1250 0.0625 0.0313 0.0156

Columns 8 through 11 0.0078 0.0039 0.0020 0.0010

>> s1=sum(x) s1 =1.9990 >> n=0:50 n =Columns 1 through 12 0 1 2 3 4 5 6 7 8 9 10 11

Columns 13 through 24 12 13 14 15 16 17 18 19 20 21 22 23

Columns 25 through 36 24 25 26 27 28 29 30 31 32 33 34 35

Columns 37 through 48 36 37 38 39 40 41 42 43 44 45 46 47

Columns 49 through 51 48 49 50

>> r=.5 r =0.5000 >> x=r.^n; >> s2=sum(x) s2 =2.0000 >> n=0:100 n = Columns 1 through 12 0 1 2 3 4 5 6 7 8 9 10 11

Columns 13 through 24

12

13

14

15

16

17

18

19

20

21

22

23

Columns 25 through 36 24 25 26 27 28 29 30 31 32 33 34

Columns 37 through 48 36 37 38 39 40 41 42 43 44 45 46 47

Columns 49 through 60 48 49 50 51 52 53 54 55 56 57 58 59

Columns 61 through 72 60 61 62 63 64 65 66 67 68 69 70 71

Columns 73 through 84 72 73 74 75 76 77 78 79 80 81 82 83

Columns 85 through 96 84 85 86 87 88 89 90 91 92 93 94 95

Columns 97 through 101 96 97 98 99 100

>> x=r.^n x= Columns 1 through 7 1.0000 0.5000 0.2500 0.1250 0.0625 0.0313 0.0156

Columns 8 through 14 0.0078 0.0039 0.0020 0.0010 0.0005 0.0002 0.0001

Columns 15 through 21 0.0001 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000

Columns 22 through 28 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000

Columns 29 through 35

0.0000

0.0000

0.0000

0.0000

0.0000

0.0000

0.0000

Columns 36 through 42 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000

Columns 43 through 49 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000

Columns 50 through 56 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000

Columns 57 through 63 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000

Columns 64 through 70 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000

Columns 71 through 77 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000

Columns 78 through 84 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000

Columns 85 through 91 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000

Columns 92 through 98 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000

Columns 99 through 101 0.0000 >> r=.5; >> x=r.^n x= Columns 1 through 7 1.0000 0.5000 0.2500 0.1250 0.0625 0.0313 0.0156 0.0000 0.0000

Columns 8 through 14 0.0078 0.0039 0.0020 0.0010 0.0005 0.0002 0.0001

Columns 15 through 21 0.0001 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000

Columns 22 through 28 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000

Columns 29 through 35 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000

Columns 36 through 42 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000

Columns 43 through 49 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000

Columns 50 through 56 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000

Columns 57 through 63 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000

Columns 64 through 70 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000

Columns 71 through 77 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000

Columns 78 through 84 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000

Columns 85 through 91 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000

Columns 92 through 98 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000

Columns 99 through 101 0.0000 >> r=.5; >> x=r.^n; >> s3=sum(x) s3 = 2 >> (1-1/2^5)^-1 ans = 1.0323 >> y=r*sin(theta); >> r=.5;993 ans = 993 >> v=0:0.2:12; >> m=[sin(v);cos(v)]; >> size(v) ans = 61 >> size(m) ans = 61 >> m(1:1:10) ans = Columns 1 through 7 0 1.0000 0.1987 0.9801 0.3894 0.9211 0.5646 0.0000 0.0000

Columns 8 through 10

0.8253

0.7174

0.6967

>> m(2:1:10) ans = Columns 1 through 7 1.0000 0.1987 0.9801 0.3894 0.9211 0.5646 0.8253

Columns 8 through 9 0.7174 0.6967

Practical - 3

Objective: To learn how to plot a function of an independent variable in matlab.

What we are going to learn from this practical?


1) How to plot a sine function in MATLAB. 2) How to plot a curve of a transcendental equation 3) How to provide the title of the plot, x-label and y-label.

Method:
1) For plotting any function, first the values of the independent variable are inserted, and then these values are put into the given function to calculate the values of dependent function. Then the plot of dependent and independent variables is made using inbuilt functions like plot( ), semilog( ), plot3( ) etc. The variables are inserted as the parameters of the functions. 2) Any appropriate title can be provided to the plot using title( ) function with name given as the parameter in the function. 3) Similarly labels for x-axis and y-axis can be provided using xlabel( ) and ylabel() functions.

Commands and Output:


>> x=linspace(0,2*pi,100) x= Columns 1 through 7 0 0.0635 0.1269 0.1904 0.2539 0.3173 0.3808

Columns 8 through 14 0.4443 0.5077 0.5712 0.6347 0.6981 0.7616 0.8251

Columns 15 through 21 0.8885 0.9520 1.0155 1.0789 1.1424 1.2059 1.2693

Columns 22 through 28 1.3328 1.3963 1.4597 1.5232 1.5867 1.6501 1.7136

Columns 29 through 35 1.7771 1.8405 1.9040 1.9675 2.0309 2.0944 2.1579

Columns 36 through 42 2.2213 2.2848 2.3483 2.4117 2.4752 2.5387 2.6021

Columns 43 through 49 2.6656 2.7291 2.7925 2.8560 2.9195 2.9829 3.0464

Columns 50 through 56 3.1099 3.1733 3.2368 3.3003 3.3637 3.4272 3.4907

Columns 57 through 63 3.5541 3.6176 3.6811 3.7445 3.8080 3.8715 3.9349

Columns 64 through 70 3.9984 4.0619 4.1253 4.1888 4.2523 4.3157 4.3792

Columns 71 through 77 4.4427 4.5061 4.5696 4.6331 4.6965 4.7600 4.8235

Columns 78 through 84 4.8869 4.9504 5.0139 5.0773 5.1408 5.2043 5.2677

Columns 85 through 91 5.3312 5.3947 5.4581 5.5216 5.5851 5.6485 5.7120

Columns 92 through 98 5.7755 5.8389 5.9024 5.9659 6.0293 6.0928 6.1563

Columns 99 through 100 6.2197 6.2832

>> y=sin(x) y= Columns 1 through 7 0 0.0634 0.1266 0.1893 0.2511 0.3120 0.3717

Columns 8 through 14 0.4298 0.4862 0.5406 0.5929 0.6428 0.6901 0.7346

Columns 15 through 21 0.7761 0.8146 0.8497 0.8815 0.9096 0.9341 0.9549

Columns 22 through 28 0.9718 0.9848 0.9938 0.9989 0.9999 0.9969 0.9898

Columns 29 through 35 0.9788 0.9638 0.9450 0.9224 0.8960 0.8660 0.8326

Columns 36 through 42 0.7958 0.7557 0.7127 0.6668 0.6182 0.5671 0.5137

Columns 43 through 49 0.4582 0.4009 0.3420 0.2817 0.2203 0.1580 0.0951

Columns 50 through 56

0.0317 -0.0317 -0.0951 -0.1580 -0.2203 -0.2817 -0.3420 Columns 57 through 63 -0.4009 -0.4582 -0.5137 -0.5671 -0.6182 -0.6668 -0.7127 Columns 64 through 70 -0.7557 -0.7958 -0.8326 -0.8660 -0.8960 -0.9224 -0.9450 Columns 71 through 77 -0.9638 -0.9788 -0.9898 -0.9969 -0.9999 -0.9989 -0.9938 Columns 78 through 84 -0.9848 -0.9718 -0.9549 -0.9341 -0.9096 -0.8815 -0.8497 Columns 85 through 91 -0.8146 -0.7761 -0.7346 -0.6901 -0.6428 -0.5929 -0.5406 Columns 92 through 98 -0.4862 -0.4298 -0.3717 -0.3120 -0.2511 -0.1893 -0.1266 Columns 99 through 100 -0.0634 -0.0000 >> plot(x,y) >> xlabel('x'),ylabel('sin(x)') >>title('Plot of x vs sin(x)')

>> plot(x,y,'*');

>> plot(x,y,x,y,'*');

>>x=linspace(0,4*pi,10); >> y=exp(-0.4*x).*sin(x); >> plot(x,y);

>> t=linspace(0,20,50); >> x=sin(t); >> y=cos(t); >> z=t; >> plot3(x,y,z);

>> x=0:10:1000; >> y=x.^3; >> semilogx(x,y);

>> x=linspace(0,2*pi,100); >> y=cos(x); >> plot(x,y)

>> hold on >> z=sin(x); >> plot(x,z)

Practical - 4

Objective: TO LEARN HOW TO CREATE SCRIPT FILES FOR PLOTTING A CIRCLE AND WORK WITH THE SCRIPT FILE IN MATLAB

WHAT ARE WE GOING TO LEARN FROM THIS PRACTICAL?


1) 2) 3) 4) How to create script files in the editor of Matlab? How to view that script file (saved as .m file) in the workspace of Matlab? How to add comments to the script files? How to run script files?

Methods:
1) For creating the script file, the code for the file is written in Matlabs editor and then it is saved with .m as extension. 2) To view that script file, type filename.m command is used. 3) Any comment that has to be added to the script file should start with a percentage sign (%). Whenever we ask for help about any pre-created script-file, the comments in the file are shown as the description of the file. 4) To run a script file, open the file and click on the run option of the debug menu of the editor of Matlab.

Commands and Output:


>> type circle %CIRCLE-A script file to draw a unit circle %------------------------------theta=linspace(0,2*pi,2000); x=cos(theta); y=sin(theta); plot(x,y); axis('equal'); title('Circle of unit radius');

>> type circle2 %CIRCLE-A script file to draw a circle of given radius %-----------------------------------------------------r=input('Enter the radius of the circle:'); theta=linspace(0,2*pi,2000); x=r*cos(theta); y=r*sin(theta); plot(x,y,0,0,'*'); axis('equal'); title('Circle of given radius r:'); Enter the radius of the circle:4

>> type hello %Matlab -Hello %------------------------disp('Hello World') disp(' ') disp('Today is........') disp(date) time=fix(clock); hourstr=int2str(time(4)); minstr=int2str(time(5)); if time(5)<10 minstr=['0',minstr]; end timex=[hourstr ':' minstr]; disp(' ') disp('And the time is....') disp(timex) >> run hello Hello World Today is........ 19-Oct-2011 And the time is.... 21:45

Vous aimerez peut-être aussi