# Error in mul!(c,a,b) if size(b) = (n,1)

**URL:** <https://discourse.julialang.org/t/error-in-mul-c-a-b-if-size-b-n-1/47999>\
**Category:** General Usage\
**Created:** [October 8, 2020, 8:02pm UTC](https://discourse.julialang.org/t/error-in-mul-c-a-b-if-size-b-n-1/47999 "2020-10-08T20:02:41Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![mcabbott](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcabbott/32/6603_2.png) [@mcabbott](https://discourse.julialang.org/u/mcabbott)\
**Post date:** [October 9, 2020, 6:25pm UTC](https://discourse.julialang.org/t/error-in-mul-c-a-b-if-size-b-n-1/47999/11 "2020-10-09T18:25:27Z")

</div>

`vec` should be almost free, it doesn’t copy. Changing [this line](https://github.com/JuliaNLSolvers/LsqFit.jl/blob/master/src/curve_fit.jl#L114) seems to work:

```julia
julia> @eval LsqFit function curve_fit(model, xdata::AbstractArray, ydata::AbstractArray, p0::AbstractArray; inplace = false, kwargs...)
           check_data_health(xdata, ydata)
           # construct the cost function
           T = eltype(ydata)

           if inplace
               f! = (F,p) -> (model(F,xdata,p); @. F = F - ydata)
               lmfit(f!, p0, T[], ydata; kwargs...)
           else
               f = (p) -> vec(model(xdata, p) .- ydata)
               lmfit(f, p0, T[]; kwargs...)
           end
       end
curve_fit (generic function with 6 methods)

julia> fit = curve_fit(model, x, y, p0)
LsqFit.LsqFitResult{Array{Float64,1},Array{Float64,1},Array{Float64,2},Array{Float64,1}}([0.21569863842289005, -0.1138581876726169], [-0.1323849313529998, 0.20481817486535325, 0.043805073224580104, 0.155411990397395, -0.29901825872037796, -0.329567866582958, 0.37937477638777567, -0.08988966719591829, 0.19722118793395427, -0.12888003824352467], [1.1205931996875342 -0.2417104274027374; 1.2557291191811646 -0.5417181224843365; … ; 2.786325461960339 -5.409059477823121; 3.1223373647917025 -6.734839186952479], true, Float64[])

julia> fit2 = curve_fit(model, x, y, reshape(p0,:,1)) # this might be harder
ERROR: MethodError: no method matching levenberg_marquardt(::NLSolversBase.OnceDifferentiable{Array{Float64,1},Array{Float64,2},Array{Float64,2}}, ::Array{Float64,2})

```

---

_[View the full topic](https://discourse.julialang.org/t/error-in-mul-c-a-b-if-size-b-n-1/47999)._
