第1个回答 2015-10-01
g = subs(f,old,new) replaces
all occurrences of old with new in f,
and then evaluates f.
g = subs(f,new) replaces
all occurrences of the default variable
in f (defined
by symvar)
with new ,
and then evaluates f.
g = subs(f) replaces
symbolic variables in f with
their values obtained from the calling function and the MATLAB
workspace, and then evaluates f.
Variables with no assigned values remain as variables.
syms a b; subs(cos(a) + sin(b), {a, b}, {sym('alpha'), 2})
Simplifications
Here are three different symbolic expressions.
syms x
f = x^3 - 6*x^2 + 11*x - 6;
g = (x - 1)*(x - 2)*(x - 3);
h = -6 + (11 + (-6 + x)*x)*x;
Here are their prettyprinted forms, generated by
pretty(f);
pretty(g);
pretty(h);
These expressions are three different representations of the same mathematical function, a cubic polynomial in x.
Each of the three forms is preferable to the others in different situations. The first form, f, is the most commonly used representation of a polynomial. It is simply a linear combination of the powers of x. The second form, g,
is the factored form. It displays the roots of the polynomial and is
the most accurate for numerical evaluation near the roots. But, if a
polynomial does not have such simple roots, its factored form may not
be so convenient. The third form, h, is the Horner, or nested,
representation. For numerical evaluation, it involves the fewest
arithmetic operations and is the most accurate for some other ranges of
x.
The symbolic simplification problem involves the verification that these
three expressions represent the same function. It also involves a less
clearly defined objective — which of these representations is "the
simplest"?
This toolbox provides several functions that apply various algebraic and
trigonometric identities to transform one representation of a function
into another, possibly simpler, representation. These functions are collect, expand, horner, factor, simplify, and simple.
collect
The statementcollect(f) views f as a polynomial in its symbolic variable, say x, and collects all the coefficients with the same power of x.
A second argument can specify the variable in which to collect terms
if there is more than one candidate. Here are a few examples.
第2个回答 2015-07-19
g = subs(f,old,new) replaces
all occurrences of old with new in f,
and then evaluates f.
g = subs(f,new) replaces
all occurrences of the default variable
in f (defined
by symvar)
with new ,
and then evaluates f.
g = subs(f) replaces
symbolic variables in f with
their values obtained from the calling function and the MATLAB
workspace, and then evaluates f.
Variables with no assigned values remain as variables.
syms a b; subs(cos(a) + sin(b), {a, b}, {sym('alpha'), 2})
Simplifications
Here are three different symbolic expressions.
syms x
f = x^3 - 6*x^2 + 11*x - 6;
g = (x - 1)*(x - 2)*(x - 3);
h = -6 + (11 + (-6 + x)*x)*x;
Here are their prettyprinted forms, generated by
pretty(f);
pretty(g);
pretty(h);
These expressions are three different representations of the same mathematical function, a cubic polynomial in x.
Each of the three forms is preferable to the others in different situations. The first form, f, is the most commonly used representation of a polynomial. It is simply a linear combination of the powers of x. The second form, g,
is the factored form. It displays the roots of the polynomial and is
the most accurate for numerical evaluation near the roots. But, if a
polynomial does not have such simple roots, its factored form may not
be so convenient. The third form, h, is the Horner, or nested,
representation. For numerical evaluation, it involves the fewest
arithmetic operations and is the most accurate for some other ranges of
x.
The symbolic simplification problem involves the verification that these
three expressions represent the same function. It also involves a less
clearly defined objective — which of these representations is "the
simplest"?
This toolbox provides several functions that apply various algebraic and
trigonometric identities to transform one representation of a function
into another, possibly simpler, representation. These functions are collect, expand, horner, factor, simplify, and simple.
collect
The statementcollect(f) views f as a polynomial in its symbolic variable, say x, and collects all the coefficients with the same power of x.
A second argument can specify the variable in which to collect terms
if there is more than one candidate. Here are a few examples.