Coding for the mathematical function in C

Joined
Aug 29, 2021
Messages
1
Reaction score
0
I have a function
f(t) = e^(−5) e^(−5cos cos(t)) e^(10cos(t)) e^(−5sin sin(t))
I need to find the value of f for different values of t. Let us say from t=0 to t=5. How to write coding for that?. I just know some basics of C
 
Joined
Mar 3, 2021
Messages
241
Reaction score
30
Below should get you started. The formula was a bit hard to read, so I kind of guessed. I split the different factors up to make it a little easier to read. You have to include to the math library to compile it, e.g., `gcc -lm formula.c`.

C:
#include <stdio.h>
#include <math.h>

const double e = 2.7182818284590452353602874713527;

double f(double t){
    const double f1 = pow(e, -5);
    const double f2 = pow(e, -5 * cos(cos(t)));
    const double f3 = pow(e, 10 * cos(t));
    const double f4 = pow(e, -5 * sin(sin(t)));
    return f1 * f2 * f3 * f4;
}

int main(){
    printf("f(%f) = %f\n", 0., f(0.));
    printf("f(%f) = %f\n", 1., f(1.));
    printf("f(%f) = %f\n", 2., f(2.));
    printf("f(%f) = %f\n", 3., f(3.));
    printf("f(%f) = %f\n", 4., f(4.));
    return 0;
}
If you've got any questions or want anything explained, let me know.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top