Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<math.h>
- #define ITMAX 100
- using namespace std;
- double error = 0.0001;
- double f1(double x)
- {
- return x * exp(x)-1;
- }
- double f2(double x)
- {
- return exp(x) + x * exp(x);
- }
- double modul(double a)
- {
- if(a < 0)
- {
- a *= -1;
- }
- return a;
- }
- double a = 2;
- int p = 2;
- int main()
- {
- int n = 1;
- double x = 2;
- /*EX 1
- while(modul(f1(x)) > error && n <= ITMAX)
- {
- Ex 1
- x = x-(f1(x)/f2(x));
- n = n+1;
- }
- */
- /*EX 2 */
- while(fabs(pow(x, p) - a) > error && n <= ITMAX)
- {
- //x = (1.0/p * ((p-1) * x + (a/pow(x, p-1))));
- x = ((p-1) * x + (a/pow(x, p-1)))/p;
- n = n+1;
- }
- if(n > ITMAX)
- {
- cout<<endl<<"In "<<n<<" iteratii nu a fost realizata aproximarea dorita";
- }
- else
- {
- cout<<endl<<"Aproximarea dorita este "<<x;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement