C++ Programming
determine the roots of the equation with errors of less than 0.1%
for x values between -5 and 5. you MUST NOT use the "if" statement
in your code.

Copy pastable code :
#include <iostream>
#include<cmath>
using namespace std;
double f(double x)
{
return (0.2 + sin(x)*sin(x))/(1+cos(x)*log10(x+20));
}
int main()
{
double x = -5;
double value;
double step = 0.2;
double arr[100];
int i =0;
while(abs(x)<5){
value = f(x);
switch (abs(value)<0.1){
case true :
arr[i] = x;
i+=1;
break;
}
x+=step;
}
switch (i>0){
case true:
cout<<"Root is near : ";
for(int j = 0; j<i ; j++){
cout<<arr[j]<<", ";
}
break;
case false:
cout<<"No root found";
}
cout<<endl;
}
Code Snippet :

Output of the code :

C++ Programming determine the roots of the equation with errors of less than 0.1% for x...
Java Programming Question. I am writing a code to calculate the roots of the quadratic equation based on the values of the coefficients A, B, and C. I am supposed to enter 5 values for each coefficient, and the output should be five different answers (see example) using a for loop and if else statements. However, when I run my code, I am only able to enter one value for each coefficient and the output is one answer repeated five...
Use Bairstow’s method to determine the roots of (a) f(x) = -2 + 6.2x -4x^2 + 0.7x^3 b) f(x) = 9.34 - 21.97x +16.3x^2- 3.704x^3 (c) f(x) = x^4- 2x^3 + 6x^2- 2x + 5 I need the the solution for above equation in excel programming.
The following procedure can be used to determine the roots of a cubic equation a_3x^3 + a_2x^2 + a_1x + a_0 = 0: Set: A =a_2/a_3, B = a_1/a_3, and C = a_0/a_3 Calculate: D = Q^3 + R^2 where Q = (3B - A^2)/9 and R = (9AB - 27C - 2A^3)/54. If D > 0, the equation has complex roots. It D = 0, all roots are real and at least two are equal. The roots are given...
C programming!!C programming!!C programming!!C programming!!C programming!! C programming!!C programming!!C programming!!C programming!!C programming!! C programming!!C programming!!C programming!!C programming!!C programming!! Q2 (20 marks): remembering state, conditions, functions Write a function that takes two arguments an array and the size of the array and returns a count of all of the numbers between 2 and 5 inclusive. The code below shows how your function will be called. int main(void) { int values[6]={1,2,4,5,3,6}; int size=6; printf("There are %d values between 2 and 5 (inclusive)\n",...
Using matlab and if/else statement please!
Write a function that determines the real roots of a quadratic equation ax2 + bx + c = 0. To calculate the roots of the equation, the function calculates the discriminant D, given by: D = b2-4ac If D> 0, the code should display "The equation has two roots" and print the values on a new line. If D 0, the code should display "The equation has one root.", and print the value on...
Please Solve in C programming. Please Use “ f(x) = e^(-x^2) “
for thus question.
Thank You
rite computer code in any programming language or mathematical software to estimate he following derivatives. Then calculate the absolute and relative errors for each: I, f"(1.5) for f(z) in Question 3 above using the three-point formula. Use h 0.5
rite computer code in any programming language or mathematical software to estimate he following derivatives. Then calculate the absolute and relative errors for each:...
2. The roots of the quadratic $a x^2 + b x + c$ are given by $$\frac{-b \pm \sqrt{b^2-4ac}}{2a}$$ If $b^2-4ac <0$, the quadratic has no real roots. Write a function to calculate the real roots of a quadratic. The function should have 3 arguments, *a*, *b* and *c*. If $b^2-4ac <0$, the function should print "quadratic has no real roots", and then return(NULL). Otherwise, the function should return a vector of length 2, those being the real roots (which...
#6 Write a Matlab program that finds numerically all the roots (or the zeros) of the algebraic equation below in the interval 1.0 <=x<=3.0: sqrt(log(x^2+1))=x^2*sin(e^x)+2 Part a) Prompt the user to enter a positive integer number n, defined the range 2<=n<=15, and then verify if the number entered lies within the specifications. Your program must allow the user to reenter the number without the need to rerun the program. Part b) Create a user-defined function for the bisection method(see details...
Need help with number 3, thanks!
isplays l itnuml is less than num2. 2. (50+30- 80 Points) Write a MATLAB function numcomp502 (numl, num2) that takes two numbers numl and as input and returns num3 as output, such that num3 is equal to 0, 1, and-1 depending on whether numl is equal to, greater than or less than num2 respectively. Test your code with the pairs (10, 5), (-3,-3), and (2, 10) as input. Attach a screen-shot. 3. 80 Points...
2) (15 points) a) Determine the roots of f(x)=-12 – 21x +18r? - 2,75x' graphically. In addition, determine the first root of the function with b) bisection and c) false-position. For (b) and (c), use initial guesses of x, =-land x, = 0, and a stopping criterion of 1%. 3) (25 points) Determine the highest real root of f(x) = 2x – 11,7x² +17,7x-5 a) Graphically, b) Fixed-point iteration method (three iterations, x, = 3) c) Newton-Raphson method (three iterations,...