Applications of Symbolic computation in MATLAB - CiteSeerX

14 downloads 392382 Views 552KB Size Report
Franklin Math. 9. FriCAS. 10. GAP e.t.c. Also there are more than 30 commercial SCT tools, such as ... Toolbox, whose notebook interface provides access to the.
International Journal of Computer Applications (0975 – 8887) Volume 41– No.8, March 2012

Applications of Symbolic computation in MATLAB Zhaparov Meirambek Kazimovich Suleyman Demirel University Almaty, Kazakhstan

ABSTRACT This paper contains brief information about symbolic computation techniques. The location of symbolic computation within Computer Language classification is defined. MATLAB + MuPAD as combined method have been introduced. After some introductory information about MuPAD, some important applications of MATLAB + MuPAD are given. The method, transfer from MuPAD into MATLAB has been discussed as well. These two methods have been illustrated to engineering students on selected topics.

General Terms Programming languages, symbolic computation, logical programming, functional programming

Keywords Symbolic computation, MATLAB, MuPAD

1. INTRODUCTION Symbolic computation deals with mathematical computations on numbers, symbols, expressions, and formulas, in an exact manner, as opposed to numeric computation that deals only with floating-point numbers (and therefore approximations). Typical operations include symbolic differentiation, integration, polynomial etc… Symbolic computation is more exact generic solution compared to numeric solutions, which are more approximate solutions. In some cases, symbolic computation methods need long time and resources to solve problems. Numerical computation methods are usually much faster. Some problems can be better solved using symbolical way, while other can be solved better in a numerical way. Symbolic and numeric computation methods can be combined to solve problems.

Selim Guvercin Suleyman Demirel University Almaty, Kazakhstan

In Computer Science there exist many programming languages, which are used for numerical applications as solution to problems. General classification of programming languages is illustrated in Figure 1. Symbolic computation techniques (SCT) are created from knowledge logical and functional programming techniques. Some examples of SCT open-source, cost free tools are given in the following list: 1. Axiom 2. Bergmann 3. Calc 4. CoCoA 5. DoCon 6. DCAS 7. Eigenmath 8. Franklin Math 9. FriCAS 10. GAP e.t.c Also there are more than 30 commercial SCT tools, such as MATLAB and MuPAD from MathWorks. Detailed information can be found in reference [1], [2], [3], [4], [5], [6]. MATLAB (matrix laboratory) is a numerical computing environment developed by MathWorks. MATLAB supports plotting, operations with matrix, creation user interface and interfacing with programs written in other languages, such as Fortran, C, C++, Java, MAPLE and MuPAD.[7] Some projects can be done with MATLAB only, with request some symbolic computation so that one of symbolic computation tools is essential to apply them. On old version of MATLAB there was used system of MAPLE for symbolic computations. The last 14th version of MATLAB (September 2008) has included MuPAD as Symbolic Math Toolbox add-on.[8] MATLAB with MuPAD can be used in solving engineering problems in Computer Science and industry. This paper illustrates typical applications for engineering students, according to lectures in Computer Science.

2. INTRODUCTION TO MuPAD

Figure 1: Classification of programming languages

MuPAD (Multiprocessing Algebra Data Tool) is a programming language for symbolic algebra and high-precision decimal integer and floating-point arithmetic. Its development started about 1990 at the University of Paderborn, Paderborn, Germany, and was later changed into a separate commercial company that is now known as SciFace Software GmbH & Co. KG. [9]

1

International Journal of Computer Applications (0975 – 8887) Volume 41– No.8, March 2012 MuPAD consists of a powerful symbolic engine, a language that is optimized for operating on symbolic math expressions, and an extensive set of mathematical functions and libraries. The MuPAD engine serves as the foundation of Symbolic Math Toolbox, whose notebook interface provides access to the complete MuPAD language.[10], [11] MuPAD offers a notebook concept similar to word processing systems that allows the formulation of mathematical problems as well as graphics visualization and explanations in formatted text. MuPAD tools are applicable for different operating systems, Windows, Unix and Linux. Following possibilities are important in MuPAD:  a computer algebra system to manipulate formulas symbolically  classic and verified numerical analysis in discretionary accuracy  program packages for linear algebra, differential equations, number theory, statistics, and functional programming  an interactive graphic system that supports animations and transparent areas in 3D  a programming language that supports object-oriented programming and functional programming There is combined method to use MATLAB+MuPAD together.

