DimensionMismatch ("Cannot Multiply two vectors")


#1

Dear Julia users, I am getting the following error when I try to multiply some coefficients contained in my matrix Data G by the values in another matrix P. The code is the following one:

while bd>dualitygap
q=0;
for i in 1:ngen
 for j in 1:T
## Cases with Popt
 Popt[i,j]=(Lambda[j]-DataG[i,5])/2*DataG[i,4]
 if Popt[i,j]<=DataG[i,2]
 P[i,j]=DataG[i,2]
elseif (Popt[i,j]>=DataG[i,2] && Popt[i,j]<DataG[i,3])
 P[i,j]=Popt[i,j];
 posibles[i,j]=1
elseif Popt[i,j]>=DataG[i,3]
 P[i,j]=DataG[i,3]
 end
## Dynamic Programming
F[i,j]=DataG[i,(4:6)]*[P[i,j]^2;P[i,j];1]-Lambda[j]*P[i,j]
if F[i,j]<0
U[i,j]=1
else
U[i,j]=0
end
end
end >DimensionMismatch("Cannot multiply two vectors")
U
.
.
.

Note

[P[1,1]^2,P[1,1],1]
3-element Array{Float64,1}:
 10000.0
   100.0
     1.0
DatosG[1,(4:6)]
3-element Array{Float64,1}:
   0.002
  10.0
 500.0

#2

Please post the full error output and try to simplify your example as much as possible. Otherwise there’s no way for us to know what the problem is.


#3

Although the error is pretty explicit: somewhere you’ve got two vectors and you’re doing v*w to multiply them, which does not work. If you want an inner (dot) product of the two, you can do v'w. If you want an outer product, you can do v*w'. You probably want an inner product.


#4

Also can do v⋅w for inner product (\cdot for the dot).


#5

Problem solved, everything is working fine thank you so much.