0% found this document useful (0 votes)
62 views6 pages

Class 7

Uploaded by

lucy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
62 views6 pages

Class 7

Uploaded by

lucy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 6
Solving Linear Systems Suppose A is a nonsingular n x n matri: ‘Then typing x» A\b numerically computes the wnii Type help mldivide for more information. ‘Ifeither A or b is symbolic rather than numeric, the solution to a"x = b symbolically. To calculate a s; both inputs are numeric, type x = sym(A)\b. CLASs -1 Calculating Eigenvalues end Eigenvectors The eigenvalues of a s eig(a) calculates both the eig mand (0, RJ The eigenvalues are the diagonal elements of the columns of U are the eigenvectors. Here is an example illus! eig: b> A= [3 -2 0; 2 -2 07 O11; >> eig (A) ans = 1 -1 2 >> (U, RI = U= ° 0 1.0000 or et gla) ~0.4082 -0.9165 0.4082 Neo 0.9165 -C.4082 -C.4082 x and b is a column vector of length 2. que solution ton*x = then x = A\b computes ymbolic solution when \quare matrix A are calculated with eig (A). The com- envalues and eigenvectors. diagonal matrix R, and the trating the use of 2 on Slernvector in the first column of U corresponds to the eigenvalue as ae ee of R, and so on. These are numerical values for the pairs. To get symbolically calculated eigenpairs, type [U, R] eig(sym(a)). Doing Calculus with MATLAB i sic caleulus FE Dmss has commands for most of the computations ot te ocean Toolbox. This toolbox includes part of a sep: nits Symbolic Math Dp r oried Maple, which processes the symbolic calculations. Differentiation You can use di ££ to differentiate symbolic exp? mate the derivative of a function given numeric: ressions, and also to approxi- ally (say by an M-file): >> syms x; diff (x3) ans ~ 3*x*2 Here MATLAB has figured out that the variable is x. (See Defauli Variabies at the end of the chapter.) Alternatively. >> £ = inline(’x73’, 'x’); diff(£(x)) ans = 3x2 The syntax for second derivatives is diff (£(x), 2), and for nth derivatives, diff (fix), n). The command difé can also compute partial derivatives of expressions involving several variables, as in aiff (x“2*y, y), but todo multiple partials with respect to mixed variables you must use diz£ repeat- Pedly, as in diff (diff (sin(x*y/z), x), y)- (Remember to declare y and -z-symbolic.) ~~ Peat There is une instance where differentiation must be represented by the Jetter_D, namely when you necd to specify a differential equation as input to a command. For example, to use the symbolic ODE sclver on the differential equation xy’ +1 = y, you enter dgolve(’x*Dy + 1 = y's ‘x‘) 62 Chapter 4: Beyond the Basics Integration > MATLAB can compute definite and indefinite integrals. Here is an indefinite, integral: p> int (7x72", 184) ans ~ 1/3*x*3 As with diff, you can declare x to be symbolic and dispense with the chur- acter string quotes. Note that MATLAB does not include a constant of inte- gration; the output is a single antiderivative of the integrand. Now here is a definite integral: >> syms x; int(asin(x), 0, 4) ana = 1/2*pi-2 You are undoubtedly aware that not every function that appears in caleu- Jus can be symbolically integrated, and so numerical integration is sometimes necessary. MATLAB has three commands for numerical integration of a func- tion f(2): quad, quad8, and quadl (the, latter is new in MATLAB 6). We recommend quadl, with quad8 as a second choice. Here’s an example: >> syms x; int(exp(-x74). 0, 1) Warning: Explicit integral could not be found. > In /data/mat labr12/toolbex/symbolic/@sym/int .m at line 58 ans = int (exp (+x*4),x = 0 .- 1) >> quadl (vectorize(exp(-x°4)), 0, 4) ans = 0.6448 quad quad8 quadl Inf -Inf int very large Doing Calculus with MATLAB another option. If you type doub2e (int ( )), th gration routine wi Maple’s I evaluate the integral — even over an numer fe range. MATLAB can algo do multiple integrals. The following command compuces MATLAB can 2 the double ii tegral fel “oe? + dy dx: lo Jo >> syms x Y? int (int (x*2 + yh. y, 0, sin(x)), 0, pi) ane = pi*2-32/3 Note that MATLAB presumes that the variable of integration in int is x unless you prescribe otherwise. Note also that the order of integration is as in caloulvs, from the “inside out”. Finally, we observe that there is 2 numerical doubie integral command dbiguad, whose properties and use you to discover from the online help. wl allow Limits You can use limit to compute right- and left-handed limits and limits at infinity. For example, here is lim sin(x)/x: = >> syms x; limit(sin(x)/x, x, 0) ans = 1 To compute one-sided limits, use the ‘right’ and ‘left’ options. For exam- ple, >> limit (abs{x)/x, x, 0, ‘left’) ans = i “1 Limits at infinity can be computed using the symbol Int: b> Limit (x74 4 x72 = 3)/(34x74 - Log(x)), x, Taf) ans = 1/3 64 Chapter 4: Beyond the Basics Sums and Products Finite Numerical sums and Products ce; capabilities of MATLAB an n and prod. For example. >> X= a7; >> pum (x) ana = 28 >> prod (x) ana = 5040 ‘You can do finite and infinite symbolic sums using the command symoun, To illustrate, here is the telescoping sum EG-th): >> syms k a; symsum(1/k - 1/{k +1), 1, 2} ans = -2/(n=1) +1 * And here is the well-known iafinite sum . en 1 De >> symsum(1/n*2, 1, Inf) ans = 1/6*Di~z : / f the infinite gt ic series: Another familiar example is the sum of the infinite geometric other f , >> gyms a ke symsum{a"k, 0, Inf) ans = -1/(a-+) i i jal < 1 Note, however, that the answer is only valid for |al EXERCISE CLASS-7 I m of linear equations 2 (array +Sz=2 x-dy+7z2=8 (xtytz 1 foe ayaae 1 | sea y 22 =6 fevers 8, x-6y +z 7x — By + 262 = 31 at y+2e=9 tytn ax+3y +259 (xty tz frvarea vo, frceay't 3 6, fend et xtay+4z=22 (ax+y+2z=8 lxty42 x4 2y 432 2x + 3yt4z 7x + 13y +9 2. Solve following integral (Ecos (x) abe, fF e% de, ft POU? + y? 2 L aoe SG IE xydxdy, fiesta Sxe* “dx, Jf (Bx? + 2)/(3 + 2x + 5) dx 3. kind 3" order derivative of following functions x4 5x3 + 2x + 3, sin(3x). sin(3x? + 2),e°* + sin(2x), e3*?, xe* e* sin(2x) ,sin(xy?) with respect to y, e7*%? with respect Coz 4. Find value of following by using Matlab dy, f xsin(x*)dx, frxe*dx, wes xt4x?-3 S 1 Mn+ ide i 2e-*, li , sin(=) lima, lity eo ES, + liMpaeg X77*, UM SiN) limy0~ en) ibe + “cos(x))/ Gt i" 1) 3. Attempt all problems 'A. find rank, determinant value, eigen value and eigen vector of following 9 0} matrices > yl 2 3 10 2 ot 2 am [ 3 ‘} 1 z)[3 3 1 o,f 1 a) oa} 10-1 Re e 4) 13 -1 1jlo 1 0 1 0-2 yfl -1 -1))3 -1 * [ 2 i}. ° 0 U3 3 i =i oe 3 * ZnS: -1 12 22u 0 - o 0 5 B. Find Taylor Polynomial (af indicated order nat the point c of following = functions fl) =e n= 7,c = 0; f(x) =sin(z). n= 7.¢ f(x) = sin(x),n 6c = 0,f{x) = =tan(x) n=7,c=0 ressions -C. Using simplify or simple to snl the following exp! ,cos?(x) — sin’(x), 1/1 + a . Compute up to 30 digits by using Matlab; cosh(0.1), sin(i) V7,V2.¢,e", log3, tog 7.

You might also like