2.1. Passing variables from MuPAD to MATLAB 1 – open MuPAD like n = mupad 2 – input the statement like y := x^a 3 – to take back to MATLAB use function getVar like c = getVar(n, 'y').

2.2. Passing variables from MATLAB to MuPAD 1 – open MATLAB 2 – define symbolic variables like syms x a 3 – write expression like y = x^a 4 – to send this to MuPAD use function setVar like setVar(n, y) 5 – in MuPAD write symbolic like y

2.3. Saving results of MuPAD It can be saved by using file-save as in most standard programs. To reload this file use following statement n=mupad('exp1.mn').

3. APPLICATIONS 3.1 Writing formulas In MuPAD after writing expression press ENTER. Use standard operations like +, -, *, /, ^, =. Use ; to end statement as in programming languages. Use := to assign as in programming languages. a*b; a^b; sqrt(a); a[b] // some operations with symbols 𝑎𝑏 𝑎𝑏 𝑎 𝑎𝑏 x:=a: y:=b: x-y; // some equations with symbols 𝑎−𝑏

x:=a; y:=(a)!; x*(x)^y 𝑎 𝑎! 𝑎 𝑎𝑎! ((a)/b) // division by symbols

𝑎 𝑏

Exercises: 1 – Write an expression 𝑥 = 𝑎 + 𝑏 + 𝑐 2 – Write an expression 𝑥 = 𝑎 ∗ 𝑏 ∗ 𝑐

3.2 Factorization Factorization of expression can be done by function factor. x := a^3 + 1: s := factor(x) 𝑎 + 1 𝑎2 − 𝑎 + 1 s[1] 𝑎+1 s[2]

𝑎2 − 𝑎 + 1

y := b^2 + 2*b + 1: t := factor(y) 𝑏+1 2 t*s 𝑏 + 1 2 𝑎 + 1 𝑎2 − 𝑎 + 1 Exercises: 1 – Find factorization of an expression 𝑎2 − 𝑏2 ∗ 𝑎3 − 1 2 – Find factorization of an expression 𝑒 2𝑥 − 1 ∗ 𝑎 + 1

3.3 Solving equations To solve an algebraic equation use the solve command solve(a*x^2 + b*x + c = 0, x) 𝑏 + 𝑏 2 − 4𝑎𝑐 𝑏 − 𝑏 2 − 4𝑎𝑐 − ,− 2𝑎 2𝑎 𝑖𝑓 𝑎 ≠ 0 𝑐 − 𝑏 𝑖𝑓 𝑎 = 0 ∧ 𝑏 ≠ 0 ℂ 𝑖𝑓 𝑎 = 0 ∧ b = 0 ∧ c = 0 ∅ 𝑖𝑓 𝑎 = 0 ∧ b = 0 ∧ c ≠ 0 solve(a*x^2 + b*x + c = 0, x) assuming b = 0 −𝑐 −𝑐 ,− 𝑎 𝑎 𝑖𝑓 𝑎 ≠ 0 ℂ 𝑖𝑓 𝑎 = 0 ∧ c = 0 ∅ 𝑖𝑓 𝑎 = 0 ∧ c ≠ 0 Exercises: 1 – Solve expression 𝑥 2 + 𝑐 ∗ 𝑥 = 𝑎 ∗ 𝑏 2 – Solve expression 𝑥 𝑎 + 𝑥 𝑎−1 = 𝑏

3.4 Solving System of Equations To solve system of equations write functions and use function solve. s:=a*x + b*y; 𝑎𝑥 + 𝑏𝑦

2

International Journal of Computer Applications (0975 – 8887) Volume 41– No.8, March 2012 1 – Find derivate of function 3𝑥 2 + 5𝑦 4 by x and y.

