Question

Consider the equation f(x) = 2*sin(pi*x) + 3*cos(pi*x) Write a c program that computes the values...

Consider the equation f(x) = 2*sin(pi*x) + 3*cos(pi*x)

Write a c program that computes the values of f(x) for the following values of x: 0.25, 0.5, 1, 2. Your program should allow the user to enter the value from the standard input and the results will be displayed as follows:

/*****************************************************************/

Value of x Value of f(x)

0.25 3.5355

0.5

1

2

0 0
Add a comment Improve this question Transcribed image text
Answer #1

C CODE:

#include <stdio.h>
#include <math.h>
#define PI 3.1415
// Function to get value of f(x)
float f(float x){
    return 2*sin(PI*x) + 3*cos(PI*x);
}
int main(){
    // Array to store 4 values of x
    float x[4];
    // Get values of x from the user
    printf("Enter 4 values of x for which f(x) has to be found:\n");
    for(int i = 0; i < 4; i++){
        printf("\tEnter x%d: ", i+1);
        scanf("%f", &x[i]);
    }
    // Print values of f(x) for each x
    printf("\n%-12s%s\n", "Value of x", "Value of f(x)");
    for(int i = 0; i < 4; i++){
        printf("%-12.2f%.4f\n", x[i], f(x[i]));
    }
    return 0;
}

OUTPUT:

FOR ANY HELP JUST DROP A COMMENT

Add a comment
Know the answer?
Add Answer to:
Consider the equation f(x) = 2*sin(pi*x) + 3*cos(pi*x) Write a c program that computes the values...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • a.) Write a C++ program that calculates the value of the series sin x and cos...

    a.) Write a C++ program that calculates the value of the series sin x and cos x, sin 2x or cos 2x where the user enters the value of x (in degrees) and n the number of terms in the series. For example, if n= 5, the program should calculate the sum of 5 terms in the series for a given values of x. The program should use switch statements to determine the choice sin x AND cos x, sin...

  • 8.2 (2). Consider the linear equation Y'(x) = XY (2) + (1 - 1) cos(x) -...

    8.2 (2). Consider the linear equation Y'(x) = XY (2) + (1 - 1) cos(x) - (1+) sin(x), quady (0) = 1 The true solution is Y (1) = sin(1) + cos(r). Solve this problem using Euler's method with several values of and h, for 0 <<<10. Comment on the results. (a) X = -1; h=0.5, 0.25, 0.125 (b) X = 1; h = 0.5, 0.25, 0.125 (c) = -5; h=0.5, 0.25, 0.125, 0.0625 (d) = 5; h= 0.0625

  • 8.2 (2). Consider the linear equation Y'(x) = XY (2) + (1 - 1) cos(x) -...

    8.2 (2). Consider the linear equation Y'(x) = XY (2) + (1 - 1) cos(x) - (1+) sin(x), quady (0) = 1 The true solution is Y (1) = sin(1) + cos(r). Solve this problem using Euler's method with several values of and h, for 0 <<<10. Comment on the results. (a) X = -1; h=0.5, 0.25, 0.125 (b) X = 1; h = 0.5, 0.25, 0.125 (c) = -5; h=0.5, 0.25, 0.125, 0.0625 (d) = 5; h= 0.0625

  • Consider the linear equation Y ′(x) = λY (x) + (1 − λ) cos(x) − (1...

    Consider the linear equation Y ′(x) = λY (x) + (1 − λ) cos(x) − (1 + λ) sin(x), quadY (0) = 1 . The true solution is Y (x) = sin(x) + cos(x). Solve this problem using Euler’s method with several values of λ and h, for 0 ≤ x ≤ 10. Comment on the results. (a) λ = −1; h = 0.5, 0.25, 0.125 (b) λ = 1; h = 0.5,0.25,0.125 (c) λ = −5; h = 0.5,...

  • USING C LANGUAGE Write a program that computes the total weight of a cargo. Ask the...

    USING C LANGUAGE Write a program that computes the total weight of a cargo. Ask the user to enter multiple inputs. For each input, the user indicate the weight and quantity of the boxes. The program computes and prints the total cargo weight The output should match the sample below. Make sure you print the input number (Input #1, Input #2,) 3 - Input # 1. Weight of the box (lbs): 4 Enter quantity: 2 Input #2. Weight of the...

  • Results for this submission Entered Answer Preview Result (3/2)+(6/pi)*cos(x) e + cos(2) correct (3/2)+(6/pi)*cos(x)-(2/pi)*cos(3*x) 3 6...

    Results for this submission Entered Answer Preview Result (3/2)+(6/pi)*cos(x) e + cos(2) correct (3/2)+(6/pi)*cos(x)-(2/pi)*cos(3*x) 3 6 st-ce 2 s(3x) correct (3/2)+(6/pi)*cos(x)-(2/pi)*cos(3*x)+(6/5)*pi*cos(5*x) it coule) = _ cou(30) + * cos(52) incorrect A correct f(x) f(x) correct At least one of the answers above is NOT correct. 1 (1 point) (a) Suppose you're given the following Fourier coefficients for a function on the interval (-1,7): a 3 6 6 6 = , ai = –, az = -2,25 = = and 22,...

  • The equation f(x) = (1 ‐ x) cos x ‐ sin x = 0 has at...

    The equation f(x) = (1 ‐ x) cos x ‐ sin x = 0 has at least one root between a = 0 and b = 1 since f(a)f(b) < 0. The bisection method of finding the root proceeds as follows: a. It finds the midpoint r = (a + b)/2. b. If f(r) = 0, then r is the root. If |b ‐ a| is very small less than ∈ then also we can take r as the root....

  • Write a program that computes the average of a set of grades. The user is prompted...

    Write a program that computes the average of a set of grades. The user is prompted the following: 1-Number of grades to be entered. 2-The value of the minimum grade. 3-The value of the maximum grade. Make sure to write input validation for the following: 1-The number of grades cannot be negative! In case it is 0, it means that user has no grades to enter. 2-Each entered grade should be a valid grade between the minimum and maximum values...

  • Write a c++ program to calculate the approximate value of pi using this series. The program...

    Write a c++ program to calculate the approximate value of pi using this series. The program takes an input n that determines the number of values we are going to use in this series. Then output the approximation of the value of pi. The more values in the series, the more accurate the data. Note 5 terms isn’t nearly enough. You will try it with numbers read in from a file. to see the accuracy increase. Use a for loop...

  • What to do Write a C program that computes Pi with the approximation algorithm that I...

    What to do Write a C program that computes Pi with the approximation algorithm that I introduced in class. I want you to write the program in two different ways: The first version will add up the first 28284277 elements of the approximation series in a simple for loop. I ask you to put the code into a function with this signature: float get_pi_for(void); The second version will break out of a while loop depending on whether a pair of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT