-1

hey guys i just need someone to help me out in parts (c) and (d) of the following question:

a- Implement the function f(a,x)=sin(ax)/x. (the prototype is double f1(double a, double x). Note that this function is equal to a for x=0. (6 points)
b- Write a code that asks the user to enter a, and calculates the sum: sum= f(a,0)+f(a,0.01)+f(a,0.02)+…+f(a,1) , i.e. in the interval 0<=x<=1. Test your code for a=12, and include the result as a comment in your program.

c- Write a code which counts, calculates, and displays the roots of f(a,x) in the interval 0<=x<=1, with an error less than 0.01. Note that a root exists between r and r+0.01 if f(a,r)*f(a,r+0.01) is negative. Test your code for a=12, and include the result as a comment in your program.

d- Write a code which counts, calculates, and displays the number of minima of f(a,x) in the interval 0<=x<=1, with an error less than 0.01. Test your code for a=12, and include the result as a comment in your program.

Edited by ??!!

2
Contributors
3
Replies
19
Views
5 Years
Discussion Span
Last Post by shvmgyl15
0

do you want the code or explanation

for the (c) part you just have to write the square root code

-1

an explanation would do

Edited by ??!!

0
double SQRT(double num)

{

    // Assume that the number is less than 1,000,000. so that the maximum of SQRT would be 1000.

    // Lets assume the result is 1000. If you want you can increase this limit


double min = 0, max = 1000;

    double answer = 0;

    double test = 0;

    if(num < 0)

    {

    printf("Negative numbers are not allowed");

    return -1;

    }

    else if(num == 0)

    return 0;



    while(1)

    {

    test = (min + max) / 2;

    answer = test * test;

    if( num > answer)

    {

        // min needs be moved

        min = test;

    }

    else if(num < answer)

    {

        // max needs be moved

        max = test;

    }

    if(num == answer)

        break;

    if(num > (answer - 0.01) &&

        num < (answer + 0.01))

        break;

    }

    return test;

}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.