找回密码
 注册
Simdroid-非首页
查看: 96|回复: 3

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

[复制链接]
发表于 2010-8-2 08:42:30 | 显示全部楼层 |阅读模式 来自 上海
已经定义各参数为正,应该只有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)

发表于 2010-8-2 10:28:43 | 显示全部楼层 来自 四川成都
Simdroid开发平台
本帖最后由 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.
  1. >> syms a positive
  2. >> a+1>sym(0)
复制代码
NOTE: PERSONAL IDEA, ONLY FOR CONSULTATION.
回复 不支持

使用道具 举报

发表于 2010-8-2 10:31:01 | 显示全部楼层 来自 山东济南
本帖最后由 lengyunfeng 于 2010-8-2 10:43 编辑

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

个人拙见

===================================================================
你可以试一下:
  1. syms a b positive
  2. solve('a*x^2=b',sym('x','positive'))
复制代码

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

评分

1

查看全部评分

回复 不支持

使用道具 举报

 楼主| 发表于 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

查看全部评分

回复 不支持

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Simapps系列直播

Archiver|小黑屋|联系我们|仿真互动网 ( 京ICP备15048925号-7 )

GMT+8, 2024-10-4 15:38 , Processed in 0.079494 second(s), 18 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表