matlab中如何进行公式的推导

比如说我现在有公式S=sqrt(D^2-h^2)+D^3/a,其中仅D和S为参数,其他为常数,将D表示为S的函数式,怎么实现?谢谢
如果我将S设为常数呢?

一般来说用solve函数就行
clear;clc;
syms S D a h;
solve('S=sqrt(D^2-h^2)','D')
这样的结果就是两个解:
ans =
(h^2+S^2)^(1/2)
-(h^2+S^2)^(1/2)
但是你给的这个公式 S=sqrt(D^2-h^2)+D^3/a 应该是没有精确的解析解的,matlab报错Unable to find closed form solution.如果有解析解的都是可以求解出来的。
温馨提示:答案为网友推荐,仅供参考
第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.
相似回答