# Partial deriviatives of the Euclidean norm of an ODE with respect to some parameters

I am trying to reformulate a first order ODE in a way that I can approximate the solution up to a residuum using a gradient based optimization.

The ODE I am considering is: $$\frac{\text{d}s}{\text{d}t} - \frac{2}{h(t)} \cdot \left(\mu\cdot s(t) - \sigma(t) \cdot \left(\frac{t}{R}+\mu\right)\right) = 0$$

I am assuming that the solution to this ODE can be represented by a polynomial, so I substitute this into my ODE: $$\left(2a\cdot t + b\right) - \frac{2}{h(t)} \cdot \left(\mu\cdot \left(a\cdot t^2 + b\cdot t + c \right) - \sigma(t) \cdot \left(\frac{t}{R}+\mu\right)\right) = \vec e$$

Minimizing the Euclidean norm $\lVert\vec e\rVert_2$ of the residuum $\vec e$ of this ODE is my final goal. To do that efficiently I would like to calculate the analytical gradient of this ODE with respect to the parameters $a$ and $b$.

I assume the Euclidean norm is: $$\int\left(\left(2a\cdot t + b\right) - \frac{2}{h(t)} \cdot \left(\mu\cdot \left(a\cdot t^2 + b\cdot t + c \right) - \sigma(t) \cdot \left(\frac{t}{R}+\mu\right)\right)\right)^2 \text{d}t = \lVert\vec e\rVert_2$$

However I do not know how to calculate the partial derivatives $\frac{\text{d}\lVert\vec e\rVert_2}{\text{d}a}$ and $\frac{\text{d}\lVert\vec e\rVert_2}{\text{d}b}$ with respect to a and b.

Is this even possible and how would I do that?

But answering to your question, assuming that you have the right regularity you can write $$\frac{d}{da}\lVert\vec e\rVert_2=2\int\left((2at + b) - \frac{2}{h(t)} \left(\mu(at^2 + b t + c) - \sigma(t) \left(\frac{t}{R}+\mu\right)\right)\right)^2 \left(2t - \frac{2\mu t^2}{h(t)} \right)\,dt,$$ and similarly for $\frac{d}{db}\lVert\vec e\rVert_2$.