Both of the questions need to be done on C++ please. 8 Question 8 In this questi
ID: 3726295 • Letter: B
Question
Both of the questions need to be done on C++ please.
8 Question 8 In this question, we compute the following sum: N-1 $(z) = cos z sin Set N = 20 in this question. . Define the following function f(z) = 5-11 S(r) (8.2) . Consider only values >0 in this question Find brackets of size not less than 0.1 which enclose the first 6 positive roots of f(z), i.e. where/(x) = 0. Find brackets of size not less than 0.1 which enclose the first 6 discontinuities of Using the bisection algorithm and your brackets above, calculate the values of the first, third and fifth positive roots of f(a) to an accuracy of three decimal places. . Solutions which compute roots other than the first, third and fifth will receive a score of zero. to 3 . Using the bisection algorithm and your brackets above, calculate the locations fourth and sixth discontinuities of fr) (for z >0) to an accuracy of three decimal places. Terminate the iteration if If(r) 10 in the iteration. State your reason for terminating the iteration (converged in or function of the value lf(z) > 10 ”). . Solutions which compute discontinuities other than the second, fourth and sixth will receive a score o f zero. reason for terminatOI final answer in r or (f()>Explanation / Answer
Code for finding the bracket of root(first 6):
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <cmath>
using namespace std;
#define PI 3.14159265
double val(double x)
{
double sum =0.0 ;
for( double i=0;i<20;i++)
{
sum += cos(double(x*sin(double(i*PI/20))));
}
sum = sum/20;
return sum;
}
int main()
{
int count =0;
double f = 4; // base
double s = 1; //base
double start = 0;
double end = 0.1;
while ( count < 6 && abs(f) <= 1000000 ) {
double v1 = val(start);
double v2 = val(end);
double v3 = (5-(1/v1));
double v4 = (5-(1/v2));
if((v3 >=0 && v4 <= 0) || (v3<=0 && v4 >=0)) // if S(x) have different sign in the goven bracket
{
if((v1 >=0 && v2 <= 0) || (v1<=0 && v2 >=0)) // if f(x) have different sign in the given bracket
{
cout << endl;
//cout << " infinite value attained "<< endl; // returnn the bracket of infinite value
}
else
{
count++;
cout<< count << " domain found " << start << " " << end << endl ; // return the bracket of root of function
}
}
start = end;
end = end + 0.1;
}
return 0;
}
Code for finding the discontinuities of f (first 6):
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <cmath>
using namespace std;
#define PI 3.14159265
double val(double x)
{
double sum =0.0 ;
for( double i=0;i<20;i++)
{
sum += cos(double(x*sin(double(i*PI/20))));
}
sum = sum/20;
return sum;
}
int main()
{
int count =0;
double f = 4; // base
double s = 1; //base
double start = 0;
double end = 0.1;
while ( count < 6 && abs(f) <= 1000000 ) {
double v1 = val(start);
double v2 = val(end);
double v3 = (5-(1/v1));
double v4 = (5-(1/v2));
if((v3 >=0 && v4 <= 0) || (v3<=0 && v4 >=0)) // if S(x) have different sign in the goven bracket
{
if((v1 >=0 && v2 <= 0) || (v1<=0 && v2 >=0)) // if f(x) have different sign in the given bracket
{
count++;
cout<< count << " domain found " << start << " " << end << endl ; // return the bracket of root of function
//cout << " infinite value attained "<< endl; // returnn the bracket of infinite value
}
}
start = end;
end = end + 0.1;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.