在Matlab中评估符号函数

时间:2015-04-19 20:24:14

标签: matlab function evaluate

我在Matlab中定义了一个函数,如下所示: clg = 2*pi*(alpha-alphai+0.5*A(1)); 其中A是一个依赖于alpha的数组。 我想为clg评估aplha=0.53。 我试过subs(clg, alpha, 0.53),但它给了我一堆奇怪的错误:

Error using sym/subs>normalize (line 210)
Entries in second argument must be scalar.

Error in sym/subs>mupadsubs (line 136)
[X2,Y2,symX,symY] = normalize(X,Y); %#ok

Error in sym/subs (line 124)
    G = mupadsubs(F,X,Y);

Error in integral (line 45)
subs(clg, alpha, 0.53)

关于如何实现这一点的任何想法? 谢谢!

2 个答案:

答案 0 :(得分:0)

我的问题没问题。

>> syms x x1 x2
>> clg = 2*pi*(x-x1+0.5*x2);
>> subs(clg,x,0.53)

ans =

2*pi*(x2/2 - x1 + 53/100)

答案 1 :(得分:0)

我正在尝试重现该问题,但这可行:

syms x
%A is a symbolic matrix that depends on x
A = inv([10*x, 2*x, 3*x;
        4*x, 10, 6*x;
        7*x, 8*x, 10*x])
%y is a symbolic expression defined such that
%it depends on A, but collapses to an expression of x
y = x + 0.5*A(2,2)
%subs returns a symbolic (in this case fraction) evaluation:
subs(y, x, 3)
%eval returns a numeric evaluation:
x = 3
eval(y)

(我在自己的代码中遇到了与您相同的错误消息,但尚未找到其源代码。)