Monday, December 9, 2019

Symbolic Processing free essay sample

Symbolic processing is the most powerful feature of matlab. We can solve even most complex equations very easily in matlab that are very difficult to solve by hand. Matlab performs symbolic processing to obtain answers in the form of expressions. Symbolic processing is the term used to describe how a computer performs operations on mathematical expressions. To improve engineering designs by modeling it with mathematical expressions that do not have specific parameter values are very difficult to solve by hand on paper but matlab performs these tasks very easily through symbolic processing symbolic processing is used for solving algebraic and transcendental equations, for solving ordinary differential equations and for symbolic calculus including integration, differentiation, limits and series. Symbolic expressions and algebra: The â€Å"sym† function can be used to create a â€Å"symbolic objects† in MATLAB. If the input argument to sym is a string, the result is a symbolic number or variable. If the input argument is a numeric, scalar or matrix, the resulting is a symbolic representation of the given numeric values. For example, typing x=sym (‘x’) creates the symbolic variable with name x, and typing y=sym(‘y’) creates a symbolic variable named y. typing x=sym(‘x’,’real’) tells MATLAB to assume that x is real. Typing x=sym(‘x’,’unreal’) tells MATLAB to assume that x is not real. The â€Å"syms† function enables you to combine more than one such statement into a single statement. For example typing syms x is equivalent to typing x=sym(‘x’), and typing syms x y u v creates the four symbolic variables x, y, u and v. when used without arguments, syms lists the symbolic objects in the work space. The syms command, however, cannot be used to create symbolic constants. The syms command enables you to specify that certain variables are real. For example, syms x y real Manipulating expressions: The following functions can be used to manipulate expressions by collecting coefficients of like powers, expanding powers, and factoring expressions, for example. The function collect (E) collects coefficients of like powers in the expression E. if there is more than one variable, you can see the optional form collect(E,v), which collects all the coefficients with the same power of v. syms x y E = ( x 5 ) ^ 2 + ( y 3 ) ^ 2; collect ( E ) ans= x ^ 2 – 10 * x + 25 + ( y – 3 ) ^ 2 collect ( E , y ) ans= ^ 2 – 6 * y + ( x – 5 ) ^ 2 + 9 the function simplify (E) simplifies the expression E. For example, syms x y simplify ( x * sqrt ( x ^ sqrt ( x ^ 8 * y ^ 2 )) ans= x * ( x ^ 8 * y ^ 2 ) ^ ( 1 / 2 ) The operators +, -, *, / and ^ can be used with symbolic expressions to obtain new expressions. This is shown below. syms x y E1 = x ^ 2 + 5 ; % define two expressions E2 = y ^ 3 – 2 ; S1 = E1 + E2 % add the expressions S1 = x ^ 2 + 3 + y ^ 3 gt; E3 = x ^ 3 + 2 * x ^ 2 + 5 * x + 10 ; % define the third expression S3 = E3 / E1 S3 = ( x ^ 2 + 2 * x ^ 2 + 5 * x + 10 ) / ( x^ 2 + 5 ) simplify ( S3 ) ans= x + 2 The function â€Å"subs(E, old, new) substitutes â€Å"new† for â€Å"old† in the expression â€Å"E†, where old can be a symbolic variable or expression and new can be a symbolic variable, expression, or matrix, or a numeric value or matrix. For example, syms x y E = x ^ 2 + 6 * x + 7 ; F = subs ( E, x, y ) F = Y ^ 2 + 6 * y + 7 Another example is shown below to perform multiple substitutions. For example, to substitute a = x and b = 2 into the expression E = a sin b, the session is syms a b x E = a * sin ( b ) ; F = subs ( E, { a, b }, { x, 2 } ) F = x * sin (2) The function â€Å"double (E)† converts the expression E to numeric form. The expression E must not contain any symbolic variables. The term â€Å"double† stands for floating point, double precision. For example, sqroot2 = sym ( ‘ sqrt ( 2 ) ‘ ) ; yy = 6 * sqroot2 y = 6 * 2 ^ ( 1 / 2 ) = double ( y ) z = 8. 4853 Algebraic and transcendental equations: The symbolic math toolbox can solve algebraic and transcendental equations, as well as system of such equations. There are three ways to use the â€Å"solve† function. For example, to solve the equation x + 5 = 0 , one way is eq1 = ‘ x + 5 = 0 ’ ; solve ( eq1 ) ans = -5 The second way is solve ( ‘ x + 5 = 0 ‘ ) ans = -5 The third way is syms x s olve ( x + 5 ) ans = -5 Solutions can be saved as vectors by using the form [ x, y ] = solve ( eq1, eq2 ). Note the difference in the output formats in the following example: eq1 = ‘ 6 * x + 2 * y = 14 ’ ; eq2 = ‘ 3 * x + 7 * y = 31 ’ ; solve ( eq1, eq2 ) ans = x : [ 11 sym] y : [ 11 sym] x = ans. x x = 1 y = ans. y y = 4 [ x, y ] = solve ( eq1, eq2 ) x = 1 y = 4 The solution can be saved in a structure with named fields. The individual solutions are saved in the fields. For example, continue the preceding section as follows: s = solve ( eq1, eq2 ) s = x : [ 11 sym] : [ 11 sym] S. x ans = 1 S. y ans = 4 All the equations can be simultaneously solved in by writing all in the one command of solve as shown below. syms x y b s = solve ( ( x – 3 ) ^ 2 + ( y – 5 ) ^ 2 – 4 , ( x – 5 ) ^ 2 + ( y – 3 ) ^ 2 – b ^ 2 ) s = x : [ 21 sym] y : [ 21 sym] % note that the result x : [ 21 sym] indicates that there are two solutions for x. similarly there are two solutions for y. S. x ans = [9/2–1/8*b^2+1/8*(-16+24*b^2-b^4)^(1/2)] [9/ 2–1/8*b^2-1/8*(-16+24*b^2-b^4)^(1/2)] Equations can also be solved for theta values in degrees or radians by writing the equations in the way as shown in the following example in which the values of theta 1 and theta 2 in certain equations are find out: s = solve ( ‘ 4 * cos ( th1 ) + 3 * cos ( th1 + th2 ) = 6 ‘ , . . . ‘ 4 * sin ( th1 ) + 3 * sin ( th1 + th2 ) = 2 ‘ ) s = th1 : [ 21 sym] th2 : [ 21 sym] double ( s. th1 ) * ( 180 / pi ) % converts from radians to degrees ans = -3. 2981 40. 1680 double ( s. th2 ) * ( 180 / pi ) % converts from radians to degrees ans = 51. 3178 -51. 3178

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.