Mudanças entre as edições de "Uso do calculo simbólico na Matlab"

De MediaWiki do Campus São José
Ir para navegação Ir para pesquisar
Linha 33: Linha 33:
 
*[http://www.mathworks.com/help/symbolic/use-subs-to-evaluate-expressions-and-functions.html Use subs to Evaluate Expressions and Functions]
 
*[http://www.mathworks.com/help/symbolic/use-subs-to-evaluate-expressions-and-functions.html Use subs to Evaluate Expressions and Functions]
 
*[http://www.mathworks.com/help/symbolic/formula-rearrangement-and-rewriting.html Formula Rearrangement and Rewriting]
 
*[http://www.mathworks.com/help/symbolic/formula-rearrangement-and-rewriting.html Formula Rearrangement and Rewriting]
 +
 +
=Exemplo aplicado a substituição de variáveis=
 +
Definindo uma função de transferência <math> H(s) = \frac{s^2 + 1}{3\, s^2 + 4\, s + 6} </math> como uma função simbólica
 +
<syntaxhighlight lang=matlab>
 +
syms s
 +
H(s) = (s^2 + 1)/(3*s^2 + 4*s + 6)
 +
</syntaxhighlight>
 +
H(s) =
 +
(s^2 + 1)/(3*s^2 + 4*s + 6)
 +
Imprimindo H(s) em formato LaTeX.
 +
<syntaxhighlight lang=matlab>
 +
latex(H(s))
 +
</syntaxhighlight>
 +
ans =
 +
\frac{s^2 + 1}{3\, s^2 + 4\, s + 6}
 +
 +
Substituindo a variável s pela f(z) = 2*(z-1)/(z+1);
 +
<syntaxhighlight lang=matlab>
 +
syms z
 +
Hz(z) = subs(H,2*(z-1)/(z+1))
 +
</syntaxhighlight>
 +
Hz(z) =
 +
((2*z - 2)^2/(z + 1)^2 + 1)/((3*(2*z - 2)^2)/(z + 1)^2 + (4*(2*z - 2))/(z + 1) + 6)
 +
 +
Agrupando os termos comuns em potencias de z
 +
<syntaxhighlight lang=matlab>
 +
Hz2 = collect(Hz)
 +
</syntaxhighlight>
 +
Hz2 =
 +
(5*z^2 - 6*z + 5)/(26*z^2 - 12*z + 10)

Edição das 17h36min de 27 de setembro de 2016

Funções importantes para o uso do cálculo simbólico

  • vpa(x) Variable-precision arithmetic: evaluate each element of the symbolic input x to at least d significant digits, where d is the value of the digits function. The default value of digits is 32.
  • digits(d) Change variable precision used: sets the precision used by vpa to d significant decimal digits. The default is 32 digits.
  • double(s) Convert symbolic values to MATLAB double precision: converts the symbolic value s to double precision. Converting symbolic values to double precision is useful when a MATLAB® function does not accept symbolic values.
  • x = sym('x') creates symbolic variable x
  • syms x Create symbolic variables and functions: Create symbolic variable x.
  • p = poly2sym(c) Create symbolic polynomial from vector of coefficients: creates the symbolic polynomial expression p from the vector of coefficients c.
  • S = solve(eqn,var) Equations and systems solver.
  • subs(s,new) Symbolic substitution.
  • g = matlabFunction(f) Convert symbolic expression to function handle or file.
  • simplify(S) Algebraic simplification
  • expand(S) Symbolic expansion of polynomials and elementary functions
  • F = factor(x) Factorization
  • numden(A) Extract numerator and denominator
  • partfrac(expr,var) Partial fraction decomposition
  • latex(S) LaTeX form of symbolic expression


Algumas dicas sobre o cálculo simbólico

syms x y
f = sin(x)^2 + cos(y)^2;
diff(f)
ans =
2*cos(x)*sin(x)

Exemplo aplicado a substituição de variáveis

Definindo uma função de transferência como uma função simbólica

 syms s
 H(s) = (s^2 + 1)/(3*s^2 + 4*s + 6)
H(s) =
(s^2 + 1)/(3*s^2 + 4*s + 6)

Imprimindo H(s) em formato LaTeX.

 latex(H(s))
ans =
\frac{s^2 + 1}{3\, s^2 + 4\, s + 6}

Substituindo a variável s pela f(z) = 2*(z-1)/(z+1);

syms z
Hz(z) = subs(H,2*(z-1)/(z+1))
Hz(z) =
((2*z - 2)^2/(z + 1)^2 + 1)/((3*(2*z - 2)^2)/(z + 1)^2 + (4*(2*z - 2))/(z + 1) + 6)

Agrupando os termos comuns em potencias de z

Hz2 = collect(Hz)
Hz2 =
(5*z^2 - 6*z + 5)/(26*z^2 - 12*z + 10)