t:=a*x - b*y; 𝑎𝑥 − 𝑏𝑦 solve([s,t],[x,y]) 𝑥 = 𝑧, 𝑦 = 𝑧1 𝑖𝑓 𝑎 = 0 ∧ b = 0 𝑥 = 𝑧, 𝑦 = 0 𝑖𝑓 𝑎 = 0 ∧ b ≠ 0 𝑥 = 0, 𝑦 = 𝑧 𝑖𝑓 𝑎 ≠ 0 ∧ b = 0 𝑥 = 0, 𝑦 = 0 𝑖𝑓 𝑎 ≠ 0 ∧ b ≠ 0 solve([s,t]) 𝑎 = 𝑧1, 𝑏 = 𝑧, 𝑥 = 0, 𝑦 = 0 , 𝑎 = 𝑧1, 𝑏 = 0, 𝑥 = 0, 𝑦 = 𝑧 , 𝑎 = 0, 𝑏 = 𝑧1, 𝑥 = 𝑧, 𝑦 = 0 , 𝑎 = 0, 𝑏 = 0, 𝑥 = 𝑧1, 𝑦 = 𝑧 𝑎 = 𝑧1, 𝑏 = 𝑧, 𝑥 = 0, 𝑦 = 0 , 𝑎 = 𝑧1, 𝑏 = 0, 𝑥 = 0, 𝑦 = 𝑧 , 𝑎 = 0, 𝑏 = 𝑧1, 𝑥 = 𝑧, 𝑦 = 0 , 𝑎 = 0, 𝑏 = 0, 𝑥 = 𝑧1, 𝑦 = 𝑧 Exercises: 1 – Solve system of equations 𝑥 + 𝑦 = 𝑎, 𝑥 − 𝑦 = 𝑏 2 – Solve system of equations 𝑥 𝑎 + 𝑦 𝑏 = 𝑐, 𝑑𝑥 𝑎 − 𝑒𝑦 𝑏 = 𝑡

