- #1
chill_factor
- 903
- 5
Homework Statement
Solve the following sum: Ʃ f(0.01k) from k=1 to k=100000 where f(k) = √minimum of (1,k) * exponential(maximum of (1.5, k)*maximum of (1.5,k))
Homework Equations
See above.
The Attempt at a Solution
/*I've written a C program to solve this problem. it compiles. However, when I run it, the answer is 0 which is incorrect. What's wrong with either my methodology or coding?*/
#include<stdio.h>
#include<math.h>
main(){
int k; /*declare k variable */
double min; /*declare minimum variable*/
double max; /*declare maximum variable*/
double funcResult; /*declare function result*/
double sum; /*declare sum result*/
/*create minimum function*/
if(0.01*k<1){
min=0.01*k;
}
else{
min=1;
}
/*create maximum function*/
if(0.01*k>1.5){
max=0.01*k;
}
else{
max=1.5;
}
/*create funcResult function*/
funcResult=sqrt(min*exp(-max*max));
/*compute the sum */
sum=0;
for(k=1;k<=100000;k++){
sum=(sum+funcResult);
}
printf("The answer to this sum is: %lf\n and the funcResult is %lf",sum,funcResult);
}