MATLAB BOOK PDF
Attribution. MATLAB® and Handle Graphics® are registered trademarks Dedication. This book is dedicated to my two mentors at Boston University: the late. MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, and xPC TargetBox are registered trademarks of The MathWorks, Inc. Other product or. This book is dedicated to my two mentors at Boston University: the late. Bill Henneman of the Computer Science Department, and the late Merrill Ebner.
|Language:||English, Spanish, French|
|Genre:||Business & Career|
|ePub File Size:||18.32 MB|
|PDF File Size:||11.39 MB|
|Distribution:||Free* [*Regsitration Required]|
INTRODUCTION TO MATLAB FOR. ENGINEERING STUDENTS. David Houcque . Northwestern University. (version , August ). PDF Drive is your search engine for PDF files. As of today we have 78,, eBooks for you to download for free. No annoying ads, no download limits, enjoy . This book is printed on acid-free paper containing 10% postconsumer waste. Introduction to MATLAB for engineers / William J. Palm III.
Click on View on the tool bar. Save it. A convenient arrangement of the desktop Run the sample script below three times using these values of h: Sample Script clear. As you run it look at the values of the variables h. The syntax and the commands used in this script are unfamiliar to you now. You will have lots of chances to practice debugging this way as you work through the examples in this book.
Now you can click on the Debug icon on the tool bar to see what to do next. When you write a script to solve some new problem. Look at the workspace window and note that h has been given a value. Make this happen by pressing F5 and watching the green arrow appear on the line with the breakpoint.
Take a minute now and use F10 to step through the script while watching what happens in the other windows. When the red dot is there it means that a breakpoint has been set. To see what a breakpoint does. It is very helpful in this debugging process to watch what the script does as it runs. This is because the breakpoint stops execution just before the line on which it is set. In both languages variables are not declared.
Note that variable names in Matlab are case sensitive. When you display numbers to the screen. If you want to see them all type format long e The four most useful formats to set are format format format format short the default long long e short e Note: This is not true. Matlab has just three: Do it this way: When matrices become large the.
For instance. It should come as no surprise that the Mat in Matlab stands for matrix. A more visual way to type large matrices in a script is to use spaces in place of the commas and to press the Enter key at the end of each row in place of the semicolons. Make sure you enclose them in single quotes. And if you have a matrix or an array and you want to access the last element in a row or column.
If you want to know more about how to handle strings type help strings. When you want to access the elements of a matrix you use the syntax A row. If you enter a matrix. When I converted the code to Matlab it took 15 seconds. Chapter 3 Input. Scott Bergeson. If you enter an array. When we start plotting and doing real calculations this will all become clear. Sometimes we want to take two big arrays of numbers and multiply their corresponding elements together.
Matlab also allows the operations. Be patient. So if A is a 3x3 matrix and B is another 3x3 matrix.
MATLAB Machine Learning
Because we do this so often you will see many examples later on Matlab has a special symbol for this kind of multiplication: Because everything in Matlab is a matrix. And since we might also want to divide two big arrays this way.
And if you want to raise A to a power by multiplying it by itself n times. You are probably confused about this dot business right now. As long as A and B are two variables of the same size e. If you accidentally do it the command clear i will restore it to its imaginary luster.
It can do Bessel functions of complex arguments too. Or perhaps we need to know the angle between the real axis and the complex number in the complex plane.
By using i you can do complex arithmetic.
Matlab Tutorial Books
Matlab knows it too. This means. Notice that the natural log function ln x is the Matlab function log x. I will give you a list below of a bunch of them. Example 3. The format 6.
About this book
For full information type help fprintf but to get you started. To display printed results you can use the fprintf command. Try them so you know what each one produces. Type cd to see where you are. Both of these arrays are the same length. And if you leave the middle number out of this colon construction. Check it out with help linspace. These arrays are easily built with the colon: Command Simple plots of y vs.
Chapter 4 Arrays and x-y Plotting 4. Both kinds of grids are used in computational physics. If you do make this mistake and the screen print is going to take forever. You should use the colon command whenever possible because it is a pre-compiled Matlab command.
Tests show that using: A cell-center grid is one that has N subintervals. To see what the possibilities are type help plot.
The colon and end commands can help: You can then use this string variable as the argument of the commands xlabel. Other colors are also possible. The 'r-' option string tells the plot command to plot the curve in red connecting the dots with a continuous line.
Example 4. See online help for more details. This might be a useful thing to use in a script. There are two ways you can do this. To do so. Curves in 3-D Space Matlab will draw three-dimensional curves in space with the plot3 command. They work like this. Here is how you would do a spiral on the surface of a sphere using spherical coordinates. To release it use the command hold off as shown in the example above. You can override this choice by specifying your own axes.
And if the subscript is more than one character long do this: See the section at the end of this booklet titled Plots for Publication by Tom Jenkins.
See a book on LaTex for details. To print Greek letters just type their names preceded by a backslash. You can use LaTex Greek here too. To put a subscript on a character use the underscore character on the keyboard: If you want to change the look of anything on your plot.. This will take care of simple plots. Note the use of.
Example 5. Chapter 5 Surface. In this subsection we will try to understand how Matlab goes from one-dimensional arrays x and y to two-dimensional matrices X and Y using the commands meshgrid and ndgrid. The command [X. As you can see. Because we think this way it would be nice if the matrix indices worked this way too. But exactly how Matlab did it is tricky. To understand how meshgrid turns one-dimensional arrays x and y into two-dimensional matrices X and Y. Look at them until you are convinced that meshgrid has turned your one-dimensional arrays x i and y j into their two-dimensional versions X j.
To see that this is how the example above worked for you. But in physics we usually think of two-dimensional functions of x and y in the form F x.
Stare at the matrices above and discuss them with your lab partner until you are convinced that this is true. F discussed below will look the same. No matter which command you use. Matlab has another command called ndgrid which is similar to meshgrid but does the conversion to two dimensions the other way round.
F or contour X. Try it until you get the hang of it. Another good source is Mastering Matlab 6. To make this surface oscillate up and down like a manta ray you could do this. Chapters The electrostatic potential is given by V x. The tube has width 2b in x and width a in y. See Introduction to Electrodynamics. V xlabel 'x'. Clicking on the zoom-out icon.
Chapter 6 Vector Products. Dot and Cross Matlab will do dot and cross products for you with the commands dot and cross. Linear Algebra Almost anything you learned about in your linear algebra class Matlab has a command to do. Here is a brief summary of the most useful ones for physics. The commands max and min return the maximum and minimum values of an array. And with a slight change of syntax they will also return the indices in the array at which the maximum and minimum occur.
Example 7. The inv command will compute the inverse of a square matrix. Notice that if a is a row vector then a' is a column vector.
You will use the transpose operator to switch between row and column vectors a lot in Matlab, like this [1,2,3] [1,2,3]' [4;5;6] [4;5;6]'. Matlab will let you load several special matrices. The most useful of these are given here. To load a row vector c with the contents of the second row of the matrix A use: To load a column vector b with the contents of the third column of the matrix A use: LU factorization.
You can also select just part of row or column like this: To learn about these ideas. QR factorization. To learn how they are used in Matlab use the commands.
And the commands rcond and cond will give you the condition number of a matrix. Try each piece of code in Matlab and see what it does. Chapter 8 Polynomials Polynomials are used so commonly in computation that Matlab has special commands to deal with them.
Here are some of the things Matlab can do with polynomials. Matlab can do it with the command deconv.
Before going on to the next section. Example 8. It is so important to know how to write them that several common examples of how they are used will be given here. Example 9. Chapter 9 Loops and Logic To use Matlab to solve many physics problems you have to know how to write loops and how to use logic.
Here are a few examples of how the for loop can be used. The for loop looks like this: The two kinds of loops we will use are the for loop and the while loop.
Look it up in online help. To do timing checks use the cputime command. On my Unix workstation the: The simplest logic command is the if command. This will make your code easier to read and you will make fewer mistakes. Several examples are given. The break command is designed to do this. It is also important to make sure that the variable you are testing term in this case is loaded before the loop starts with a value that allows the test to take place and for the loop to run term must pass the while test.
Note that unlike the for loop. When break is executed in a loop the script jumps to just after the end at the bottom of the loop. Here is our sum loop rewritten with break Example 9. You can follow what is happening here by looking at Fig.
You can draw your own line and see that the value of x5 obtained from the line between x3. The sequence of approximate points in the secant method.
And then you do it again. This will be a better approximation to the solution than either of your two initial guesses. Here is the Matlab code that uses fzero and fz to do the solve: You just need to build it.
As an example of what a good job centering does. To see the importance of centering. This is a little complicated. But until you do. The centered derivative approximation works best.
Notice that the data must be evenly spaced for the example I am going to give you to work. This method is shown in Fig. Matlab has its own routines for doing derivatives. We replace f x dx by f xj h and sum over all the subintervals to obtain an approximate integral. The idea of the midpoint method is to b approximate the integral a f x dx by subdividing the interval [a. Notice that this method should work pretty well over subintervals like [1.
A function that does this for you is given in Chapter Example The midpoint rule works OK if the function is nearly straight across each interval. And to see how accurate your answer is.. As an example. As you can see from Fig. As an example of what these routines can do. These will be discussed more fully in Chapter Matlab will do this integral with arrays of x.
Chapter The quadl integration command used in the example above uses higher order polynomials to do the integration and is the best Matlab integrator to use. Matlab also has a command dblquad that does double integrals. But you must be careful when using this method that your points are close enough together to give good values. This linear formula can also be used to extrapolate. Both linear and quadratic function approximations will be discussed here.
Finding function values between data points in the array is called interpolation. In Fig. The Lagrange interpolation formulas. Consider Fig. I want to do it this way because it uses the approximate derivative formulas we used in Sec.
Linear interpolation only works well over intervals where the function is straight. The grid spacing in x is h. You must be careful here as well: You can use online help to nd details about how to use them. Notice that the natural log function ln x is the Matlab function log x.
From now on it will prepare you better for the more dicult material coming up if you have both a command window and an M-le window open. Put the examples to be run in the M-le call it junk. To display printed results you can use the fprintf command.
For full information type help fprintf but to get you started, here are some examples. Try them so you know what each one produces. A g means use whatever format; if the number is really big or really small, use scientic notation, otherwise just throw 6 signicant gures on the screen in a format that looks good. The format 6. An e means scientic notation, with the number of decimal places controlled like this: 1. If you want all the details on this stu, look in a C-manual or Chapter 10 of Mastering Matlab 6.
This command will also write output to a le. Here is an example from online help that writes a le lled with a table of values of x and exp x from 0 to 1. Note: the example in the box below is available on the Physics course website, as are all of the examples labeled in this way in this booklet.
Example 3. Type cd to see where you are. Chapter 4 Arrays and x-y Plotting 4. These arrays are easily built with the colon : command. If you do make this mistake and the screen print is going to take forever, ctrl-c will rescue you. An array like this that starts at the beginning of an interval and nishes at the end of it is called a cell-edge grid. Note: Matlabs linspace command also makes cell-edge grids. Check it out with help linspace. You should use the colon command whenever possible because it is a pre-compiled Matlab command.
Tests show that using : is about 20 times faster than using a loop that you write yourself discussed in Chapter 9. Other colors are also possible, and instead of connecting the dots you can plot symbols at the points with various line styles between the points. To see what the possibilities are type help plot. And what if you want to plot either the rst or second half of the x and y arrays? This might be a useful thing to use in a script. See online help for more details.
There are two ways you can do this. Example 4. To release it use the command hold off as shown in the example above. Here is how you would do a spiral on the surface of a sphere using spherical coordinates. They work like this. You can override this choice by specifying your own axes, like this.
See a book on LaTex for details. To write on your plot you can just click the button labelled A on the gure tool bar, then click in the gure window where you want the text to appear and type the text. You can use LaTex Greek here too. Or, you can use Matlabs text command in the format: text 10,.
If you want to change the look of anything on your plot, like the font style or size of text, the width of the lines, the font style and size of the axis labels, etc. This will take care of simple plots, but if you want to make publication quality gures you will have to work harder. See the section at the end of this booklet titled Plots for Publication by Tom Jenkins.
Start by dening arrays x and y that span the region that you want to plot, then create the function F x, y over the plane, and nally either use contour, surf, or mesh. In this subsection we will try to understand how Matlab goes from one-dimensional arrays x and y to two-dimensional matrices X and Y using the commands meshgrid and ndgrid.
Lets begin by executing the following example. Example 5. Note the use of. But exactly how Matlab did it is tricky, so pay close attention. To understand how meshgrid turns one-dimensional arrays x and y into two-dimensional matrices X and Y , consider the following simple example.
As you can see, the rst index of both X and Y is a y -index since there are only 2 entries, as in y. X 1, 1 and X 2, 1 are both 1 because as the y -index changes, x stays the same. To see that this is how the example above worked for you, make sure your Workspace window is open, then click on X and Y to view them with the Array Editor. Look at them until you are convinced that meshgrid has turned your one-dimensional arrays x i and y j into their two-dimensional versions X j,i and Y j,i.
But in physics we usually think of two-dimensional functions of x and y in the form F x, y , i. Stare at the matrices above and discuss them with your lab partner until you are convinced that this is true. No matter which command you use, plots made either with surf X,Y,F or contour X,Y,F discussed below will look the same, but the F i, j order is a more natural t to the way we usually to two-dimensional physics problems, so I suggest you use ndgrid most of the time.
Download, or type, the following example, read through it and watch what it does. Try it until you get the hang of it. Heres a piece of code that lets you y around the surface plot by continually changing the viewing angles and using the pause command; I think youll be impressed Example 5. To make this surface oscillate up and down like a manta ray you could do this.
Another good source is Mastering Matlab 6, Chapters When matrices become large the. There are two ways you can do this. Trial software. The simplest logic command is the if command. Quanser has a DC motor control kit with a user manual that lists at least 6—7 experi-ments1. Dabney, Thomas L. The spacing between the lines is a lot and there are a lot of figures and white spaces.
Command Simple plots of y vs.
- PRACTICAL COMPILER CONSTRUCTION PDF
- LAWS OF SPIRIT WORLD EBOOK
- FIBER OPTIC COMMUNICATIONS PALAIS PDF
- GATE 2013 STUDY MATERIAL FOR CSE PDF
- START DAY TRADING NOW PDF
- POSITIVE INTELLIGENCE PDF
- RAS STUDY MATERIAL IN HINDI PDF
- DAG HEWARD MILLS PDF
- 127 HOURS BOOK PDF
- THE FOURTH INDUSTRIAL REVOLUTION PDF
- FOUNDATIONS OF CLINICAL RESEARCH APPLICATIONS TO PRACTICE PDF