lettura simple

Symbolic Calculation on Matlab

Let me tell you about a fascinating tool in mathematics: symbolic variables and symbolic calculation.

What is symbolic calculation? Symbolic calculation, as you may know, is a branch of mathematics that deals with solving mathematical problems expressed in terms of symbols. It's different from numerical calculation, which, as the name suggests, deals with problems expressed in numbers. Symbolic calculation has many applications, including physics, economics, and engineering, and understanding how to perform it on Matlab can greatly improve your problem-solving skills in these fields.

How to declare a symbolic variable

Now, to perform symbolic calculation on Matlab, what you need to do is declare the unknown variables as symbols using the syms command.

It's quite simple really, just type in syms x and Matlab will recognize the variable 'x' as a mathematical symbol.

>> syms x

And if you have more than one variable, say 'x', 'y', and 'z', you can declare them all at once with syms x y z.

>> syms x y z

This way, Matlab recognizes the variables as mathematical symbols.

Example of Usage

Symbolic variables allow you to perform algebraic calculations with unknown variables.

Let's take an example to illustrate this concept. Consider two polynomials:

$$ P(x) = x + y $$

$$ Q(x) = x - 2y $$

When you multiply these polynomials together, you get:

$$ P(x) \cdot Q(x) = (x + y) \cdot (x - 2y) $$

$$ P(x) \cdot Q(x) = x^2 - 2xy + xy -2y^2 $$

$$ P(x) \cdot Q(x) = x^2 - xy -2y^2 $$

Now, suppose you want to perform the same calculation in Matlab. You can do that easily using symbolic calculation.

First, define the two symbolic variables x and y using the command syms x y

>> syms x y

These variables allow you to manipulate and solve algebraic expressions involving unknown variables with great ease.

Then, calculate the expression pq = (x+y)(x-2y) on the command line.

>> pq = (x+y)*(x-2*y)

ans =
(x + y)*(x - 2*y)

Matlab will recognize the variables x and y as symbolic variables and will define the symbolic expression.

Note. It's worth noting that Matlab doesn't substitute the symbolic variables x and y with numerical values but uses them as the symbols of two unknown variables.

To perform the algebraic calculation, use the function expand(pq)

>> expand(pq)

ans =
x^2 - x*y - 2*y^2

And there you have it, the result is the expression x2-xy-2y2

Symbolic variables can be used to perform any algebraic calculation in Matlab, and they are a powerful tool for mathematicians and scientists alike.




Report a mistake or post a question




FacebookTwitterLinkedinLinkedin