3.5 Differential equations To define an ordinary differential equation use function ode. To solve differential equations use function ode::solve or just solve. eq := ode(x^a*y'(x)+b*y(x) = c, y(x)) 𝑜𝑑𝑒 𝑏𝑦 𝑥 − 𝑐 + 𝑥 𝑎 𝑦 ′ 𝑥 , 𝑦 𝑥 solve(eq) 𝑐 𝑥1−𝑎 𝐶3 − 𝑖𝑓 𝑏 = 0 𝑎−1 𝑐 − 𝐶2 𝑒 𝑏

𝑏𝑥 1−𝑎 𝑎−1

𝑖𝑓 𝑏 ≠ 0

eq2 := ode({x^a*y'(x)+b*y(x) = c, y(0)=z, y'(0)=s}, y(x)) 𝑦 0 = 𝑧, 𝑦 ′ 0 = 𝑠, 𝑜𝑑𝑒 ,𝑦 𝑥 𝑏𝑦 𝑥 − 𝑐 + 𝑥 𝑎 𝑦 ′ 𝑥 solve(eq2) 𝑧+

𝑜 1−𝑎 𝑐 𝑎−1



𝑐𝑥 1−𝑎 𝑎 −1

𝑏 𝑥 1−𝑎 𝑒 𝑎 −1 𝑐−𝑏 𝑧 𝑐− 𝑜 1−𝑎 𝑏 𝑒 𝑎 −1

𝑏

∅ 𝑖𝑓 𝜎1 ≠

𝑐 𝑜𝑎

𝑐

𝑖𝑓 𝑠 =

𝑖𝑓 𝜎1 =

𝑜𝑎

𝑐 𝑜𝑎

∧b=0

∧b≠0

∨𝑏 =0 ∧ 𝑠 ≠

where

𝑐

∨𝑏≠0 𝑏𝑧 𝜎1 = 𝑠 + 𝑎 𝑜

Exercises: 1 – Find derivative of 𝑓 𝑥 = 2 – Find derivative of 𝑦 =

sin 𝑥 𝑥+1

𝑜𝑎

1 𝑥

𝜋

, 𝑓′( ) 2

3.6 Derivative To find derivative of a function write a function and use diff() function diff(a*x^2+b*y) //0th derivative of f (itself) 𝑎 𝑥2 + 𝑏 𝑦 diff(a*x^2+b*y, y) //1st derivative of f by y 𝑏 diff(a*x^2+b*y, x) //1st derivative of f by x 2𝑎𝑥 diff(a*x^2+b*y, x, x) //2nd derivative of f by x 2𝑎 Exercise:

3.7 Integration To find integration use function int. In MuPAD there are two types of integral definite and indefinite. int(f, x) computes the indefinite integral. int(f, x = a..b) computes the definite integral. int (a*x^3+ b*y,x) // integration by indefinite x 𝑎𝑥 4 + 𝑏𝑦𝑥 4 int (a*x^3+ b*y,y) // integration by indefinite y 𝑏𝑦 2 𝑎𝑥 3 𝑦 + 2 int (a*x^3+ b*y,x=0..5) // integration by definite 0 n = mupad n = MuPAD notebook

y:=x^3 x3

>> z = getVar(n, ‘y’) z= x^3 >> ezplot(z,[0,5])

Exercise:

3.10 Fourier transform There are 2 functions fourier, invfourier (inverse of Fourier) to compute fourier transform or its reverse. ∞

𝑡𝑟𝑎𝑛𝑠𝑓𝑜𝑟𝑚 ∷ 𝑓𝑜𝑢𝑟𝑖𝑒𝑟 𝑓, 𝑡, 𝑠 = 𝐹 𝑠 =

𝑓 𝑡 𝑒 𝑖𝑠𝑡 𝛿𝑡

−∞

𝑡𝑟𝑎𝑛𝑠𝑓𝑜𝑟𝑚 ∷ 𝑖𝑛𝑣𝑓𝑜𝑢𝑟𝑖𝑒𝑟 𝑓, 𝑠, 𝑡 = 𝐹 𝑡 1 ∞ = 𝑓 𝑠 𝑒 −𝑖𝑠𝑡 𝛿𝑠 2𝜋 −∞

1 – Use 𝑦 = 2𝑥 function to get from MuPAD and draw.

3.12 Transferring from MATLAB to MuPAD To transfer data from MATLAB to MuPAD use function setVar. Cause MuPAD is symbolic tool in MATLAB use syms function to send variables as symbolic.

Write in MATLAB

To use them transform keyword must be used, like transform::fourier(f, t, s) a:=3

>> syms x a >> y = x^a y= x^a 𝑥 𝑎n = mupad >> n= MuPAD notebook >> setVar(n, y) 4

International Journal of Computer Applications (0975 – 8887) Volume 41– No.8, March 2012 3 plot(y, x = 0..5)

6. REFERENCES [1] Comparison of computer algebra systems http://en.wikipedia.org/wiki/Comparison_of_computer_alg ebra_systems [2] "mathematics in the computer" as compiled by Freek Wiedijk.: http://www.cs.ru.nl/~freek/digimath/xindex.html [3] Mathematics in Open Project http://www.dmoz.org/Science/Math/Software

Directory

[4] Combinatorial Software and Databases http://www.mat.univie.ac.at/~slc/divers/software.html

4. CONCLUSION This paper gives brief information about symbolic computation techniques. The location of symbolic computation within programming language is illustrated. Symbolic and numeric computation methods can be combined to solve problems, such as MATLAB and MuPAD. After given some introductory information about MuPAD, different applications of MuPAD are computed. The ways how to apply from MATLAB into MuPAD and from MuPAD into MATLAB are illustrated in topics 11, 12. The results from other topics can also be done using these topics. These combined methods can be developed for further research activities.

[5] Oberwolfach References on Mathematical Software http://orms.mfo.de/about [6] The Scientific Computation System axiom http://axiomdeveloper.org/axiom-website/rosetta.html [7]

MATLAB: http://en.wikipedia.org/wiki/MATLAB

[8] MuPAD: http://en.wikipedia.org/wiki/MuPAD [9] MuPAD: http://www.math.utah.edu/faq/mupad/ [10]

MuPAD official site in MathWorks http://www.mathworks.com/discovery/mupad.html

[11] Algebraic Combinatory package for MuPAD http://mupadcombinat.sourceforge.net/

5. ACKNOWLEDGMENT The author would like to thank to the research department of the University of Technology (em. Niyazi Ari, Prof. Dr. sch. Techn. ETH) Zurich, Switzerland.

5

Suggest Documents