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.
Printable View
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.
For, While and Do While Loops in C - Cprogramming.com
I would likely use a for loop.
Tim S.
Code:double f ( double t ) {
double answer = pow(2.7182818,-5);
return answer;
}
int main ( ) {
for ( double t = 0 ; t < 5 ; t++ ) {
printf("f(%f)=%f\n", t, f(t));
}
}
I should get like this
f(0)= 1
f(1)=1
f(2)=1
f(3)=1
f(4)=1
f(5)=1
I have done the programming for f(0). Can you tell me how to insert loop here?
Code:
#include <stdio.h>
#include <math.h>
#define PI 3.14159265
int t;
double cos(double x);
int main(int argc, const char * argv[])
{
double x, ret1, val, val1;
int roundret1;
t = 0;
/* first exponential*/
/*define variables*/
double value;
double result;
/* Assign the value we will find the exp of */
value = -5;
/* Calculate the exponential of the value */
result = exp(value);
/* Display the result of the calculation */
printf("The Exponential of %f is %f\n", value, result);
/*second exponential*/
/*defining variables*/
double value1;
double ret;
double result1;
int tempCheck, tempret1;
val = PI / 180.0;
ret = cos( t*val );
printf("The ret is %f\n", ret);
ret1 = cos(ret*val );
printf("The ret1 is %f\n", ret1);
/*rounding the ret1*/
if(ret1>0)
{
tempret1 = ret1*10;
tempCheck = tempret1%10;
if(tempCheck>=5)
{
roundret1 = ret1;
roundret1++;
}
else
{
roundret1 = ret1;
}
printf("The roundret1 is %d\n", roundret1);
}
/* Assign the value we will find the exp of */
value1 = -5*roundret1;
printf("The value1 is %f\n", value1);
/* Calculate the exponential of the value */
result1 = exp(value1);
/* Display the result of the calculation */
printf("The Exponential of %f is %f\n", value1, result1);
/* Third exponential*/
/*defining variables*/
double value2, result2;
value2 = 10;
result2 = exp(value2);
/* Display the result of the calculation */
printf("The Exponential of %f is %f\n", value2, result2);
/* fourth exponential*/
/*defining variables*/
double ret2, ret3, value3, result3;
ret2 = sin(t*val);
ret3 = sin(ret2);
value3 = -5*ret3;
printf("The value1 is %f\n", value2);
/* Calculate the exponential of the value */
result3 = exp(value3);
/* Display the result of the calculation */
printf("The Exponential of %f is %f\n", value3, result3);
/*multiplying 4 exponentials*/
double F;
F=result*result1*result2*result3;
printf("The final value of F when t=0 is %f\n", F);
return 0;
}
Are you sure the equation is correct?
Attachment 16382
> Can you tell me how to insert loop here?
I already showed you.
You put the bulk of that main() into another function and call it f(), with a parameter of t.
Then the loop goes in main, as I SHOWED YOU!.
And... let's say the first equation is correct... So, you want to calculate a FUNCTION, isn't it? Why not to code a function f()?
Code:double f(double t)
{
return exp(-5)*exp(-5*cos(cos(t)))*exp(10*cos(t))*exp(-5*sin(sin(t)));
}
Yes the equation is absolutely correct