ODE's error with if else function
- February 2, 2026
- 1 reply
- 226 views
I am solving a system of 1D steady ODEs in Mathcad using RK4. The system works correctly until I add a heat transfer term representing two-way coupling between a gas phase and injected droplets. When this term is included, the solver no longer outputs results and reports that the gradient matrix must be scalar or a matrix.
The gas stagnation temperature gradient depends on Reynolds number, Nusselt number and a convective heat transfer coefficient that is itself a function of the ODE variables, which vary along z (length of nozzle)
All other gradients (Mach, pressure, velocity, etc.) are functions of the same state vector and work correctly when the heat term is removed. I suspect I am incorrectly defining a function within the gradient matrix or using If else wrong.
Any help would be appreciated, as I'm going round in circles.
below is screenshot of part of code:




Thanks very much

