# Using BoundaryValueDiffEqFIRK: How many boundary condition residual elements allowed?

**URL:** <https://discourse.julialang.org/t/using-boundaryvaluediffeqfirk-how-many-boundary-condition-residual-elements-allowed/125602>\
**Category:** General Usage\
**Created:** [February 6, 2025, 7:34am UTC](https://discourse.julialang.org/t/using-boundaryvaluediffeqfirk-how-many-boundary-condition-residual-elements-allowed/125602 "2025-02-06T07:34:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![P0p5](https://avatars.discourse-cdn.com/v4/letter/p/45deac/32.png) [@P0p5](https://discourse.julialang.org/u/P0p5)\
**Post date:** [February 6, 2025, 7:34am UTC](https://discourse.julialang.org/t/using-boundaryvaluediffeqfirk-how-many-boundary-condition-residual-elements-allowed/125602/1 "2025-02-06T07:34:30Z")

</div>

Again, I’m trying to use BVProblem with solver RadauIIa5.  
In the boundary condition function called by the solver, what is the maximum length of the  
residual vector, which is the first argument of this function?  
I am getting an error when I try to assign values to more elements than there are solution vectors, suggesting that only one residual element is allowed per solution vector.  
(This would imply that constraints on both the solution vector and its derivative would need to be combined as sums of absolute values, which would complicates the search for a minimum.)  
But this restriction seems to be inconsistent with the two examples [here](https://docs.sciml.ai/DiffEqDocs/stable/tutorials/bvp_example/), which both apply  
two constraints to only the first of two solution vectors. In this case, the residuals are not assigned to corresponding solution vectors.  
Please advise.  
Thanks

---

<div class="post-metadata">

**Author:** ![Domenico\_Lahaye](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/domenico_lahaye/32/203728_2.png) [@Domenico\_Lahaye](https://discourse.julialang.org/u/Domenico_Lahaye)\
**Post date:** [February 6, 2025, 8:08am UTC](https://discourse.julialang.org/t/using-boundaryvaluediffeqfirk-how-many-boundary-condition-residual-elements-allowed/125602/2 "2025-02-06T08:08:06Z")

</div>

Not sure.

It is math that dictates how the residual elements should be defined to solve either a boundary or initial value problem.

Does it help here to explain what you are aiming at?

---

<div class="post-metadata">

**Author:** ![P0p5](https://avatars.discourse-cdn.com/v4/letter/p/45deac/32.png) [@P0p5](https://discourse.julialang.org/u/P0p5)\
**Post date:** [February 6, 2025, 8:37am UTC](https://discourse.julialang.org/t/using-boundaryvaluediffeqfirk-how-many-boundary-condition-residual-elements-allowed/125602/3 "2025-02-06T08:37:21Z")

</div>

Domenico, thanks for your interest, but I have to disagree with you about constraint by math.  
I see no mathematical restriction against having any number of constraints  
on each solution vector, corresponding to various features and derivatives of that vector.  
I think it can be restricted only by the code design. That’s what I’m asking about.  
Andy

---

<div class="post-metadata">

**Author:** ![Domenico\_Lahaye](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/domenico_lahaye/32/203728_2.png) [@Domenico\_Lahaye](https://discourse.julialang.org/u/Domenico_Lahaye)\
**Post date:** [February 6, 2025, 8:43am UTC](https://discourse.julialang.org/t/using-boundaryvaluediffeqfirk-how-many-boundary-condition-residual-elements-allowed/125602/4 "2025-02-06T08:43:39Z")

</div>

Thanks, Andy.

Again, I am not sure that I understand the matter.

Again, does it help here to pose a problem that you are trying to solve? This might help to reach some concensus.

What do you think?

---

<div class="post-metadata">

**Author:** ![ErikQQY](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/erikqqy/32/23074_2.png) [@ErikQQY](https://discourse.julialang.org/u/ErikQQY)\
**Post date:** [February 6, 2025, 10:45am UTC](https://discourse.julialang.org/t/using-boundaryvaluediffeqfirk-how-many-boundary-condition-residual-elements-allowed/125602/5 "2025-02-06T10:45:12Z")

</div>

> [@P0p5](#):
>
> I am getting an error when I try to assign values to more elements than there are solution vectors, suggesting that only one residual element is allowed per solution vector.

I am guessing you are trying to solve an overconstrained BVP right? BoundaryValueDiffEq.jl does support that, here is a simple example:

```julia
function f1!(du, u, p, t)
    du[1] = u[2]
    du[2] = -u[1]
end

function bc1!(resid, sol, p, t)
    solₜ₁ = sol(0.0)
    solₜ₂ = sol(100.0)
    resid[1] = solₜ₁[1]
    resid[2] = solₜ₂[1] - 1
    resid[3] = solₜ₂[2] + 1.729109
end
prob = BVProblem(BVPFunction(f1!, bc1!; bcresid_prototype = zeros(3)), u0, tspan),
sol = solve(prob, RadauIIa5(), dt=0.01)

```

You need to specify `bcresid_prototype` to explicitly state the number of boundary conditions

---

<div class="post-metadata">

**Author:** ![P0p5](https://avatars.discourse-cdn.com/v4/letter/p/45deac/32.png) [@P0p5](https://discourse.julialang.org/u/P0p5)\
**Post date:** [February 6, 2025, 6:51pm UTC](https://discourse.julialang.org/t/using-boundaryvaluediffeqfirk-how-many-boundary-condition-residual-elements-allowed/125602/6 "2025-02-06T18:51:37Z")

</div>

> [@ErikQQY](#):
>
> `BVPFunction(`

hmmm, it seems that bcresid\_prototype so far may have appeared only in examples for TwoPointBVProblem.  
And BVPFunction not at all?  
So news about this feature is welcome!

Are there alternatives to “zeros” in “bcresid\_prototype = zeros” ?

thanks
