# MethodError: no method matching\*Vector{Float64}

**URL:** <https://discourse.julialang.org/t/methoderror-no-method-matching-vector-float64/96720>\
**Category:** New to Julia\
**Tags:** error\
**Created:** [March 28, 2023, 3:46pm UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-vector-float64/96720 "2023-03-28T15:46:18Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![HamidLD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hamidld/32/48112_2.png) [@HamidLD](https://discourse.julialang.org/u/HamidLD)\
**Post date:** [March 28, 2023, 3:46pm UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-vector-float64/96720/1 "2023-03-28T15:46:18Z")

</div>

Hi everyone,  
I know there are similar topics but I couldn’t fix my issue by reading them.  
I get this error:  
MethodError: no method matching \*(::Vector{Float64}, ::Vector{Float64})

And here is my code:

```julia
function Qbandit(params, data)
	Beta = params[1]
	LR = 0.5 + 0.5 * erf(params[2] / sqrt(2))
	 W = params[3]
	 
 r1::Array{Int64,1} = data.r1
 r2::Array{Int64,1} = data.r2
 C::Array{Int64,1} = data.Choice
 TrialType::Array{Int64,1} = data.TrialType
 Feedback::Array{Int64,1} = data.Feedback
 Condition::Array{Int64,1} = data.Condition
 
	 
	 # Initialize Q values
 
 Q = zeros(typeof(Beta),4, 4)
 conditions = ["condition1", "condition2", "condition3", "condition4"]
 rownames = ["QA1", "QB1", "QA2", "QB2"]
 Q = NamedArray(Q, (rownames, conditions), ("rows", "conditions"))
 
 
	 
	 # Initialize lik
	 lik = 0
	 
	 # loop over trials
 for t in 1:length(C)
	 QC = Condition[t]
 
	 #increment likelihood according to log probability of making their actual choice
	 QATotal = (1-W)*(Q["QA1",QC]) - W*Q["QA2",QC]
	 QBTotal = (1-W)*(Q["QB1",QC]) - W*Q["QB2",QC]
        
      if C[t] == 1
		 lik += lik + (Beta*QATotal - log(sum(exp.(Beta*c(QATotal, QBTotal)))))

 elseif C[t] == 2
		 lik += lik + (Beta*QBTotal - log(sum(exp.(Beta*c(QATotal, QBTotal)))))          
        end

	 # Learning
  if TrialType[t] == 1 && Feedback[t] == 1
	 if C[t] == 1
		 Q["QA1", QC] = (1 - LR) * Q["QA1", QC] + LR * r1[t]
	 elseif C[t] == 2
		 Q["QB1", QC] = (1 - LR) * Q["QB1", QC] + LR * r2[t]
	 end
 elseif TrialType[t] == 1 && Feedback[t] == 0
	 if C[t] == 1
		 Q["QB1", QC] = (1 - LR) * Q["QB1", QC] + LR * r2[t]
	 elseif C[t] == 2
		 Q["QA1", QC] = (1 - LR) * Q["QA1", QC] + LR * r1[t]
	 end
 elseif TrialType[t] == 0 && Feedback[t] == 1
	 if C[t] == 1
		 Q["QA2", QC] = (1 - LR) * Q["QA2", QC] + LR * r1[t]
	 elseif C[t] == 2
		 Q["QB2", QC] = (1 - LR) * Q["QB2", QC] + LR * r2[t]
	 end
 elseif TrialType[t] == 0 && Feedback[t] == 0
	 if C[t] == 1
		 Q["QB2", QC] = (1 - LR) * Q["QB2", QC] + LR * r2[t]
	 elseif C[t] == 2
		 Q["QA2", QC] = (1 - LR) * Q["QA2", QC] + LR * r1[t]
		  end
	  end
 end
 
 return -lik
 end
 
(betas,sigma,x,l,h) = em(data,subs,X,startbetas,startsigma,Qbandit; emtol=emtol, full=full);

```

I’m not sure which line the error refers to, but I assumed this one:  
lik += lik + (Beta_QATotal - log(sum(exp.(Beta_c(QATotal, QBTotal)))))

I tried writing it in different ways but to no avail.

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [March 28, 2023, 3:56pm UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-vector-float64/96720/2 "2023-03-28T15:56:06Z")

</div>

Hi!  
It’s usually a good idea to format your code with three backticks at the beginning and three at the end, to make it easier to read. I haven’t read it but could it be that you’re trying to multiply two vectors elementwise? If so, you need to use the dot syntax for vectorization: `U .* V` instead of `U * V`

---

<div class="post-metadata">

**Author:** ![HamidLD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hamidld/32/48112_2.png) [@HamidLD](https://discourse.julialang.org/u/HamidLD)\
**Post date:** [March 28, 2023, 4:26pm UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-vector-float64/96720/3 "2023-03-28T16:26:18Z")

</div>

Thanks for the prompt response and the tip, it should be readable now.  
I tried replacing U\*V with U.\*V everywhere in the code but it still gives that error.

---

<div class="post-metadata">

**Author:** ![sanjeev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sanjeev/32/212058_2.png) [@sanjeev](https://discourse.julialang.org/u/sanjeev)\
**Post date:** [March 28, 2023, 4:38pm UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-vector-float64/96720/4 "2023-03-28T16:38:22Z")

</div>

Look at the stacktrace. You might be doing `Vector{Float64} * Vector{Float64}`, somewhere else. Maybe in function c ?

---

<div class="post-metadata">

**Author:** ![HamidLD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hamidld/32/48112_2.png) [@HamidLD](https://discourse.julialang.org/u/HamidLD)\
**Post date:** [March 28, 2023, 5:58pm UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-vector-float64/96720/5 "2023-03-28T17:58:54Z")

</div>

Thanks, this was it. I’m using a package and traced it back to a function inside it.  
Just one more thing, I’m still confused as to when I should use just \* and when .\* in julia.

---

<div class="post-metadata">

**Author:** ![Nathan\_Boyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nathan_boyer/32/14825_2.png) [@Nathan\_Boyer](https://discourse.julialang.org/u/Nathan_Boyer)\
**Post date:** [March 28, 2023, 6:15pm UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-vector-float64/96720/6 "2023-03-28T18:15:39Z")

</div>

Use `.` whenever you want the operation performed element-by-element. This is called [broadcasting](https://docs.julialang.org/en/v1/manual/arrays/#Broadcasting) and Julia forces you to be explicit about when you want that behavior.

There is [a macro available](https://docs.julialang.org/en/v1/base/arrays/#Base.Broadcast.@ __dot__ ) to make this a little more convenient in case you have many broadcasting operations in one line: `2 .* x .* y == @. 2 * x * y`.

See more detailed explanations here:

> [@Understand vectorized dot operators](https://discourse.julialang.org/t/understand-vectorized-dot-operators/96388):
>
> Dear folks I’m an old Matlab user who is trying to switch to Julia. In Matlab, I use array (element-wise) arithmetic a lot. When I tried to make element-wise arithmetic using Julia, I noticed the following strange behavior: Adding a scalar to a vector needs dot “.+”, while multiplying them works fine without the dot!!! Multiplying two vectors needs dot “.\*”, while adding them works fine without the dot!!! I got confused!! Please help me understand when I need the dot and when I don’t need i…

---

<div class="post-metadata">

**Author:** ![sanjeev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sanjeev/32/212058_2.png) [@sanjeev](https://discourse.julialang.org/u/sanjeev)\
**Post date:** [March 28, 2023, 6:20pm UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-vector-float64/96720/7 "2023-03-28T18:20:02Z")

</div>

Mathematically vector times vector is not defined. So julia doesn’t know what to do when you ask it do vector times vector. You can ask it to multiply each ith element of two vectors if that is your requirement. You can see all the methods of the `*` operator by running `methods(*)`.

---

<div class="post-metadata">

**Author:** ![HamidLD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hamidld/32/48112_2.png) [@HamidLD](https://discourse.julialang.org/u/HamidLD)\
**Post date:** [March 28, 2023, 6:43pm UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-vector-float64/96720/8 "2023-03-28T18:43:07Z")

</div>

Thanks!
