Skip to content

Instantly share code, notes, and snippets.

@olegkapitonov
Created January 21, 2020 11:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olegkapitonov/9c2495ed0f4abbd80022ba6f09033199 to your computer and use it in GitHub Desktop.
Save olegkapitonov/9c2495ed0f4abbd80022ba6f09033199 to your computer and use it in GitHub Desktop.
thermo model.c
#include <cstdio>
// Internal integration step in seconds
#define STEP 0.01
// Calculate temperature after delta_t seconds of heating
// with power P in watts
double calculate_temp(double temp_start, double P, double delta_t)
{
// Heat capacity, for aluminium = 920 J/K/Kg * (body mass, Kg)
double C = 920 * 0.02;
// Thermal resistance, K/W
double Rt = 0.5;
// Environment temperature, Celsius degree
double t_env = 15;
double tau = temp_start - t_env;
for (double t = 0.0; t < delta_t; t += STEP)
{
double dtau_dt = (P * Rt - tau) / C / Rt;
tau += dtau_dt * STEP;
}
return tau + t_env;
}
int main()
{
// Initialize with environment temperature
double temp = 15;
printf("t=%f\n", temp);
// Heating power
double P = 200;
for (int i = 0; i < 10; i++)
{
temp = calculate_temp(temp, P, 10.0);
printf("t=%f\n", temp);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment