# MethodError: Cannot \`convert\` an object of type Vector{Float64} to an object of type Float64 in the ODEProblem

**URL:** https://discourse.julialang.org/t/methoderror-cannot-convert-an-object-of-type-vector-float64-to-an-object-of-type-float64-in-the-odeproblem/111796
**Category:** New to Julia
**Tags:** differentialequation
**Created:** [March 18, 2024, 11:39pm UTC](https://discourse.julialang.org/t/methoderror-cannot-convert-an-object-of-type-vector-float64-to-an-object-of-type-float64-in-the-odeproblem/111796 "2024-03-18T23:39:26Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Shashank\_Kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shashank_kumar/32/207838_2.png) [@Shashank\_Kumar](https://discourse.julialang.org/u/Shashank_Kumar)
#### Post date: [March 18, 2024, 11:39pm UTC](https://discourse.julialang.org/t/methoderror-cannot-convert-an-object-of-type-vector-float64-to-an-object-of-type-float64-in-the-odeproblem/111796/1 "2024-03-18T23:39:26Z")

</div>

I have been trying to solve this differential equation using ODEProblem whose code is given below,

```julia
using QuadGK
function solve_eq(a0::Float64)
    e0 = sqrt(2/(8.85*10^(-12)*3*10^8) * (0.5 * 10^(12)/(10^-4)))
    e_field(t) = e0 * cos(2.35*(t) + 0.003*(t)^2)*exp(-(t)^2/25.0^2)
    vector_potential(t) = -1 * quadgk(x-> e_field(x), -200.0, t)[1]

    k_time(t) = 1.6e-19*a0/(1.054571817e-34) * 1e-15 * vector_potential(t)

    function pulse_tdse!(du, u, p, t)
        du[1] = k_time(t) * u[1]
        du[2] = k_time(t) * u[2]
    end
    # a0 = [exp(1im*pi/4), exp(1im*pi/4)]
    a0 = [0.0, 0.0]
    tspan = (-100.0, 100.0)
    prob = ODEProblem(pulse_tdse!, a0, tspan)
    sol = solve(prob, RK4(), dt = 0.1, saveat = 0.1)
    return sol
end

solve_eq(4.2e-10)

```

This gives an error

```julia
MethodError: Cannot `convert` an object of type Vector{Float64} to an object of type Float64

```

However, I was able to identifiy the problem, if I remove the argument of the solve\_eq function then it runs smoothly. The debugged code is below,

```julia

using QuadGK
function solve_eq()
    e0 = sqrt(2/(8.85*10^(-12)*3*10^8) * (0.5 * 10^(12)/(10^-4)))
    e_field(t) = e0 * cos(2.35*(t) + 0.003*(t)^2)*exp(-(t)^2/25.0^2)
    vector_potential(t) = -1 * quadgk(x-> e_field(x), -200.0, t)[1]

    k_time(t) = 1.6e-19*4.2e-10/(1.054571817e-34) * 1e-15 * vector_potential(t)

    function pulse_tdse!(du, u, p, t)
        du[1] = k_time(t) * u[1]
        du[2] = k_time(t) * u[2]
    end
    # a0 = [exp(1im*pi/4), exp(1im*pi/4)]
    a0 = [0.0, 0.0]
    tspan = (-100.0, 100.0)
    prob = ODEProblem(pulse_tdse!, a0, tspan)
    sol = solve(prob, RK4(), dt = 0.1, saveat = 0.1)
    return sol
end

solve_eq()

```

Can someone let me know what is the problem with the first code?

---

<div class="post-metadata">

### Author: ![Shashank\_Kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shashank_kumar/32/207838_2.png) [@Shashank\_Kumar](https://discourse.julialang.org/u/Shashank_Kumar)
#### Post date: [March 18, 2024, 11:55pm UTC](https://discourse.julialang.org/t/methoderror-cannot-convert-an-object-of-type-vector-float64-to-an-object-of-type-float64-in-the-odeproblem/111796/2 "2024-03-18T23:55:41Z")

</div>

I figured out the problem. The a0 argument and the initial value variable name is same. That’s why its creating problem. The following code works perfectly fine.

```julia
using QuadGK
function solve_eq(a0::Float64)
    e0 = sqrt(2/(8.85*10^(-12)*3*10^8) * (0.5 * 10^(12)/(10^-4)))
    e_field(t) = e0 * cos(2.35*(t) + 0.003*(t)^2)*exp(-(t)^2/25.0^2)
    vector_potential(t) = -1 * quadgk(x-> e_field(x), -200.0, t)[1]

    k_time(t) = 1.6e-19*a0/(1.054571817e-34) * 1e-15 * vector_potential(t)

    function pulse_tdse!(du, u, p, t)
        du[1] = k_time(t) * u[1]
        du[2] = k_time(t) * u[2]
    end
    # a0 = [exp(1im*pi/4), exp(1im*pi/4)]
    u0 = [0.0, 0.0]
    tspan = (-100.0, 100.0)
    prob = ODEProblem(pulse_tdse!, u0, tspan)
    sol = solve(prob, RK4(), dt = 0.1, saveat = 0.1)
    return sol
end

solve_eq(4.2e-10)

```

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [March 19, 2024, 12:29am UTC](https://discourse.julialang.org/t/methoderror-cannot-convert-an-object-of-type-vector-float64-to-an-object-of-type-float64-in-the-odeproblem/111796/3 "2024-03-19T00:29:55Z")

</div>

this would also work fine if you just remove the type constraint on a0 which doesn’t help performance at all.
