Skip to content

Instantly share code, notes, and snippets.

@jaems33
Last active August 18, 2021 21:11
Show Gist options
  • Save jaems33/b90239912ea71f5f53841588cb373181 to your computer and use it in GitHub Desktop.
Save jaems33/b90239912ea71f5f53841588cb373181 to your computer and use it in GitHub Desktop.
Catenary Equation in C
#include <stdio.h>
#include <math.h>
double catenary(const double x, const double a) {
return a * cosh(x / a);
}
double catenary_with_eulers(const double x, const double a) {
return (a / 2.0) * (exp(x / a) + exp(-x / a));
}
int main(void) {
const double x = -2.0;
const double a = 2.0;
const double y1 = catenary(x, a);
const double y2 = catenary_with_eulers(x, a);
printf("Hyperbolic cosine of %lf (in radians) = %lf\n", x, y1);
printf("Hyperbolic cosine of %lf (in radians) = %lf\n", x, y2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment