# How to fit ODE system only on one @variables

**URL:** https://discourse.julialang.org/t/how-to-fit-ode-system-only-on-one-variables/97910
**Category:** General Usage
**Tags:** optimization, differentialequation
**Created:** [April 25, 2023, 4:45pm UTC](https://discourse.julialang.org/t/how-to-fit-ode-system-only-on-one-variables/97910 "2023-04-25T16:45:17Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![fdekerme](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fdekerme/32/43574_2.png) [@fdekerme](https://discourse.julialang.org/u/fdekerme)
#### Post date: [April 25, 2023, 4:45pm UTC](https://discourse.julialang.org/t/how-to-fit-ode-system-only-on-one-variables/97910/1 "2023-04-25T16:45:17Z")

</div>

Hello, 😁  
I have a small system of 2 differential equations whose `@variables` are `N1` and `N2`, with 3 `@parameters` `a, b, c`. I have evolution data (experimental measurements) for the variable `N1` only, named (time, data).  
I would like to use `DiffEqParamEstim.jl` to fit my model on my data and to estimate the optimal `a,b,c` parameters.  
How can I change the following cost function (and in particular the L2Loss I think) to fit the data only on `N1` and not on `N2` ?

```julia
cost_function = build_loss_objective(prob, Tsit5(), L2Loss(time, data),
                                     Optimization.AutoForwardDiff(),
                                     maxiters=10000,verbose=false)

optprob = Optimization.OptimizationProblem(cost_function, [0.0005, 0.009, 0.09])
result_bfgs = solve(optprob, BFGS())

```

Tanks ! 😁  
fdekerm

---

<div class="post-metadata">

### Author: ![fdekerme](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fdekerme/32/43574_2.png) [@fdekerme](https://discourse.julialang.org/u/fdekerme)
#### Post date: [April 26, 2023, 11:43am UTC](https://discourse.julialang.org/t/how-to-fit-ode-system-only-on-one-variables/97910/2 "2023-04-26T11:43:53Z")

</div>

For instance, the [`DiffEqParamEstim.jl`](https://docs.sciml.ai/DiffEqParamEstim/stable/) documentation give example of fit with synthetic data generated from the ODE system, so there is data for all `@variables`.

```julia
sol = solve(prob,Tsit5())
t = collect(range(0,stop=10,length=200))
using RecursiveArrayTools # for VectorOfArray
randomized = VectorOfArray([(sol(t[i]) + .01randn(2)) for i in 1:length(t)])
data = convert(Array,randomized)

```

---

<div class="post-metadata">

### Author: ![fdekerme](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fdekerme/32/43574_2.png) [@fdekerme](https://discourse.julialang.org/u/fdekerme)
#### Post date: [April 27, 2023, 3:27pm UTC](https://discourse.julialang.org/t/how-to-fit-ode-system-only-on-one-variables/97910/3 "2023-04-27T15:27:15Z")

</div>

Let me up the discussion one last time. It’s probably not very complicated (maybe even trivial), but I really don’t see how to do it. I’d like to avoid having to do a loss function “by hand”, but maybe it’s necessary.

---

<div class="post-metadata">

### Author: ![Vaibhavdixit02](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vaibhavdixit02/32/2916_2.png) [@Vaibhavdixit02](https://discourse.julialang.org/u/Vaibhavdixit02)
#### Post date: [May 2, 2023, 5:59am UTC](https://discourse.julialang.org/t/how-to-fit-ode-system-only-on-one-variables/97910/4 "2023-05-02T05:59:52Z")

</div>

Replied on github [Fit a model on incomplete data · Issue #219 · SciML/DiffEqParamEstim.jl · GitHub](https://github.com/SciML/DiffEqParamEstim.jl/issues/219#issuecomment-1530923459)
