DOUBLE cannot convert the input expression into a double array

7 views (last 30 days)
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 Comments
Walter Roberson
Walter Roberson on 4 Mar 2013
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 on 4 Mar 2013
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?

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 4 Mar 2013
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 Comments

Sign in to comment.

More Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 3 Mar 2013
Edited: Azzi Abdelmalek on 3 Mar 2013
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 Comments
xueqi
xueqi on 4 Mar 2013
f =
exp(-(2*x)/125)/20 + (7*exp(-(7*x)/125))/40 - (7*exp((7*x)/125))/40
xueqi
xueqi on 4 Mar 2013
Edited: xueqi on 4 Mar 2013
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!

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!