Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

esc Let 1(x) 1 -x+x2 x4 We are going to approximate by the formula I(x) a t valw

ID: 3782310 • Letter: E

Question

esc Let 1(x) 1 -x+x2 x4 We are going to approximate by the formula I(x) a t valwe Your task is to write a the user enter a real number X between -1 an 1; then displays the three values of t prompts to I(x), and the approximation error. Part We can show that any real number x satisfies cos x (til infinity) Let C(x) We are going to approximate cos(x) by the formula C(x) our task is to write a program that prompts the user to enter a real number x then displays the three values of: cos(x), and the approximation error. You should calculate the first using the cos function from the math.h library. Part We can show that any real number x satisfies x x (til infinity) In(x +1) 2 3 4 5 6 7 Let L(x) x We are going to approximate ln(x+1) by the formula L(x) Your task is to write a program that prompts the user to enter a real number x; then displays the three values of: ln(x-1), L(x), and the approximation error. You should calculate the first value using the log function from the math.h library.

Explanation / Answer

code for the progam is :

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

int main() {
int i = 1, n, power;
float sum0 = 0.0,sum1=0.0,av,x;
float tv=0.0;
float ape;
/*
* get the number of elements
* needed in infinte series
*/
printf("Enter the value for n:");
scanf("%d", &n);
printf("Enter the value for x between -1 and 1:");
scanf("%f", &x);
av=1/(1+x);
/* calculate the sum of infinite series */
while (i <= n) {
//odd
if(i%2!=0)
{

sum0=sum0+pow(x,i);
}

else{
  
sum1 = sum1+pow(x,i);
}
i++;
}
tv=1+sum0-sum1;
ape=tv-av;
  
printf(" True value: %f ", tv);
printf(" Apprx Value: %f ", av);
printf(" Error: %f ", abs(ape));
return 0;
}

2)

#include <stdio.h>
#include <math.h>
unsigned long factorial(unsigned long f)
{
if ( f == 0 )
return 1;
return(f * factorial(f - 1));
}
int main() {
int i = 2, n, power;
float sum0 = 0.0,sum1=0.0,x;
float tv=0.0;
float ape,av;
/*
* get the number of elements
* needed in infinte series
*/
printf("Enter the value for n:");
scanf("%d", &n);
printf("Enter the value for x between -1 and 1:");
scanf("%f", &x);
tv = cos( x );
  
  
/* calculate the sum of infinite series */
while (i <= n) {
//odd
int odd=i/2;
int rem=odd%2;
if(rem==0)
{
//even
sum0=sum0+pow(x,i)/factorial(i);
}
  
else{
sum1 = sum1+pow(x,i)/factorial(i);
}
i=i+2;
}
av=x+sum1-sum0;
ape=tv-av;
  
printf(" True value: %f ", tv);
printf(" Apprx Value: %f ", av);
printf(" Error: %f ", abs(ape));
return 0;
}

3)

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

int main() {
int i = 2, n, power;
float sum0 = 0.0,sum1=0.0,x;
float tv=0.0;
float ape,av;
/*
* get the number of elements
* needed in infinte series
*/
printf("Enter the value for n:");
scanf("%d", &n);
printf("Enter the value for x between -1 and 1:");
scanf("%f", &x);
tv = log(x+1);
  
  
/* calculate the sum of infinite series */
while (i <= n) {

if(i%2==0)
{
//even
sum0=sum0+pow(x,i)/(i);
}
else{
sum1 = sum1+pow(x,i)/(i);
}
i++;
}
av=x+sum1-sum0;
ape=tv-av;
  
printf(" True value: %f ", tv);
printf(" Apprx Value: %f ", av);
printf(" Error: %f ", abs(ape));
return 0;
}