Need help on #3 only. Will rate 3. Let g(x)- + Write a program (using Matlab/Oct
ID: 3590573 • Letter: N
Question
Need help on #3 only. Will rate
3. Let g(x)- + Write a program (using Matlab/Octave or C/C++) that inplenents fixed point iteration as discussed in class (i.e., do not use any built-in fixed point iteration functions, if they are available). If you like, your code may assume that the fixed point iteration will converge quadratically. Run your program using p0 1.5 and 10-6 What was the final p(n) value (include what value of n it was)? What was the final e( n 1) approximation (including what value of n it was)? Use 9 significant figures for your answers. Hint. Since e( n- 1 ) = abs( p( n ) -p( n- 1 ) ); can only be calculated for n >= 2, you can use an if statement in your loop so that you only approximate the error just set the error approximate to, for example, 10. 4. Let f(z) 25. a) Find the corresponding fixed point function g(x) for Newton's Method. b) Starting with the initial guess Po = 2.5, run Newton's Method by hand to complete the following table. Keep as many digits of precision as you calculator (or program if you write one!) gives (hopefully at least 8) in intermediate calculations and from one iteration to the next, but round to 7 significant figures (which will mean 6 digits after the decimal) when filling in the table to turn in. nPn 0 2.5Explanation / Answer
#include <iostream>
#include <cmath>
using namespace std;
class FixedPoint
{
public:
void askEqn();
double g(double x);
void solve();
void findError();
void askX0();
void display();
private:
double a,b,c;
double Error;
double x0,x1;
};
void FixedPoint::askX0()
{
cout << "Enter initial value of X0: ";
cin >> x0;
}
void FixedPoint::askEqn()
{
cout << "For the eqn ax*x + bx + c = 0 , Enter a,b,c,d: ";
cin >>a>>b>>c;
}
double FixedPoint::g(double x)
{
return -(a*x*x + c) / b;
}
void FixedPoint::findError()
{
Error = fabs( (x1-x0)/x1 );
}
void FixedPoint::solve()
{
askEqn();
askX0();
cout << endl << endl << "S.N. Xi Xi+1 Error ";
do{
x1 = g(x0);
findError();
display();
x0 = x1;
}while(Error>=0.0009);
cout << endl<< "The root is : " << x1 << endl;
}
void FixedPoint::display()
{
static int i;
cout << ++i << " " << x0 << " " << x1 << " " << Error << endl;
}
int main()
{
FixedPoint f1;
f1.solve();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.