正在加载图片...
>>eval(phi)% execute the string(1+sqrt(5)/2 正如所期望那样, numeric和eval返回相同数值。 符号函数sm2poly将符号多项式变换成它的 MATLAB等价系数向量。函数poly2syrm功能 正好相反,并让用户指定用于所得结果表达式中的变量。 >>f2*x2+x3-3*x+5 f is the symbolic polynomials 2*x^2+x^3-3*x+5 > n=sym2poly(f)% extract eht numeric coefficient vector > poly 2sym(n)% recreate the polynomials in x( the default) ans- 2*x^2+x^3-3*x+5 s^3+2*s^2-3*s+5 变量替换 假设有一个以x为变量的符号表达式,并希望将变量转换为y。 MATLAB提供一个工具称 作subs,以便在符号表达式中进行变量替换。其格式为subs(f,new,od),其中f符号表达 式,new和old是字符、字符串或其它符号表达式。‘新’字符串将代替表达式f中各个‘旧 字符串。以下有几个例子 >>fa*x2+*x+c create a function f(x) a*x2+b*x ans- >>subs(f, 'alpha, 'a )% substitute 'alpha 'for 'a'in f>> eval(phi) % execute the string ' (1+sqrt(5))/2 ans= 1.6180 正如所期望那样,numeric和eval返回相同数值。 符号函数sym2poly将符号多项式变换成它的MATLAB等价系数向量。函数poly2syrn功能 正好相反,并让用户指定用于所得结果表达式中的变量。 >> f=' 2*x^2+x^3-3*x+5 ' % f is the symbolic polynomials f= 2*x^2+x^3-3*x+5 >> n=sym2poly(f) % extract eht numeric coefficient vector n= 1 2 -3 5 >> poly2sym(n) % recreate the polynomials in x (the default) ans= 2*x^2+x^3-3*x+5 >> poly2sym(n,' s ') % recreate the polynomials in s ans= s^3+2*s^2-3*s+5 变量替换 假设有一个以x为变量的符号表达式,并希望将变量转换为y。MATLAB提供一个工具称 作subs,以便在符号表达式中进行变量替换。其格式为subs(f,new,old),其中f是符号表达 式,new和old是字符、字符串或其它符号表达式。‘新’字符串将代替表达式f中各个‘旧’ 字符串。以下有几个例子: >> f= ' a*x^2+b*x+c ' % create a function f(x) f= a*x^2+b*x+c >> subs(f,' s ',' x ') % substitute ' s ' for ' x ' in the expression f ans= a*s^2+b*s+c >> subs(f,' alpha ',' a ') % substitute ' alpha ' for ' a ' in f
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有