Uso do calculo simbólico na Matlab

De MediaWiki do Campus São José
Ir para navegação Ir para pesquisar

Use subs to Evaluate Expressions and Functions

Evaluation is one of the most common mathematical operations. Therefore, it is important to understand how and when Symbolic Math Toolbox™ performs evaluations. For example, create a symbolic variable, x, and then assign the expression x^2 to another variable, y.

syms x
y = x^2;

Now, assign a numeric value to x.

x = 2;

This second assignment does not change the value of y, which is still x^2. If later you change the value of x to some other number, variable, expression, or matrix, the toolbox remembers that the value of y is defined as x^2. When displaying results, Symbolic Math Toolbox does not automatically evaluate the value of x^2 according to the new value of x.

y
y =
 x^2

To enforce evaluation of y according to the new value of x, use the subs function.

subs(y)
ans =
  4

Formula Rearrangement and Rewriting

syms s
H = (s^2 + 5*s + 6)/(s^4 + 7*s + 27)
H =
(s^2 + 5*s + 6)/(s^4 + 7*s + 27)
[N,D] = numden(H)
N =
s^2 + 5*s + 6
D =
s^4 + 7*s + 27

Coefficients of Univariate Polynomial - Find the coefficients of this univariate polynomial.

n = coeffs(N)
n =
[ 1, 5, 6]

Cuidado, pois os zeros não são inseridos no vetor dos coeficientes.

[d,terms] = coeffs(D)
d =
[ 1, 7, 27]
terms =
[ s^4, s, 1]