function errorfunction(data, p1)
** ddprob, ddprob_response = data**
** error = 0.0**
** for i in 1:length(ddprob)**
** error += sum(abs2, ddprob_response[i][:] - ddprob[i][:])**
** end**
** return error** end

Above function is the error function from the systems in order to acheive synchronization. While using prob = OptimizationProblem(errorfunction, z0, p1) the output is “prob = OptimizationProblem. In-place: true
u0: 2-element Vector{Float64}:
0.0
0.0”

When I wanted to use solve(prob, OptimizationOptimJL.NelderMead()), I am gettin message as: MethodError: no method matching getindex(::Float64, ::Colon)

Closest candidates are:

getindex(::Number, !Matched::Integer)

@ Base number.jl:96

getindex(::Number)

@ Base number.jl:95

getindex(::Number, !Matched::Integer…)

@ Base number.jl:101

and in stack trace

errorfunction(data::Vector{Float64}, p1::Vector{Float64}) @ [Other cell: line 6]

It’s hard to figure things out at the moment, can you post a complete example and try to format your code a little better?

Off the top of my head I would bet that ddprob is a matrix, and that you should be indexing it as ddprob[i, :] instead of ddprob[i][:] (which would work in Python). In Julia, whatever the shape of the array a, a[i] for integer i is the i-th element in the flattened array, hence a scalar. That’s why you cannot apply getindex(..., :) (“colon”) on it.

Here, ddprob is a matrix and size(ddprob) = (3, 100001). In the program, I wanted to find the error between ddprob_response and ddprob, where both matrices are the same size. So here length would be 100001.

So the function I have defined is: function errorfunction(ddprob, ddprob_response, p1)
error = 0.0
for i in 1:length(ddprob)
error += sum(abs2, ddprob_response[i][:] - ddprob[i][:])
end
return error
end

To the above function, I wanted to optimize, so the code used is:

prob = OptimizationProblem(errorfunction, z0,p1)

here z0 is the initial guess and p1 is the parameters. And the output to the above code is: true
u0: 2-element Vector{Float64}:
0.0
0.0

After this I use to evaluate the code, which is: solve(prob, OptimizationOptimJL.NelderMead())

but this time, error message is shown as follow: MethodError: no method matching getindex(::Float64, ::Colon)

I hope, I explained it correctly, if not please suggest me. Thank you so much.

It is as I assumed: you are indeed trying to manipulate a matrix by first selecting the row and then performing operations. But the syntax to do that in Julia might be counter-intuitive if you come from Python.
Does the following example help you understand what is going on?

Can you please post one complete code file, surrounded by backticks, with all the necessary imports and definitions, so that we can reproduce the bug? And it seems you still haven’t corrected your array indexing problem