MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   MATLAB论坛 (https://www.labfans.com/bbs/forumdisplay.php?f=6)
-   -   求助!关于结果中无理数的问题 (https://www.labfans.com/bbs/showthread.php?t=4796)

gkyingkyin 2008-10-11 10:43

求助!关于结果中无理数的问题
 
在计算过程中:
x=solve('1.0e+006=0.71e+006*(x/(52.8527^(1/3)))^(-2.09)');
x=eval(x)
结果得到:

x =

-3.1565 - 0.4296i
-3.1565 + 0.4296i
3.1856

其中我只想要得到有理数的结果,舍去两个无理数结果,请问应该怎么做
请大虾指点,谢谢~

meteora1005 2008-10-11 16:59

回复: 求助!关于结果中无理数的问题
 
用这个代码可以找出全部的实数解:

n=length(x);
for i=1:n
p=false(n,1);
if isreal(x(i))
p(i)=true(1);%p为一逻辑向量
end
end
x=x(p);


所有时间均为北京时间。现在的时间是 12:36

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.