write a c++ program that can solve problems using the secant method
Question : write a c++ program that can solve problems using the secant method
ANSWER : secant method is a root-finding algorithm.
Algorithm :
1) Enter the values of initial guesses, a and b.
2) Enter the value of the tolerance error, e (accuracy)
3) Repeat
set a = b
set b = c
set c = b-f(b)*(a-b)/(f(a)-f(b))
until |cn-c|<Tolerance value (e)
4) Print 'C', tne root in the interval [a,b].
Program :
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
double f(double x); //declare the function for the given
equation
double f(double x) //declare the function for the given
equation
{
double a=pow(x,3)-x-11.0; //write the equation whose roots are to
be determined
return a;
}
int main()
{
cout.precision(4);
cout.setf(ios::fixed); //set the precision of the output
double a,b,c,e;
cout<<"Enter the initial guess: \na = ";
cin>>b;
cout<<"b = ";
cin>>c;
cout<<"Enter the degree of accuracy\n";
cin>>e; //take the desired accuracy
do
{
a=b;
b=c;
c=b-(b-a)/(f(b)-f(a))*f(b); //calculate c
if (f(c)==0)
{
cout<<"\nThe root of the equation is "<<c; //print the
root
return 0;
}
}while(abs(c-b)>=e); //check if the error is greater than the
desired accuracy
cout<<"\nThe root of the equation is "<<c; //print the
root
return 0;
}
OUTPUT :
Using Python please Problem 3 (15 pts): Using the Secant Method, for A>0, (10 pts) Write a program which finds A/m for any positive value m. Note, you need to choose a function f(r) for the Secant Method whose root is A1 'm. (5 pts) How does your choice of m effect how many iterations your program takes to converge for a given tolerance choice? Plots will help me to understand your thinking here In [11]: #present your program for...
JAVA programming: Construct a computer program that uses the Secant Method to solve the problem: fox)cos(3.0)- 1.0/20.00 Starting with the initial guesses of x 2 and x- 3, obtain an approximation to x such that fx)<0.000000001. On your output, show the iteration number (n), the approximate value of x on the nth iteration (xn), and the value of fxn Show the values to 9 or 10 digits. -0.5
Write a matlab program to implement the secant root finding method in matlab. The function name should be Secant and it should take the equation as input whoes root has to be found and the two initial values of a and b and maximum tolerable error. Consider the following example: Your code should generate the following: >> secantAssg5(@(x)(x^4+x^2+x+10),2,3,0.0001) Xn-1 f(Xn-1) Xn f(Xn) Xn+1 f(Xn+1) 2.0000 32.0000 3.0000 103.0000 1.5493 19.7111 ….. ….. ….. Root is x = 0.13952 ans...
Can you help me with parts A to D please? Thanks 3 Newton and Secant Method [30 pts]. We want to solve the equation f(x) 0, where f(x) = (x-1 )4. a) Write down Newton's iteration for solving f(x) 0. b) For the starting value xo 2, compute x c) What is the root ξ of f, i.e., f(5) = 0? Do you expect linear or quadratic order of convergence to 5 and why? d) Name one advantage of Newton's...
please use matlab only COMPUTER PROBLEMS 8.6 1. Write a computer program to solve this initial-value problem using the Taylor-series method. Include terms in h, h2, and h and continue the solution tor 1. Let h 0.01 x1 = t + x1+x2 i xd-1)=0.43 avl COMPUTER PROBLEMS 8.6 1. Write a computer program to solve this initial-value problem using the Taylor-series method. Include terms in h, h2, and h and continue the solution tor 1. Let h 0.01 x1 =...
using c++ program please solve all of the following in a simple method with showing the steps as a code . Q.15 Write a C++ program to define two variables and initialize them with the values 123.456 and 76.543 Then display the sum and the difference of these two numbers on screen. The display will be: Sum = value of the sum Difference = value of the difference
Can someone help me with these C program problems? Thanks 1. Write a C program that creates two arrays of integers, one on the stack and one on the heap. You will loop through these arrays and populate them with values (any value is fine). You will then loop through these arrays again and print each value. Your output should look something like “Value in index 1 is 100 from stack array and 100 from heap array.” Do not forget...
1. (30 points) Write a MATLAB code to perform the Secant method of root finding. Write the code to output the table used in class showing the iteration, root estimate r,, function value at the root estimate f(r,), and the approximate error. Show that the code works by using it to re-solve Homework Assignment II Problem 2c. Which asked you to find the positive root of f(r) r,1.0 and 6 10-6, have the code iterate until the approximate error is...
Need to be solved in c# Write the program using the method that calculates the cube of numbers from 1 to 9 that comes as a parameter to it as a series.
find the root(s) of the following functions using both Newton's method and the secant method, using tol = eps. 3 Find the root s of the following functions using both Newton's ulethod and the anat inethod using tol epa. . You will vood to experiment with the parameters po, pl, ad maxits. . For each root, visualize the iteration history of both methods by plotting the albsolute errors, as a function . Label the two curves (Newton's method and secaut...