# Implementing Crank-Nicolson Method to Solve 1D Heat Diffusion

**URL:** <https://discourse.pymc.io/t/implementing-crank-nicolson-method-to-solve-1d-heat-diffusion/14784>\
**Category:** v5\
**Tags:** modeling, pytensor\
**Created:** [July 16, 2024, 3:19pm UTC](https://discourse.pymc.io/t/implementing-crank-nicolson-method-to-solve-1d-heat-diffusion/14784 "2024-07-16T15:19:17Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![jessegrabowski](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/jessegrabowski/32/5010_2.png) [@jessegrabowski](https://discourse.pymc.io/u/jessegrabowski)\
**Post date:** [July 17, 2024, 5:16am UTC](https://discourse.pymc.io/t/implementing-crank-nicolson-method-to-solve-1d-heat-diffusion/14784/2 "2024-07-17T05:16:10Z")

</div>

Hi,

You want to use `pytensor.scan`, which is a differentiable loop. Docs [here](https://pytensor.readthedocs.io/en/latest/library/scan.html), some discussion and example using a scan together with a CustomDist (which you will want to do) [here](https://discourse.pymc.io/t/declaring-priors-using-loops-for-state-space-models/13819).

---

_[View the full topic](https://discourse.pymc.io/t/implementing-crank-nicolson-method-to-solve-1d-heat-diffusion/14784)._
