DOUBLE cannot convert the input expression into a double array

조회 수: 10 (최근 30일)
This is the code. Could anyone run it and give me some suggestion about the error 'DOUBLE cannot convert the input expression into a double array' ? Cheers!
if true % DD =
1.2000 0.6000 1.6000 0.5000 1.3000 1.4000 100.0000
1.2000 0.6000 1.6000 0.5000 1.3000 1.6000 100.0000
1.2000 0.6000 1.6000 0.5000 1.3000 1.8000 100.0000
1.2000 0.8000 1.6000 0.7000 1.2000 1.4000 100.0000
1.2000 0.6000 1.4000 0.7000 1.2000 1.4000 100.0000
1.3000 0.6000 1.6000 0.7000 1.3000 1.4000 100.0000
1.3000 0.6000 1.6000 0.7000 1.3000 1.4000 100.0000
1.4000 0.4000 1.6000 0.6000 1.5000 1.4000 100.0000
1.4000 1.6000 0.4000 0.8000 1.1000 1.2000 100.0000
1.4000 1.8000 0.4000 0.8000 1.1000 1.2000 100.0000
1.4000 2.0000 0.4000 0.8000 1.1000 1.2000 100.0000
1.2000 2.2000 0.3000 0.8000 1.1000 1.2000 100.0000
1.5000 1.6000 0.4000 0.6000 1.1000 1.3000 100.0000
1.5000 1.3000 0.4000 0.6000 1.5000 1.3000 100.0000
1.2000 2.0000 0.7000 0.8000 1.1000 1.2000 100.0000
1.1000 2.0000 0.7000 0.8000 1.1000 1.2000 100.0000
0.5000 1.3000 1.5000 1.4000 0.6000 0.8000 100.0000
0.4000 1.5000 1.5000 1.4000 0.6000 0.8000 100.0000
1.1000 0.5000 1.5000 0.4000 1.2000 1.5000 100.0000
1.1000 0.5000 1.5000 0.4000 1.2000 1.7000 100.0000
1.1000 0.5000 1.5000 0.6000 1.1000 1.3000 100.0000
1.3000 0.3000 1.5000 0.5000 1.4000 1.3000 100.0000
1.1000 0.5000 1.6000 0.4000 1.2000 1.5000 100.0000
1.1000 0.5000 1.7000 0.4000 1.2000 1.5000 100.0000
1.1000 0.6000 1.5000 0.4000 1.2000 1.5000 100.0000
1.3000 0.5000 1.5000 0.4000 1.2000 1.5000 100.0000
1.1000 0.5000 1.6000 0.4000 1.2000 1.5000 100.0000
1.1000 0.8000 1.6000 0.7000 1.2000 1.5000 100.0000
1.1000 0.5000 1.5000 0.4000 1.4000 1.7000 100.0000
1.1000 0.6000 1.5000 0.4000 1.2000 1.7000 100.0000
1.1000 0.5000 1.5000 0.4000 1.2000 1.7000 100.0000
1.1000 0.5000 1.5000 0.4000 1.2000 1.7000 100.0000
1.1000 0.5000 1.5000 0.8000 1.2000 1.7000 100.0000
1.1000 0.5000 1.5000 0.4000 1.2000 1.7000 100.0000
1.1000 0.9000 1.5000 0.4000 1.2000 1.7000 100.0000
1.8000 0.5000 1.5000 0.4000 1.2000 1.7000 100.0000
0.9000 0.5000 1.5000 0.8000 1.2000 1.3000 100.0000
1.1000 0.6000 1.5000 0.8000 1.2000 1.7000 100.0000
0.8000 0.5000 1.8000 0.8000 1.2000 1.7000 100.0000
rn=size(DD,1);
sub=[0.25,0.25,0.25,0.08]
p1=sub(1);
p2=sub(2);
p3=sub(3);
r=sub(4);
eutotal=zeros(rn,5);
eu=zeros(1,rn);
for i=1:rn;
d1=DD(i,1:3)-1;
d2=DD(i,4:6)-1;
edw=DD(i,7);
syms x;
%f=@(x)
f=p1*(d1(1,1)-d2(1,1))*exp(-r*x*(d1(1,1)-d2(1,1)))...
+p2*(d1(1,2)-d2(1,2))*exp(-r*x*(d1(1,2)-d2(1,2)))...
+p3*(d1(1,3)-d2(1,3))*exp(-r*x*(d1(1,3)-d2(1,3)));
y=solve(f,x)
isempty(y);
if isempty(y)
PF(1,1)=10;
else
PF=double(y);
end
end
end
  댓글 수: 2
Walter Roberson
Walter Roberson 2013년 3월 4일
After the solve(), please show use "y", and show class() and size() of all the names that are mentioned in y (that is, the ones that would be affected by the subs())
xueqi
xueqi 2013년 3월 4일
It shows y = 125*log(z1) + 250*pi*k*i but doesnt give any information about z1,pi,k. I think it is becasue of that they are produced after the code is run... Can you have a look at the whole code I comment below?

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2013년 3월 4일
Okay, I think I understand what is going on.
Sometimes MuPAD (the symbolic engine) creates expressions along the lines of
... * z1 .... where z1 = ...
That is, it extracts a complicated sub-expression and gives it a name, and then at the end says "where" and gives a definition for the sub-expression.
Unfortunately when this happens, the MATLAB interface drops the clause defining the subexpression, leaving a z* variable that did not exist in the original expression. This is, of course, a bug. And it seems to happen more in more recent versions (including in R2012a)
If you start up a MuPAD notepad with the "mupad" command, and solve() the expression inside it, you will see MuPAD's fuller answer.
In the case of the "f" you show above, general solution is
125*ln(RootOf(7*z^14-2*z^5-7,z))
where RootOf(7*z^14-2*z^5-7,z) means all of the values of "z" such that 7*z^14-2*z^5-7 comes out as 0 (the "roots" of the expression).
  댓글 수: 10
xueqi
xueqi 2013년 3월 7일
This is the answer. Thanks!
xueqi
xueqi 2013년 3월 7일
And it makes my program much much faster!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 3월 3일
편집: Azzi Abdelmalek 2013년 3월 3일
Try
subs(y)
Example
y=solve('x+1');
whos y
r=subs(y)
whos r
Also
if isempty(y)==1 is the same as if isempty(y)
  댓글 수: 15
xueqi
xueqi 2013년 3월 4일
f =
exp(-(2*x)/125)/20 + (7*exp(-(7*x)/125))/40 - (7*exp((7*x)/125))/40
xueqi
xueqi 2013년 3월 4일
편집: xueqi 2013년 3월 4일
OK. Sorry to be chaos. But when I run this code in my office pc, there is no problem at all. And also this error is not always showing in my own laptop. I just have no idea what is happening... I don.t know it is because I am using 2010 in my own laptop but 2012 in my office pc, or this error just shows randomly!

댓글을 달려면 로그인하십시오.

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by