The window in Figure 1. The left bracket on the upper left side of the white note pad is where the commands are typed. The panel on the right side of the pad is the Command Bar. It provides easy access to many of the commands needed to do mathematics including the manipulation and evaluation of math- ematical expressions as well as plotting graphs.
The two toolbars above the pad provide useful utilities to enhance your usage of MuPAD. Moving the cursor over the items on the second line tells you what each button does.
The first line requires moving the cursor over them and a left-click on the mouse to open the pull-down menu. Let us examine a simple example. Left-click in the note pad just above the left bracket. At this location you can start typing text i. Figure 1. This notebook was saved under the name Calc1. The details of this example are also provided in the figure. They are as follows: Differentiation and integration In this note we are going to examine a few of the mathematical commands available to us and listed in the Command Bar.
Let us begin with taking the derivative of a function f. With the cursor placed on the upper left most symbol, a left-click on the mouse produces the following result: diff f, x. The sign is a place holder at which input is required. The next step is to point to the right of the left bracket below and left-click to place the note pad cursor at this location.
Then click on the command of interest in the Command Bar. Then hit enter to execute the command. Left-click on this operation in the Command Bar to get: int f, x. Replace f with S1 and x with x. The only issue, if any, that you must keep in mind is that the constants of integration are set to zero.
If you need to explicitly carry them along in your analysis, then you must add a constant to the results at this step. The help can be accessed by a left click on the blue circle with the question mark in the toolbar just above this pad.
A second example is the graphics capabilities in MuPAD. The MuPAD environment is particularly well suited for this kind of investigation. Suppose you are reading a technical article and you come across two interesting functions and you want to have an idea as to what they look like. Let us examine two examples.
One is the sech2 x function which plays an important role in nonlinear wave theory. The second is the complete elliptic integral of the first kind, viz. This integral plays an important role in potential theory. What do these functions look like? More on these functions among other functions can be examined in the help documentation and in the references cited in the help documentation. This concludes this brief introduction to an APP and a brief introduction to the capabilities of the Symbolic Math toolbox.
In addition, there is a capability for you to create your own APPS. Hence, if there is anything that we learn from our first experiences with MATLAB is that there is a lot to learn a lifelong experience of learning because of the wealth of technology incorporated in this technical computing environment. The fact that you can develop your own toolboxes, your own APPS, and you can customize your working environment desktop arrangement, color backgrounds, fonts, graph- ical user interfaces, and so on provides real opportunities and useful experi- ence in creating designs, creating useful tools and documenting your work.
You can even get a contour plot of the elements of a magic square. MATLAB pre- tends that the elements in the square are heights above sea level of points on a map, and draws the contour lines. If you want to see the famous Mexican hat Figure 1. The following animation is an extension of the Mexican hat graphic in Figure 1. The execution of the commands between the for and end state- ments repeat times in this example.
The pause 0. One way is to listen to the signal. For different sounds try loading chirp, gong, laughter, splat, and train. You have to run sound y,Fs for each one. Try why why not? Then try why 2 twice. The edit command will be used soon to illustrate the creation of an M-file like why. A collection of statements to solve such a problem is called a program.
In this section we look at the mechanics of writing and running two short programs, without bothering too much about how they work—explanations will follow in the next chapter. The Windows environment lends itself to nifty cut and paste editing, which you would do well to master. Proceed as follows. The additional argument 'k' for plot will draw a black graph, just to be different.
Change 'k' to 'r' to gener- ate a red graph if you prefer. Next, move the mouse pointer which now looks like a very thin capital I to the left of the x in the first line. Keep the left mouse button down while moving the mouse pointer to the end of the second line. This process is called dragging. Both lines should be highlighted at this stage, probably in blue, to indicate that they have been selected.
This action copies the highlighted text to the Win- dows clipboard, assuming that your operating system is Windows. Now go back to the Command Window. The contents of the clipboard will be cop- ied into the Command Window. To execute the two lines in the program, press Enter. The graph should appear in a figure window.
If you need to correct the program, go back to the Editor, click at the posi- tion of the error this moves the insertion point to the right place , make the correction, and cut and paste again.
Alternatively, you can use command-line editing to correct mistakes. As yet another alternative, you can paste from the Command History window which incidentally goes back over many previous sessions. To select multiple lines in the Command History window keep Ctrl down while you click. If you prefer, you can enter multiple lines directly in the Command Window. Then press Enter to run all the lines.
What will your bank balance be after one year? Now, if you want to write a MATLAB program to find your new bal- ance, you must be able to do the problem yourself in principle.
Display the new balance. Go back to the Editor. By the way, to de-select highlighted text, click anywhere outside the selection area. Enter the following program, and then cut and paste it to the Command Window: When you press Enter to run it, you should get the following output in the Command Window: 1. Obviously you need to save the program if you want to use it again later.
A Save file as: dialog box appears. Select a folder and enter a file name, which must have the extension. Click on Save. The Editor window now has the title junk. If you make subsequent changes to junk. We therefore refer to both script and function files gen- erally as M-files.
The special significance of a script file is that, if you enter its name at the command-line prompt, MATLAB carries out each statement in the script file as if it were entered at the prompt. As an example, save the compound interest program above in a script file under the name compint. The state- ments in compint.
A script file may be listed in the Command Window with the command type, e. Script files provide a useful way of managing large programs which you do not necessarily want to paste into the Command Window every time you run them. To change the current folder type the path for the new current folder in the toolbar, or select a folder from the drop- down list of previous working folders, or click on the browse button it is the first folder with the green arrow that is to the left of the field that indicates the location of the Current Folder.
Select a new location for saving and executing files e. You can change the current folder from the command line with cd command, e. Running a script from the current folder browser A handy way to run a script is as follows. Select the file in the Current Directory browser. Right-click it. The context menu appears context menus are a general feature of the desktop.
Select Run from the context menu. If you want to edit the script, select Open from the context menu. This means that each statement presented to the command line is translated interpreted into language the computer understands better, and then immediately carried out. You can think of this part of the memory as a bank of boxes or memory locations, each of which can hold only one number at a time.
Since the contents of balance may be changed during a session it is called a variable. Put the number into variable balance. Put the number 0. Multiply the contents of rate by the contents of balance and put the answer in interest. Add the contents of balance to the contents of interest and put the answer in balance.
Display in the Command Window the message given in single quotes. Display the contents of balance. In hardly seems necessary to stress this, but these interpreted statements are carried out in order from the top down. When the program has finished running, the variables used will have the following values: Note that the original value of balance is lost.
Try the following exercises: 1. Run the program as it stands. Can you explain what happens? Try to rewrite the program so that the original value of balance is not lost. A number of questions have probably occurred to you by now, such as: n What names may be used for variables?
These questions will be answered in the next chapter. However, before we write any more com- plete programs there are some additional basic concepts which need to be introduced. These concepts are introduced in the next chapter. They are carried out immediately. Write some statements to find the sum, difference, product and quotient of a and b. Type this into the editor, save it and execute it.
Once you finish debugging it and it executes successfully try modifying it. What is the square root of x? What is the cosine of the square root of x?
What is the square root of y? Hence the symbol i should not be used as an index or as a variable name. Hence, it also should not be used as an index or as a variable name.
Give an example of how you have used complex numbers in your studies of mathematics and the sciences up to this point in your education.
Solutions to many of the exercises are in Appendix E. The last part of this chapter and the next chapter Transposing vectors In a sense, the art of programming Operators, is this: expressions, and Getting the right values in the right variables at the right time statements The colon operator The transpose operator Examples of valid variable Formula vectorization Examples of invalid names why? Undefined function or variable … Limit of a sequence In other Avoid for loops by words, a scalar is a 1-by-1 array—an array with a single row and a single col- vectorizing!
Many programmers write variable names in lowercase except for the elseif This style is known as camel caps, the uppercase Multiple ifs versus elseif Examples are Nested ifs Some programmers prefer to sepa- Vectorizing ifs? The switch statement However, note that Complex numbers You must not use capitals when running built-in functions and commands! Enter the command clear and then rerun the compound interest program see Section 1. Now enter the command who.
You can use or change their values at any stage during the session. The command who lists the names of all the variables in your workspace. The command whos lists the size of each variable as well: Each variable here occupies eight bytes of storage. A byte is the amount of com- puter memory required for one character if you are interested, one byte is the same as eight bits.
The Class double array means that the variable holds numeric values as double-precision floating-point see Section 2. The command clear removes all variables from the workspace. A particular variable can be removed from the workspace e. More than one variable can also be cleared e. Separate the vari- able names with spaces, not commas. When you run a program, any variables created by it remain in the work- space after it runs. This means that existing variables with the same names are overwritten.
The Workspace browser on the desktop provides a handy visual representa- tion of the workspace. You can view and even change the values of workspace variables with the Array Editor. To activate the Array Editor click on a variable in the Workspace browser or right-click to get the more general context menu.
From the context menu you can draw graphs of workspace variables in various ways. For example, the following statements can be saved in myconst. A matrix is a rect- angular object e. A vector is a special type of matrix, having only one row or one column.
Vectors are called lists or arrays in other programming languages. MATLAB handles vectors and matrices in the same way, but since vectors are easier to think about than matrices, we will look at them first. We will also use the term array generally, with vector and matrix referring to the one-dimensional 1D and two-dimensional 2D array forms.
These are all examples of the explicit list method of initializing vectors. Exercises 2. Make sure to leave out the semicolon so that you can see the list. Also, make sure you hit Enter to execute the command. Under the heading Size you will see that x is 1 by 5, which means 1 row and 5 columns. You will also see that the total number of elements is 5. Take the space between the minus sign and 15 to see how the assignment of x changes.
This means x is defined and can be used where an array is appropriate without causing an error; however, it has no size or value. An empty array may be used to remove elements from an array see Section 2. The function logspace can be used to generate logarithmically spaced data. It is a logarithmic equivalent of linspace.
If the last number in this function call is omit- ted, the number of values of y computed is by default What is the interval between the numbers 1 and in this example? Thus, the logspace function produces a set of points with an interval between them that increases linearly with y. The vari- able yy was introduced for two reasons. The first was to generate a vector of the same length as dy.
The second was to examine the increase in the interval with increase in y that is obtained with the implementation of logspace. Each has one row and several columns. To generate the column vectors that are often needed in mathematics, you need to transpose such vectors—that is, you need to interchange their rows and columns. Note that x itself remains a row vector.
Try the following: 1. This gives you a row vector of seven random numbers. Enter r 3. This will display the third element of r.
The numeral 3 is the subscript. Enter r This should give you the second, third, and fourth elements. What about r and r [1 7 2 6]? You cre- ate a matrix just as you do a vector, except that a semicolon is used to indicate the end of a row. Generate the table of angles and sines as shown above. You can then edit the output, for example, by inserting text headings above each column this is easier than trying to get headings to line up over the columns with a disp statement.
The edited output can in turn be pasted into a report or printed as is the File menu has a number of printing options. Another way of capturing output is with the diary command.
The command: diary filename copies everything that subsequently appears in the Command Window to the text file filename. Stop recording the session with: diary off Note that diary appends material to an existing file—that is, it adds new infor- mation to the end of it. It is typically written in what is called pseudo-code— that is, statements in English, mathematics, and MATLAB describing in detail how to solve a problem. A structure plan may be written at a number of levels, each of increasing complexity, as the logical structure of the program is developed.
A first-level structure plan might be a simple statement of the problem: 1. Initialize Fahrenheit temperature 2. Calculate and display Celsius temperature 3. Step 1 is pretty straightforward. Step 2 needs elaborating, so the second-level plan could be something like this: 1. Initialize Fahrenheit temperature F 2. Display the value of C 4. The essential point is to cultivate the mental discipline of getting the problem logic clear before attempting to write the program.
The top-down approach of structure plans means that the overall structure of a program is clearly thought out before you have to worry about the details of syntax coding. This reduces the number of errors enormously. A script to implement this is as follows: Two checks of the tool were done. The results were found to be correct and hence this simple script is, as such, validated. The essense of any structure plan and, hence, any computer program can be summarized as follows: 1. Input: Delclare and assign of input variables.
Operations: Solve expressions that use the input variables. Output: Display in graphs or tables the desired results. Air resistance is ignored. We would like to compute the value of s over a period of about The structure plan for this problem is as follows: This plan may seem trivial and a waste of time to write down.
It is well worth developing the mental discipline of structure-planning your program first. Paste a second copy of the plan directly below the first. Finally, paste all the translated MATLAB statements into the Command Window and run them or you can just click on the green triangle in the toolbar of the Editor to execute your script. If necessary, go back to the Editor to make corrections and repaste the cor- rected statements to the Command Window or save the program in the Editor as an M-file and execute it.
This is called an array operation and is different from squaring the vector itself, which is a matrix operation, as we will see later.
You might want to save the program under a helpful name, like throw. This way, the plan reminds you what the program does when you look at it again after some months. After you block selected text, right-click to see the context menu. To comment the text, scroll down to Comment, point, and click.
Expressions are constructed from a variety of things, such as numbers, variables, and operators. First we need to look at numbers. For example, 1. This is also called floating-point notation. The number has two parts: The mantissa, which may have an optional decimal point 1. Mantissa and exponent must be separated by the letter e or E. The mantissa is multiplied by the power of 10 indicated by the exponent. Note that the following is not scientific notation: 1.
On computers using standard floating-point arithmetic, numbers are repre- sented to approximately 16 significant decimal digits. The relative accuracy of numbers is given by the function eps, which is defined as the distance between 1. Enter eps to see its value on your computer. As an exercise, enter the following numbers at the command prompt in scien- tific notation answers follow in parentheses : 1.
More information on data types can be found in the Help index. MATLAB also supports signed and unsigned integer types and single-precision floating-point, by means of functions such as int8, uint8, single, and the like. However, before mathematical operations can be performed on such types, they must be converted to double precision using the double function. The arithmetic operations on two scalar constants or variables are shown in Table 2. Operators operate on operands a and b in the table.
Left division seems a little curious: Divide the right operand by the left oper- and. However, matrix left division has an entirely different meaning, as we will see later. It also works perfectly with twisted curves, surfaces, volumes and graphical interpolation.
MATLAB Graphical Programming addresses all these issues by developing the following topics:This book is a reference designed to give you a simple syntax example of the commands and to graph it so that you can see the result for: Two dimensional graphicsStatisti This is one of those works.
This book is one of those rare contributions that can bear repeated study by practitioners and experts alike. It is not a treatise on the arcane or academic-rather it completes your understanding of things you think you know but will bite you sooner or later until you really learn them. He knows what you n Updated to include all the newer features through MATLAB Ra Includes new chapter on complex variables analysis Presents a comparison of execution time between compiled and un-compiled code that includes examples Describes the new H2 graphics features.
The main principle of the book is based on learning by doing and mastering by practicing. Every chapter ends with relevant drill exercises for self-testing purposes. This text provides an introduction that reveals basic structures and syntax, demonstrates the use of functions and procedures, outlines availability in various platforms, and highlights the most important elements for both programs.
Self-contained, it allows the reader to use the material whenever needed rather than follow a particular order. Compatible with both languages, the book material incorporates commands and structures that allow the reader to gain a greater awareness of MATLAB and Octave, write their own code, and implement their scripts and programs within a variety of applicable fields.
Includes brief, simple code that works in both MATLAB and Octave Provides exercise sections at the end of each chapter Introduces framed examples and discussions with a scientific twist Exercises are provided at the end of each chapter Essential MATLAB and Octave offers an introductory course in MATLAB and Octave programming and is an authoritative resource for students in physics, mathematics, statistics, engineering, and any other subjects that require the use of computers to solve numerical problems.
Employ essential and hands-on tools and functions of the MATLAB and Simulink packages, which are explained and demonstrated via interactive examples and case studies. After reading and using this book, you'll be proficient at using MATLAB and applying the source code from the book's examples as templates for your own projects in data science or engineering.
The book provides a systematic, step-by-step approach, building on concepts throughout the text, facilitating easier learning. Sections on common pitfalls and programming guidelines direct students towards best practice. There are also expanded examples on low-level file input functions, Graphical User Interfaces, and use of MATLAB Version Rb; modified and new end-of-chapter exercises; improved labeling of plots; and improved standards for variable names and documentation.
Presents programming concepts and MATLAB built-in functions side-by-side Systematic, step-by-step approach, building on concepts throughout the book, facilitating easier learning Sections on common pitfalls and programming guidelines direct students towards best practice. The book is a review of essential skills that an entry-level or experienced engineer must be able to demonstrate on a job interview and perform when hired.
It will help engineers prepare for interviews by demonstrating application of basic principles to practical problems. Hiring managers will find the book useful because it defines a common ground between the student's academic background and the company's product or technology-specific needs, thereby allowing managers to minimize their risk when making hiring decisions. Ten Essential Skills contains a series of "How to" chapters.
Each chapter realizes a goal, such as designing an active filter or designing a discrete servo. The book also. Familiarize yourself with MATLAB using this concise, practical tutorial that is focused on writing code to learn concepts. Starting from the basics, this book covers array-based computing, plotting and working with files, numerical computation formalism, and the primary concepts of approximations. Combined with Simulink, this is a de-facto industry standard for the analysis, modelling and visualising of complex systems.
This comprehensive textbook is ideal for engineers, scientists and those in the financial sector who want to grasp the essence of systems modelling and. Program design and algorithm development are. The main principle.
0コメント