Matlab simulink 3d animation

matlab simulink block diagram and also matlab simulink examples and how to download matlab simulink free
LylaKnight Profile Pic
LylaKnight,France,Professional
Published Date:12-07-2017
Your Website URL(Optional)
Comment
Introduction to MATLAB / SIMULINK C. James Taylor c.taylorlancaster.ac.uk Engineering Department Faculty of Science and Technology Lancaster University TM MATLAB is an interactive programming language that can be used in many ways, including data analysis and visualisation, simulation and engineering problem solving. It may be used as an interactive tool or as a high level programming language. It provides an effective environment for both the beginner and for the professional engineer and scientist. TM SIMULINK is an extension to MATLAB that provides an iconographic programming environment for the solution of differential equations and other dynamic systems. The package is widely used in academia and industry. It is particularly well known in the following industries: aerospace and defence; automotive; biotech, pharmaceutical; medical; and communications. Specialist toolboxes are available for a diverse range of other applications, including statistical analysis, financial modelling, image processing and so on. Furthermore, real time toolboxes allow for on-line interaction with engineering systems, ideal for data logging and control. At Lancaster University, MATLAB is used for research and teaching purposes in a number of disciplines, including Engineering, Communications, Maths & Stats and Environmental Science. In Engineering, students use MATLAB to help with their coursework, 3rd year individual project and MEng team project, as well as in their later career. References These notes are based on the Laboratory Handouts for the following Engineering Department taught modules: • ENGR.202 Instrumentation & Control • ENGR.500 MSc Start–Up Week Some sections align with the ENGR.202 syllabus (particularly the use of a generalised second order differential equation in Part 3) but most examples are designed to be self-explanatory. The notes are also based on the laboratories for ENGR.263 System Simulation (now laid down), developed by Prof. A. Bradshaw and updated by the present author. Some of the examples are based on code from the following recommended textbook: • Essentials of Matlab Programming (2009) S. J. Chapman, Cengage Learning, International Student Edition, 2nd Edition. TM MATLAB/SIMULINK is developed and distributed by The Mathworks Inc. For more information visit their web site at: http://www.mathworks.com/ These notes are based on MATLAB 7.0 (R14), running from a Windows XP based PC. Differences may emerge in other versions of the software, but trial and error experimentation should usually solve any problems. 27th March 2010 Part 1 – Introduction to MATLAB 1.1 Learning Objectives This laboratory (Part 1) provides a basic introduction to MATLAB. By the end of the session, you should be able to: • use MATLAB in ‘calculator mode’; • manipulate variables and import data files; • plot, annotate and copy graphs to a word processor; • write simple programs (scripts) using loops and conditional statements; • use in-built MATLAB functions, e.g. cos, sin and plot. Before leaving the class, check back on these objectives – these skills will be needed later on 1.2 MATLAB Command Line Although its original inspiration was to provide easy access to matrix operations, MATLAB (‘Matrix Laboratory’) can also be conveniently used for elementary calculations such as those available on an electronic calculator, as shown below. To begin a session on a PC, click on the MATLAB desktop icon or use the Windows Start menu. The “MATLAB Command Window” will eventually appear, where you can type instructions. Depending on the last user of your PC, the interface may appear differently. To avoid later confusion in these notes, you should follow the steps below before continuing: • Select Desktop from the MATLAB menu • Select Desktop Layout  Command Window Only The MATLAB window should now look something like the picture above. Type 1 + 2 and press return. The result is assigned to the generic variable ans and is printed on the screen. Not too difficult so far You can quit MATLAB at any time by selecting the File Menu item Exit or by typing Quit in the command window. 2 1.2.1 Expressions The usual arithmetical operators, + addition - subtraction multiplication / division power can be used in expressions. The rules of precedence are first, then / , , - and finally +. Expressions in brackets are evaluated first. Where two operations rank equally in the order of preference, then the calculation is performed from left to right. Blank spaces around the = , + and - signs are optional. Spaces are used in these notes to improve readability, but you do not need to type these spaces out when you try the examples for yourself. Arithmetic expressions allow MATLAB to be used in ‘calculator mode’ as shown below, always remembering to press return after typing a command: » 100/5 return ans = 20 » 100/5/2 ans = 10 » 100 + 5/2 ans = 102.5 » (100 + 5)/2 ans = 52.5 » 100 + 52/2 ans = 112.5 » 100 + 5(2/2) ans = 105 In all these examples, the result is assigned to the generic variable ans. Variables can be used in expressions if they have previously been assigned a numerical value, as in the following example: » a = 10 » b = 100 » ab ans = 1000 Variables can be reassigned: » a = 10 » b = 100 » a = ab a = 1000 3 Use the who command to see a list of defined variables in alphabetical order. If you have been typing the commands above, you will have three variables in memory so far: a, ans and b. Type the name of one of these variables and press return to see its current value: » who Your variables are: a ans b » a a = 1000 » b b = 100 Exercise 1 Use MATLAB to evaluate the following: 100++++ 5 97×××× 5 3 (i) 100++ 5 , (ii) , (iii) 3×× 100++ ++ ×× ++ 2++++ 10 2++++ 20 1.2.2 Editing previous commands MATLAB responds to invalid expressions with a statement indicating what is wrong, as in the example below. Here, we would like to sum two variables and then divide the total by 2, but what happens if we miss out the closing right bracket? » b = 100 » c = 5 » (b + c/2 ??? (b + c/2 A closing right parenthesis is missing. Check for a missing ")" or a missing operator. At any time, you can use the cursor keys to: • edit text on the command line (using the left / right arrow keys); • scroll back to find previously entered commands (using the up / down arrow keys); Exercise 2 Use the arrow keys to edit the previous command and hence find(b+c)/2 Check that the answer makes sense. 1.2.3 Statements and variables Statements have the generic form: variable = expression The equals symbol implies the assignment of the expression to the variable. Several scalar examples have already been given above, while a typical vector statement is: » x = 1 3 x = 1 3 4 Here the numbers 1 and 3 are assigned to an array or vector (i.e. a list of numbers) with the variable name x. The statement is executed immediately after the enter key is pressed. The array x is automatically displayed after the statement is executed. If the statement is followed by a semi-colon then the array is not displayed. Thus, now typing the statement: » x = 1 4; would not result in any output on screen but the assignment will still have been carried out You can confirm this for the above example by checking the current value of the variable: » x x = 1 4 Although not often required in these laboratory notes, the semi-colon is useful when analysing large arrays, since it avoids having to wait for several pages of data to scroll down the screen. It is also useful later on when writing your own functions, since you can avoid displaying unnecessary intermediate results to the screen. Array elements can be any valid MATLAB expression. For example: » x = -1.3 32 (1+2+3)4/5 x = -1.3000 9.0000 4.8000 Individual array elements can be referenced with indices inside brackets. Thus, continuing the previous example: » a = x(2) a = 9 » x(1) ans = -1.3 » -2x(1) ans = 2.6 » x(5) = -2x(1) x = -1.3000 9.0000 4.8000 0 2.6000 In the last case, notice that the size of the array has been automatically increased to accommodate the new element. Any undefined intervening elements, in this case x(4), are set to zero. 1.2.4 Elementary functions All the common trigonometric and elementary mathematical functions are available for use in expressions. An incomplete list includes: sin(X) sine of the elements of X cos(X) cosine of the elements of X asin(X) arcsine of the elements of X acos(X) arccosine of the elements of X 5 tan(X) tangent of the elements of X atan(X) arctangent of the elements of X abs(X) absolute value of the elements of X sqrt(X) square root of the elements of X imag(X) imaginary part of the elements of X real(X) real part of the elements of X log(X) natural logarithm of the elements of X log10(X) logarithm base 10 of the elements of X exp(X) exponential of the elements of X These functions can be included in any expression. Note that the argument X of the function may be a scalar or an array. In the latter case, the result is an array with element-by -element correspondence to the elements of X, as can be seen in this example: » sin(0 1) ans = 0 0.8415 The answer is in radians. Variable names begin with a letter that may be followed by any number of letters and numbers (including underscores), although MATLAB only remembers the first 31 characters. It is good practice to use meaningful names, but not to use names that take too long to type. Since MATLAB is case sensitive, the variables A and a are different. Note that all the predefined functions, such as those listed above have lowercase names. » a = 0 1 » A = sin(a) A = 0 0.8415 » B = cos(a) B = 1 0.5403 The function clear removes a variable from the workspace: » clear A » who Your variables are: a B ans MATLAB has several predefined variables, including: pi π NaN not - a - number Inf ∞ ∞ ∞ ∞ i -1 j -1 Although it is not recommended, these predefined variables can be overwritten. In the latter case, they can be reset to their default values by using the clear function. For example: » pi = 5 pi = 5 6 Oops, probably a bad idea » clear pi » pi pi = 3.1416 The special variable called NaN results from undefined operations. For example: » 0/0 Warning: Divide by zero ans = NaN Variables are stored in the workspace. The who function introduced above gives a list of the variables in the workspace, while the whos function gives additional information such as the number of elements in an array and the amount of memory occupied. Typing clear by itself removes all variables from the workspace, while clear name1 name2 ... removes only the particular named variables in the list. All computations in MATLAB are performed in double precision. However, the screen output can be displayed in several formats. The default contains four digits past the decimal point for non integers, as seen above. This can be changed using the format function as shown below: » format long » pi ans = 3.14159265358979 » format short e » pi ans = 3.1416e+000 » format long e » pi ans = 3.141592653589793e+000 Finally, return to the standard format: » format short » pi ans = 3.1416 1.2.5 Array operations Arrays with the same number of elements can be added and subtracted. This means adding and subtracting the corresponding elements in the arrays, as in the following example: » x = 1 2 3 » y = 4 5 6 » z = x + y z = 5 7 9 7 This is called an element-by-element operation. Such operations are useful for setting up tables of values and for graph plotting. Attempting to perform element-by-element operations on arrays containing different numbers of elements will result in an error message. Addition, subtraction, multiplication and division of an array by a scalar (an array with one element) is allowed and results in the operation being carried out on every element of the array. Thus, continuing the previous example: » w = z - 1 w = 4 6 8 Larger arrays can be set up by using the colon notation to generate an array containing the numbers from a starting value xstart, to a final value xfinal, with a specified increment xinc, by a statement of the form: x = xstart: xinc: xfinal. The following example generates a table of x against y where y = x sin(x). » x = 0: 0.1: 0.5 x = 0 0.1000 0.2000 0.3000 0.4000 0.5000 » y = x.sin(x) y = 0 0.0100 0.0397 0.0887 0.1558 0.2397 When the element-by-element operations involve multiplication, division and power, the operator is preceded by a dot, as shown below. It is easy to forget this and encounter an error » A=1 2 3 » B=-6 7 8 » A.B ans = -6 14 24 » A.2 ans = 1 4 9 The dot avoids ambiguities which would otherwise arise since, by default, MATLAB expects vector-matrix analysis: see below. 1.2.6 Vectors and Matrices In vector-matrix terms, it is not possible to multiply two row vectors, hence simply typing AB (without including the dot) results in an error: » A=1 2 3 » B=-6 7 8 » AB ??? Error using == mtimes Inner matrix dimensions must agree. However, a row vector can be multiplied by a column vector as follows. First of all, take the transpose of B using the inverted comma symbol, to create a column vector: 8 » C = B’ C = -6 7 8 In vector-matrix analysis, the order of the multiplication makes a difference to the solution: » A C ans = 32 » C A ans = -6 -12 -18 7 14 21 8 16 24 If you are not sure about the above results, then you might wish to read up about vectors and matrices. Matrices can be defined by hand using a semi-colon to indicate a new row: » X=1 2; 3 4; 5 6 X = 1 2 3 4 5 6 The transpose operator also works for matrices, as shown below: » X’ ans = 1 3 5 2 4 6 Some matrices can be defined using built-in MATLAB functions, as in the following examples: » ones(2, 3) ans = 1 1 1 1 1 1 » zeros(2, 2) ans = 0 0 0 0 » eye(3, 3) ans = 1 0 0 0 1 0 0 0 1 The last example is called the identity matrix. 9 Exercise 3 (i) Experiment with the functions ones, zeros and eye to learn how they work. Use these functions to create the following: • 5 x 5 diagonal matrix with elements all equal to 8 • 6 x 6 matrix with all its elements equal to 3.5 (ii) Evaluate the following expressions, with: A ==== 100, B ==== 5, C==== 2, D==== 10. A++++ B++++ C −−−−1 AD C (i) , (ii) A++++ B , (iii) , (iv ) 2D B( A−− B) BC −− (iii) Calculate the areas of circles of radius 1, 1.5, 2, 2.5, ..., 10m. Hint: to quickly solve all five cases at once, first define an array for the radius, e.g. rad = 1:0.5:10. (iv) Calculate the areas of the rectangles whose lengths and breadths are given in the following table. Again, it is good practice to use arrays – for more advanced problems, this would save the programmer a lot of time. length 5 10 3 2 breadth 1 5 2 0.5 1.2.7 Graphics Graphics play an important role in the design and analysis of engineering systems. The objective of this section is to introduce the most basic x-y plotting capability of MATLAB. A figure window is brought up automatically when the plot function is used. The user can switch from the figure window to the command window using the mouse. Multiple plots may be open at one time: use the figure command to open a new figure window. Available plot functions include: plot(x,y) plots the array x versus the array y semilogx(x,y) plots the array x versus the vector y with log scale on the x-axis 10 semilogy(x,y) plots the array x versus the vector y with log scale on the y-axis 10 loglog(x,y) plots the array x versus the vector y with log scale on both axes 10 The axis scales and line types are automatically chosen. However, graphs may be customised using the following functions: title('text') puts ‘text’ at the top of the plot xlabel('text') labels the x-axis with ‘text’ ylabel('text') labels the y-axis with ‘text’ text(p,q,'text','sc') puts ‘text’ at (p, q) in screen co-ordinates subplot divides the graphics window grid on / grid off draws grid lines on the current plot (turns on or off) Screen co-ordinates define the lower left corner as (0.0, 0.0) and the upper right as (1.0, 1.0). Plots may also be annotated by using the various menu options on the graph window. To illustrate some of these functions, consider a plot of y = x sin(x) versus x as shown below. » x = 0: 0.1: 1.0; y = x.sin(x) » plot(x, y) » title('Example 1.1. Plot of y = x sin(x)') » xlabel('x'); ylabel('y'); grid on 10 Plots may include more than one line and line types may be specified in the plot statement: - solid line dashed line : dotted line r red line b blue line k black line Type help plot to see a full list of all the colour and line type options. Normally, the plot command clears any previous lines in the same figure window. However, hold on freezes the figure and is useful for graphing multiple lines, as shown in the next example. Here, for brevity, some of the commands are written on the same line, separated by a semi- colon – you can either type the example this way, or write on separate lines as usual. » x = 0: 0.1: 1.0; y1 = x.sin(x); y2 = sin(x); » plot(x,y1,''); hold on; plot(x,y2,'-.') » title('Example 1.2. Plot of y1 and y2') » xlabel('x'); ylabel('y1, y2') » text(0.1,0.85,'y1 = x sin(x) -') » text(0.1,0.75,'y2 = sin(x) -.-.-.') The graph display can be divided into two, four or more smaller windows using the subplot(m,n,p) function. The effect is to divide the graph display into an m by n grid of smaller windows. This facility is illustrated in the next example. For brevity, the various annotations are omitted from the code below. » x = 0: 0.1: 1.0; » y1 = x.sin(x); y2 = sin(x); y3 = x.cos(x); y4 = cos(x); » subplot(2,2,1); plot(x,y1,'-') » subplot(2,2,2); plot(x,y2,'') » subplot(2,2,3); plot(x,y3,':') » subplot(2,2,4); plot(x,y4,'-.') 11 This document was created using Microsoft Word. The MATLAB graphs where copied to the clipboard using the MATLAB Figure Window Menu  Edit  Copy Figure, before being pasted into the word processor. To avoid ink wastage, it is best to set the background to white as follows: • From the Figure Window Menu  Edit  Copy Options… • Select Figure Copy Template  Copy Options  Force White Background. Exercise 4 Plot the graph which relates temperature in degrees centigrade from –50 to 150 C to degrees Fahrenheit. Plot the graph of the inverse function which relates degrees Fahrenheit to degrees centigrade. The relationship between the two is: 9× Centigrade Fehrenheit = 32+ 5 1.3 MATLAB Scripts So far, all interaction with MATLAB has been at the command prompt labelled ». At this prompt, a statement is entered and executed when the enter key is pressed. This is the preferred way of working only for short and non repetitive jobs. However, the real power of MATLAB for engineering calculations derives from its ability to execute a long sequence of commands stored in a file. Such files, which are generally called m-files since the filename has the form filename.m, may be either a function (see next laboratory class) or a script. Although MATLAB provides its own editor, both scripts and functions are ordinary ASCII text files which can be created and edited using any text editor or word processor. A script is just a sequence of statements and function calls that could also be used at the MATLAB command prompt. It is invoked or ‘run’ by typing the filename (without the .m extension), and simply works through the sequence of statements in the script automatically. Suppose that it is required to plot the function y = sin(ωt) for different values of the variable ω (the frequency). A script called plotsine.m is created, as shown below. You can create it by using the MATLAB Editor: select the New (M-file) item on the MATLAB File Menu or click on the standard Microsoft Window’s icon for a New Document, which is to be found near the top left of the MATLAB Command Window. Type in the commands shown in the box below. Save your work to a file called plotsine. Note that the Matlab Editor will automatically add the .m file extension. 12 % This is a script to plot the function y = sin(omegat). % % The value of omega (rad/s) must be in the workspace % before invoking the script t = 0: 0.01: 1; % time y = sin(omegat); % function output plot(t,y) xlabel('Time (s)'); ylabel('y') title(' Plot of y = sin(omegat)') grid Important At this stage, the commands in the box above should be saved in a text file. They should not be typed in the command window Any problems, please consult a demonstrator. Similar applies to other boxed text  in these notes. Scripts should be well documented with comments, so that their purpose and functionality can be readily understood sometime after their creation. A comment begins with a %. Comments at the beginning of a script form a header which can be displayed using the help function. This is illustrated by the following example: » help plotsine This is a script to plot the function y = sin(omegat). The value of omega (rad/s) must be in the workspace before invoking the script If this help message does not appear, it may be because you have saved the file to a different location from the current MATLAB workspace. For example, if you saved the file to h:\myfiles\plotsine.m then change to this directory using cd before continuing: » cd h:\myfiles » help plotsine Next, type in a value for omega: » omega=10 omega = 10 Finally enter the name of your script in the command window and press return. If you wish to change the value of omega, you should ‘re-run’ the script to update the plot, as shown below: » plotsine » omega=20 » plotsine 13 MATLAB program outputs can be made more informative by using the disp function. The purpose of this function is to display text or variable values on screen. Another useful function is format compact, which reduces the number of spaces that MATLAB inserts. The normal display is obtained by using the function format loose. Use of these functions is illustrated in the following example. Create a script for the following boxed text and save as an m-file called example.m % Example Script format compact length = 5 10 3 2; breadth = 1 5 2 0.5; area = length.breadth; disp(' length breadth area') disp(' m m sq m') disp(length' breadth' area') The program is then run by typing its filename at the MATLAB command prompt: » example length breadth area m m sq m 5.0000 1.0000 5.0000 10.0000 5.0000 50.0000 3.0000 2.0000 6.0000 2.0000 0.5000 1.0000 Note that the elements of the array variables length, breadth and area have been printed out as columns rather then rows. The apostrophe after the name changes the array from a row to a column, i.e. vector transpose (see Section 2.6 above). In fact, the expression length' breadth' area' creates a matrix comprising these three columns. 1.3.1 For loops A for loop allows a statement, or group of statements, to be repeated a fixed predetermined number of times. For example: » for i = 1:5; x(i) = i2; end » x x = 2 4 6 8 10 In the above example, i2 is assigned to the elements of the array x, where i = 1 to 5. Notice that four statements have been written on one line, terminated by a semicolon to suppress repeated printing during the loop. The x at the end displays the final result. Note that each for statement must be matched with an end to close the loop. 14 1.3.2 Conditional statements The MATLAB function if conditionally executes statements. The simple form is, if expression statements else statements end Both loops and conditional statements are most useful as part of a computer program – in other words, as a way of controlling what happens in a MATLAB script. The following program illustrates both loops and conditional statements. The example is rather arbitrary, but study it carefully and experiment until you are confident about how these programming constructs work. The example is stored as the script file example.m Notice that use has been made of the MATLAB function size which returns the number of rows and columns in the two dimensional array x. In this program, m = 1 since x is a single row, while n = 21. This saves the trouble of manually counting the number of elements in x. % This is a script to identify membership of the open % set x:abs(x-3)5 and the closed set x:abs(x-3)=5 x = -10:1:10; m,n = size(x); for i=1:n if abs(x(i) - 3) 5 yopen(i)=1; else yopen(i)=0; end if abs(x(i) - 3) = 5 yclosed(i)=1; else yclosed(i)=0; end end disp(' x yopen yclosed'); disp(x' yopen' yclosed') » example x yopen yclosed -10 0 0 -9 0 0 -8 0 0 -7 0 0 -6 0 0 -5 0 0 -4 0 0 -3 0 0 -2 0 1 -1 1 1 0 1 1 1 1 1 2 1 1 3 1 1 4 1 1 15 5 1 1 6 1 1 7 1 1 8 0 1 9 0 0 10 0 0 1.3.3 External data MATLAB can import data in a number of formats, including simple text, spreadsheet files, image files, sound files and even movies. The load command is used to import ASCII text. Typically, such a file contains data collected from an engineering device or other system of interest. For example, use the Windows Notepad or the MATLAB Editor to create the following file called test.txt and save it to the PC hard drive or your network drive. Here, the first column might be the time, while the second column is a measurement, say a voltage. The data file should contain only numbers separated by commas or spaces: 10, 8 20, 11 30, 16 40, 15 50, 18 » load test.txt » who Your variables are: test Note that the file extension .dat is required to load the data, but by default MATLAB assigns these data to a variable name that does not include the file extension. If you encounter a file- not-found error, then use the cd command to make sure that the working directory contains the data file in question. Alternatively, use the full path when loading the data, for example: » load h:\myfiles\data\test.txt 1.3.4 Matrix Elements The variable test above is a 5 by 2 matrix, i.e. 5 rows and 2 columns. Individual elements of this matrix may be extracted as illustrated below: » test(3, 2) ans = 16 Recall that ans is the default variable name. As usual, you can assign the result to a named variable by using the equals symbol. Also, the colon character is used to assign an entire row or column: » x = test(2, :) x = 20 11 The final example plots the second column against the first column: » plot(test(:, 1), test(:, 2)) 16 Exercise 5 Consider the control of ventilation rate in an instrumented micro-climate test chamber. For these exercises, sample data files are provided on the Internet at: http://www.lancs.ac.uk/staff/taylorcj/teaching/ Download one of these files to the PC hard drive or your network drive, e.g. when using some web browsers, right click and select Save As… 3 The first column of each data file is the ventilation rate (m /hour), while the second column is the input variable (fan voltage expressed as a percentage). The data are sampled every 2 seconds (each row of the file). Each file represents one particular experiment, showing how the ventilation rate responds to a given voltage signal. 1. Pick one of the data files. Write a script to load the data into MATLAB and generate a graph similar to the one shown below. You will need to use: load, subplot, plot, title, ylabel, xlabel and axis. Use the help command for more information about this new axis function: can you work out how to use it? 2. Use your script to very quickly plot data from the other files. If you have written an appropriate script for the first exercise above, all you have to do is change the filename. This is one advantage of using a script, as opposed to typing all the commands into the command window each time. If you have typed out the commands out one by one, or have used the menu system to annotate the graph, then it would be much more work 17 Part 2 – Writing and using MATLAB functions Both scripts and functions are text files with the extension .m and hence both are sometimes called MATLAB m-files. As discussed in Part 1, a script is a sequence of statements and function calls that could also be used at the MATLAB command prompt. It is invoked or ‘run’ by typing the filename and simply works through the sequence of statements in the script – just as though these were typed individually into the command window. A function file differs from a script in that variables defined inside the file are local to the function and do not operate globally on the workspace: see examples below. For this reason, arguments may be passed from the workspace to the function. Similarly, any useful variables (outputs) from the function, should be defined as output arguments, or else they will not appear as variables in the workspace. This is similar to functions in other programming languages, such as ‘C’. 2.1 Learning Objectives This laboratory (Part 2) provides a basic introduction to using and writing functions in MATLAB. By the end of the session, you should be able to: • understand the difference between global and local variables; • use common built-in MATLAB functions such as plot, cos and sin; • use pre-installed Toolboxes for extending the MATLAB language; • use MATLAB functions with multiple input and output arguments; • write your own functions to solve engineering problems. Before leaving the class, check back on these objectives. 2.2 Built-in Functions You should be familiar with several built-in functions, such as plot, load and cos. Such functions are ‘hard-wired’ into the software package and cannot be copied or modified. » cos(0) ans = 1 Here, the cos function takes the input argument zero and returns an output of unity, which is subsequently assigned to the default variable ans. The input and output arguments can be given any valid variable name. The function can also operate (element-by-element) on arrays: » a = 0:0.2:2pi a = Columns 1 through 8 0 0.2000 0.4000 0.6000 0.8000 … » b = cos(a) b = Columns 1 through 8 1.0000 0.9801 0.9211 0.8253 0.6967 … Some functions accept two or more input arguments, such as: » plot(a, b) 18 In fact, plot can accept numerous input arguments, as the following example illustrates: » c = sin(a) » plot(a, b, '-', a, c, '', 'linewidth', 2) Here, two curves are plotted on the same graph (an alternative way of doing this is to use the hold on command), one with a solid trace, the other dashed. Finally, both lines are made thicker than the default case, as specified by the final two input arguments. More details about the plot function can be found by typing: » help plot Some functions return two or more output arguments: » x = now x = 7.3291e+005 » Y, MO, D, H, MI, S = datevec(x) Y = 2006 MO = 8 D = 23 H = 12 MI = 13 S = 4.9790 19 The example above first uses the now function to obtain a scalar representation of the current time and date: obviously this number will be different when you try this example However, it is more useful to subsequently extract the year, months, date, hour, minutes and seconds from this scalar using datevec, which returns up to 6 output arguments. Note that it is up to the user to specify any necessary output arguments. For example, the following call to datevec only returns the year and month: » clear » x = now x = 7.3291e+005 » yr, mth=datevec(x) yr = 2006 mth = 8 » who Your variables are: mth x yr Since the workspace was cleared at the start of this example, the day and time do not appear in the list of variables. 2.3 MATLAB Toolboxes Type help and press return: » help return HELP topics matlab\general - General purpose commands. matlab\ops - Operators and special characters. matlab\lang - Programming language constructs. matlab\elmat - Elementary matrices and matrix manipulation. matlab\elfun - Elementary math functions. ... You will see a list of MATLAB toolboxes installed on your computer. Scroll up to see all the items on this list. Each toolbox contains various functions grouped together under a common heading. For example, typing help elfun provides a list of elementary math functions, including trigonometric functions. » help elfun Elementary math functions. Trigonometric. sin - Sine. sind - Sine of argument in degrees. ... Some of the functions in these toolboxes are very commonly used, others are more specialist in nature. For example, your version of MATLAB may include the Control System Toolbox, which includes numerous tools useful for the subject of control engineering. In fact, specialist 20