Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///***************Solve a fixed quadratic equation using Aitkenβs Delta-Squared Process***************///
- ///** a = 4; b = 6; c = -1 **///
- ///** Equation: 4x^2 + 6x - 1 = 0 **///
- ///** x1 = 0.151388 ; x2 = -1.65139 **///
- #include<iostream>
- #include<cmath>
- #define ESP 0.000001
- using namespace std;
- int main()
- {
- double x1, x2, x3, x4, y;
- //First Value
- cin >> x1 >> x2 >> x3;
- #define F(x) (x2-x1*x*x)/x3
- //#define F(x) (1-4*x*x)/6
- x1 = 1; //Initial Value
- for (int i=1; ; i=i+3)
- {
- x2 = F(x1);
- x3 = F(x2);
- if(fabs(x3-x2) < ESP)
- {
- cout << "First Value: " << x3 << endl;
- break;
- }
- else
- {
- y = x3-2*x2+x1;
- x1 = x3-(((x3-x2)*(x3-x2))/y);
- }
- }
- //Second Value
- //cin >> x1;
- x1 = 2; //Initial Value
- for (int i=1; ; i=i+3)
- {
- x2 = F(x1);
- x3 = F(x2);
- if(fabs(x3-x2) < ESP)
- {
- cout << "Second Value: " << x3 << endl;
- break;
- }
- else
- {
- y = x3-2*x2+x1;
- x1 = x3-(((x3-x2)*(x3-x2))/y);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement