MATLAB Demystified phần 1 pps

34 193 0
MATLAB Demystified phần 1 pps

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

[...]... 0 .10 00 0.2000 0.3000 0.7000 0.8000 0.9000 0.4000 0.5000 Column 11 1. 0000 The set of x values can be used to create a list of points representing the values of some given function For example, suppose that y = ex Then we have: >> y = exp(x) y = Columns 1 through 10 1. 0000 1. 1052 1. 2 214 1. 82 21 2. 013 8 2.2255 1. 3499 1. 4 918 2.4596 1. 6487 Column 11 2. 718 3 Or we could have y = x2 : >> y = x^2 y = Columns 1. .. currently in memory, their type, how much memory is allocated to each variable, and whether or not they are complex (see below) In our case we have >> whos Name Size V a ans r s t x y z 1x1 1x1 1x1 1x1 1x1 1x1 1x1 1x1 1x1 Bytes 8 8 16 8 8 8 8 8 8 Class double double double double double double double double double array array array (complex) array array array array array array Grand total is 9 elements using... cases MATLAB determines the increment in order to have the correct number of elements MATLAB also allows you to create a row vector of n logarithmically spaced elements by typing logspace(a,b,n) a b This creates n regularly spaced elements between 10 and 10 For example: >> logspace (1, 2,5) ans = 10 .0000 17 .7828 31. 6228 56.23 41 100.0000 0.6 310 1. 5849 3.9 811 Or another example: >> logspace( 1, 1,6) ans... * (temps - 32) CelsiusTemps = 0 10 .0000 18 .3333 21. 111 1 29.4444 Later, we will investigate programming in MATLAB and we will show you how to create functions that can be called later in the command window 14 MATLAB Demystified Ending Your MATLAB Session OK we have gotten started with a few very basic MATLAB commands You might want to save your work and then shut down MATLAB How do you get it off your... 2.4596 1. 6487 Column 11 2. 718 3 Or we could have y = x2 : >> y = x^2 y = Columns 1 through 10 0 0.3600 0. 010 0 0.0400 0.0900 0.4900 0.6400 0. 810 0 Column 11 1. 0000 0 .16 00 0.2500 MATLAB Demystified 20 An aside—note that when squaring a vector in MATLAB, a period must precede the power operator (^) If we just enter >> y = x^2, MATLAB gives us an error message: ??? Error using ==> mpower Matrix must be square Returning... function That is, e ≈ 2. 718 We can reference e in MATLAB by typing exp(a) which gives us the value of ea Here are a few quick examples >> exp (1) ans = 2. 718 3 >> exp(2) ans = 7.38 91 To find the square root of a number, we type sqrt For example >> x = sqrt(9) x = 3 >> y = sqrt (11 ) y = 3. 316 6 To find the natural log of a number x, type log(x) >> log(3.2) ans = 1. 1632 >> x = 5; log(5) ans = 1. 6094 If you want... + 11 /16 + 2 ^1. 2 x = 5.98489670999407 >> format short >> x = 3 + 11 /16 + 2 ^1. 2 x = 5.9849 Comparing the long and short formats, notice that the fourth decimal place was rounded up to nine when format short was used If you want to do financial calculations, you can use the format bank command As expected, this rounds everything off to two decimal places >> format bank >> hourly = 35.55 CHAPTER 1 The MATLAB. .. together: >> A = [1; 4; 5]; >> B = [2; 3; 3]; >> C = A + B C = 3 7 8 Now let’s subtract one row vector from another: >> W = [3,0,3]; >> X = [2 ,1, 1]; >> Y = W – X Y = 1 1 2 MATLAB Demystified 18 Creating Larger Vectors from Existing Variables MATLAB allows you to append vectors together to create new ones Let u and v be two column vectors with m and n elements respectively that we have created in MATLAB We... is done by writing w = [u; v] For example: >> A = [1; 4; 5]; >> B = [2; 3; 3]; >> D = [A;B] D = 1 4 5 2 3 3 This can also be done using row vectors To create a row vector u with m + n elements from a vector r with m elements and a vector s with n elements, we write u = [r, s] For example: >> R = [12 , 11 , 9] >> S = [1, 4]; >> T = [R, S] T = 12 11 9 1 4 Creating Vectors with Uniformly Spaced Elements... it off your screen? Well you can end your MATLAB session by selecting exit from the File pull-down menu, just like you would with any other program Optionally, you can type quit in the command window and MATLAB will close Quiz Use MATLAB to calculate the following quantities: 11 14 8 2 5 + 37 3 1 5 3 91. 25 4 True or False If y has not been assigned a value, MATLAB will allow you to define the equation . Class V 1x1 8 double array a 1x1 8 double array ans 1x1 16 double array (complex) r 1x1 8 double array s 1x1 8 double array t 1x1 8 double array x 1x1 8 double array y 1x1 8 double array z 1x1 8. 98 Basic Statistics 10 3 Writing Functions in MATLAB 10 6 Programming with For Loops 11 0 Calculating Standard Deviation and Median 11 0 More MATLAB Programming Tips 11 6 Quiz 11 9 Contents vii CHAPTER. Symbolic Tools 12 1 Solving Basic Algebraic Equations 12 1 Solving Quadratic Equations 12 3 Plotting Symbolic Equations 12 5 Solving Higher Order Equations 13 0 Systems of Equations 13 4 Expanding and

Ngày đăng: 12/08/2014, 21:20

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan