8/29/2019 Matlab Toolbox Symbolic Logic
Symbolic Math in Matlab Matlab allows you to create symbolic math expressions. This is useful when you don't want to immediately compute an answer, or when you have a math 'formula' to work on but don't know how to 'process' it. Matlab allows symbolic operations several areas including:. Calculus. Linear Algebra.
Algebraic and Differential Equations. Transforms (Fourier, Laplace, etc) The key function in Matlab to create a symbolic representation of data is: sym or syms if you have multiple symbols to make. Below is an example of creating some symbolic fractions and square roots: sqrt(2) ans = 1.4142 sqrt( sym(2) ) ans = 2^(1/2) 2 / 5 ans = 0.4 2/5 + 1/3 ans = 0.7333 sym(2) / sym(5) ans = 2/5 sym(2) / sym(5) + sym(1) / sym(3) ans = 11/15 Defining Symbolic Expressions We can define symbolic functions using the sym command and syms command. Here is an example of creating a symbolic function for (a.X^2) + (b.x) + c: syms a b c x% define symbolic math variables f = sym('a.x^2 + b.x + c'); From now on we can use the f symbol to represent the given function.
Evaluation of Symbolic Expressions The keyfunction subs (which stands for substitute) is used to replace symbolic variables with either new symbolic variables or with acutal values. The syntax for the function is: subs( symbolicfunction, listofsymbols, listofvalues).
Here is an example: f = sym('a.x^2 + b.x + c'); subs(f,x,5) ans = 25. a + 5. b + c subs(f,x a b c,5 1 2 3) ans = 38 Plotting Symbolic Function In Matlab, we can plot a symbolic function over one variable by using the ezplot function. Here is an example: y = sin(x) y = sin(x) ezplot(y) If you want to see something cool, try: f = sin(x); ezsurf(f); Now try: f = sin(x); g = cos(y); ezsurf(f+g); Or really cool! ezsurf( 'real(atan(x+i.y))' ); To set the bounding values of the variables, you can use: ezplot(y-5, 10 );% from -5 ezsurf(z,1 2 5 7);% x from 1 to 2, y from 5 to 7 Or plotting a polynomial equation: f = sym('a.x^2 + b.x + c'); ezplot(subs(f,a b c,1 2 3)); Integration and Derivation Matlab can also compute many integrals and derivatives that you might find in Calculus or many advanced engineering courses.
The key functions are int for integration and diff for derivation. Differentiation syms x; f = sin(5.x) f = sin(5.x) diff(f) ans = 5.cos(5.x) 2nd Derivative To take the 2nd (or greater) derivative of an equation, we use: f = x^3 f = x^3 diff(f)% 1st derivative ans = 3.x^2 diff(f,2)% 2nd derivative ans = 6.x diff(f,3)% 3rd derivative ans = 6 diff(f,4)% 4th derivative ans = 0 Partial Differential Equations Sometimes you have multiple variables in an expression. If we want to compute the derivative of the function with respect to one variable we can use a second parameter to the diff function: syms x t; f = sin( x. t ) diff(f,t)% derivative of f with respect to t ans = cos(x.t).t Integration By using the 'int' function, in the same way we use the diff function, we can ask Matlab to do symbolic integration for us. Warning: Do not confuse the int function in Matlab with the integer (int) data type in C or the int8, int16, int32 data types in Matlab. syms x t; f = x.
x; int(f) ans = 1/3.x^3 Definite Integrals As you (should) know, a definite integral represents the area under a curve from a given start point to a given end point. What if we want to know how much area is under the curve f(x) = x^3; from 0 to 10, from -10 to 10, from -10 to 0? int(x^3,0,10) ans = 2500 int(x^3,-10,10) ans = 0 int(x^3,-10,0) ans = -2500 Summations You can use Matlab to tell you the sum of a series of equations, such as: 1 + 1/2^2 + 1/3^2 + 1/4^2 +. + 1/N^2 From N = 1 to inf (or from value1 to value2) syms x k s1 = symsum(1/k^2,1,inf) s1 = 1/6.pi^2 s2 = symsum(x^k,k,0,inf) s2 = -1/(x-1) Mathematical Limits Every wonder what happens if you divide infinity by infinity? Well depending on how those values were created, you can get some interesting results.
History Of Symbolic Logic![]() Symbolic Logic Proofs
For example, what is the limit of x/ x.x as X approaches infinity? limit( 1 / x )% with no params, by definition, as x approaches 0 ans = NaN limit(x / x^2, inf)% as x approaches inf ans = 0 limit(sin(x) / x)% as x approaches 0 ans =????
Expand Function The expand function will 'expand' a formula by doing basic symbolic math where possible. Syms x; f1 = (x+5).(x+5); f1 = (x+5)^2 expand(f1) ans = x^2+10.x+25 Simplify Function When you have a complex evaluated symbolicexpression, such as: (sin(x)^2 + cos(x)^2), you can use the simplify function to ask matlab to try and simplify it to a less complex term: simplify(sin(x)^2 + cos(x)^2) ans = 1 'Pretty' Printing Symbolic Functions When you want to print a symbolic function to make it easier for the user of the program to read, you can use the 'pretty' function.
Here is an example: f = sin(x)^2 + cos(x)^2; pretty( f ) 2 2 sin(x) + cos(x) 'Taylor' Command If you would like to create a taylor series, you can use the 'taylor' function. f = taylor(log(1+x)) f = x-1/2.x^2+1/3.x^3-1/4.x^4+1/5.x^5 Known Bad Variable Names A few years ago Matlab 'upgraded' their symbolic library. When they did so they, 'broke' the ability to use any arbitrary variable name. For example, the symbol D (capitol D) is invalid in some cases. For example: int('A.x^3+B.x^2+C.x+D') Warning: Explicit integral could not be found. Ans = int(C.x + A.x^3 + B.x^2 + D, x)% BUT syms A B C D x int(A.x^3+B.x^2+C.x+D) ans = (A.x^4)/4 + (B.x^3)/3 + (C.x^2)/2 + D.x To fix this problem, append an (underscore) to the variable The following symbols are known.
Symbolic Math Toolbox™ provides functions for solving, plotting, and manipulating symbolic math equations. You can create, run, and share symbolic math code using the MATLAB ® Live Editor. The toolbox provides functions in common mathematical areas such as calculus, linear algebra, algebraic and ordinary differential equations, equation simplification, and equation manipulation. Symbolic Math Toolbox lets you analytically perform differentiation, integration, simplification, transforms, and equation solving. You can perform dimensional computations and conversions using SI and US unit systems. Your computations can be performed either analytically or using variable-precision arithmetic, with the results displayed in mathematical typeset.
You can share your symbolic work with other MATLAB users as live scripts or convert them to HTML or PDF for publication. Bridges. You can generate MATLAB functions, Simulink ® function blocks, and Simscape™ equations directly from symbolic expressions. Learn the basics of Symbolic Math Toolbox Symbolic variables, expressions, functions, conversions between symbolic and numeric Equation solving, formula simplification, calculus, linear algebra, and more Two- and three-dimensional plots, data exploration, and visualization techniques Use symbolic results in MATLAB, Simulink, Simscape, C, Fortran, and LaTeX Perform mathematics using symbolic computation and variable-precision arithmetic in MuPAD ® Access MuPAD functionality from MATLAB.
Symbolic Math Toolbox™ provides functions for solving, plotting, and manipulating symbolic math equations. You can create, run, and share symbolic math code using the MATLAB ® Live Editor.
The toolbox provides functions in common mathematical areas such as calculus, linear algebra, algebraic and ordinary differential equations, equation simplification, and equation manipulation. Symbolic Math Toolbox lets you analytically perform differentiation, integration, simplification, transforms, and equation solving. You can perform dimensional computations and conversions using SI and US unit systems. Your computations can be performed either analytically or using variable-precision arithmetic, with the results displayed in mathematical typeset.
You can share your symbolic work with other MATLAB users as live scripts or convert them to HTML or PDF for publication. You can generate MATLAB functions, Simulink ® function blocks, and Simscape™ equations directly from symbolic expressions.
First, the expression so that the exponents are separated then do the substitution. By default, when writing out an expression for the first time (before running it through any functions), MATLAB will try and simplify your expression and so exp(a).exp(b) can be much better expressed using exp(a+b). This is why your substitution had no effect.
However, if you explicitly want to replace a part of the expression that is encompassed by an exponent with a base, expand the function first, then do your substitution: syms a b A; X = exp(a+b); Xexpand = expand(X) Xexpand = exp(a).exp(b) Y = subs(Xexpand, exp(a), A) Y = A.exp(b).
. syms is a shortcut for sym. This shortcut lets you create several symbolic variables in one function call. Alternatively, you can use sym and create each variable separately.
You also can use symfun to create symbolic functions. In functions and scripts, do not use syms to create symbolic variables with the same names as MATLAB functions. For these names MATLAB does not create symbolic variables, but keeps the names assigned to the functions. If you want to create a symbolic variable with the same name as a MATLAB function inside a function or a script, use.
For example, use alpha = sym('alpha'). The following variable names are invalid with syms: integer, real, rational, positive, and clear. To create variables with these names, use sym. For example, real = sym('real').
clear x does not clear the symbolic object of its assumptions, such as real, positive, or any assumptions set by assume, sym, or syms. Selamat hari raya font. To remove assumptions, use one of these options.
Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |