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 1: Linha 1:
=[http://www.mathworks.com/help/symbolic/use-subs-to-evaluate-expressions-and-functions.html Use subs to Evaluate Expressions and Functions]=
+
= Funções importantes para o uso do cálculo simbólico =
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.
+
*[http://www.mathworks.com/help/symbolic/vpa.html 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.
syms x
+
*[http://www.mathworks.com/help/symbolic/digits.html digits(d)] Change variable precision used: sets the precision used by vpa to d significant decimal digits. The default is 32 digits.
y = x^2;
+
*[http://www.mathworks.com/help/symbolic/double.html 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.
Now, assign a numeric value to x.
+
*[http://www.mathworks.com/help/symbolic/sym.html x = sym('x')] creates symbolic variable x
x = 2;
+
*[http://www.mathworks.com/help/symbolic/syms.html syms x] Create symbolic variables and functions: Create symbolic variable x.
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.
+
*[http://www.mathworks.com/help/symbolic/solve.html S = solve(eqn,var)] Equations and systems solver:
y
+
*[http://www.mathworks.com/help/symbolic/matlabfunction.html g = matlabFunction(f)] Convert symbolic expression to function handle or file.
 +
*[https://www.mathworks.com/help/symbolic/simplify.html simplify(S)] Algebraic simplification
 +
*[https://www.mathworks.com/help/symbolic/expand.html expand(S)] Symbolic expansion of polynomials and elementary functions
 +
*[https://www.mathworks.com/help/symbolic/factor.html F = factor(x)] Factorization
 +
*[https://www.mathworks.com/help/symbolic/numden.html numden(A)] Extract numerator and denominator
 +
*[https://www.mathworks.com/help/symbolic/partfrac.html partfrac(expr,var)] Partial fraction decomposition
 +
*[http://www.mathworks.com/help/symbolic/latex.html latex(S)] LaTeX form of symbolic expression
  
y =
 
  x^2
 
To enforce evaluation of y according to the new value of x, use the subs function.
 
subs(y)
 
  
 +
= Algumas dicas sobre o cálculo simbólico =
 +
*[http://www.mathworks.com/help/symbolic/choose-symbolic-or-numeric-arithmetic.html Choose Symbolic or Numeric Arithmetic]
 +
*[http://www.mathworks.com/help/symbolic/performing-symbolic-computations.html Perform Symbolic Computations]
 +
*[http://www.mathworks.com/help/symbolic/create-symbolic-numbers-variables-and-expressions.html Create Symbolic Numbers, Variables, and Expressions]
 +
*[http://www.mathworks.com/help/symbolic/create-symbolic-functions.html Create Symbolic Functions]
 +
<syntaxhighlight lang=matlab>
 +
syms x y
 +
f = sin(x)^2 + cos(y)^2;
 +
diff(f)
 +
</syntaxhighlight>
 
  ans =
 
  ans =
  4
+
2*cos(x)*sin(x)
 
+
*[https://www.mathworks.com/help/symbolic/extract-numerators-and-denominators-of-rational-expressions.html Extract Numerators and Denominators of Rational Expressions]
=[http://www.mathworks.com/help/symbolic/formula-rearrangement-and-rewriting.html Formula Rearrangement and Rewriting]=
+
*[http://www.mathworks.com/help/symbolic/generate-matlab-functions.html Generate MATLAB Functions from Symbolic Expressions]
:*[http://www.mathworks.com/help/symbolic/numden.html numden] - Extract numerator and denominator
+
*[http://www.mathworks.com/help/symbolic/use-subs-to-evaluate-expressions-and-functions.html Use subs to Evaluate Expressions and Functions]
syms s
+
*[http://www.mathworks.com/help/symbolic/formula-rearrangement-and-rewriting.html Formula Rearrangement and Rewriting]
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
 
:*[http://www.mathworks.com/help/symbolic/coeffs.html coeffs] - Coefficients of polynomial
 
Coefficients of Univariate Polynomial - Find the coefficients of this univariate polynomial.
 
n = coeffs(N)
 
 
 
n =
 
  [ 1, 5, 6]
 
'''Atenção!!!''' Os termos nulos não são inseridos no vetor dos coeficientes.
 
[d,terms] = coeffs(D)
 
 
 
d =
 
  [ 1, 7, 27]
 
terms =
 
  [ s^4, s, 1]
 
 
 
:*[http://www.mathworks.com/help/symbolic/sym2poly.html sym2poly] - Extract vector of all numeric coefficients, including zeros, from symbolic polynomial
 
Para extrair o vetor com os termos nulos use sym2poly.
 
n = sym2poly(N)
 
 
 
n =
 
      1    5    6
 
d = sym2poly(D)
 
 
 
d =
 
    1    0    0    7    27
 

Edição das 17h11min 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.
  • S = solve(eqn,var) Equations and systems solver:
  • 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)