liangc 发表于 2010-8-2 08:42:30

已经定义各参数为正,应该只有1个正数解,结果却有正负2个解

已经定义各参数为正,应该只有1个正数解,结果却有正负2个解
怎样做,才能让方程只给出1个正数解?
x=sym('x','positive');
a=sym('a','positive');
b=sym('b','positive');
solve('a*x^2 = b','x')

ans =

b^(1/2)/a^(1/2)
-b^(1/2)/a^(1/2)

lengyunfeng 发表于 2010-8-2 10:28:43

本帖最后由 lengyunfeng 于 2010-8-2 10:29 编辑

The relational operators, such as >,<,==,~=, are not available for the symbolic data in Matlab, which suggests that if your symbolical calculation involves relational judgement in matlab (such as to judge the answers of an equation is positive or negative), the results may be not in your speculation. You can use the syntaxes as follows to understand my opinion.>> syms a positive
>> a+1>sym(0)NOTE: PERSONAL IDEA, ONLY FOR CONSULTATION.

sunfishfly 发表于 2010-8-2 10:31:01

本帖最后由 lengyunfeng 于 2010-8-2 10:43 编辑

solve中x是作为一个变量来进行计算的,
你可以试一下,前面不需要定义x,使用solve语句仍然可以得到结果,
前面对x的定义对后面的计算没有影响
所以会得到两个解

个人拙见

===================================================================
你可以试一下:
syms a b positive
solve('a*x^2=b',sym('x','positive'))

结果仍是正负两个解,所以你的看法本身虽无错,但导致这种现象的根不在这。
by lengyunfeng
===================================================================

liangc 发表于 2011-10-4 23:05:05

刚刚在matlab 2011a中试了一下,发现新版本中可以得到正确的解了!

>> x=sym('x','positive');
a=sym('a','positive');
b=sym('b','positive');
solve('a*x^2 = b','x')

ans =

b^(1/2)/a^(1/2)
页: [1]
查看完整版本: 已经定义各参数为正,应该只有1个正数解,结果却有正负2个解