Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma warning(disable:4996)
- #include <stdio.h>
- #include <conio.h>
- #include <stdlib.h>
- #include <iostream>
- #include <string>
- #include <math.h>
- #include <cmath>
- using namespace std;
- double func1(double x) {
- return x*exp(x) - 1;
- }
- double func2(double x) {
- double xderiv = x;
- return (xderiv + 1)*exp(x);
- }
- void main() {
- double epsilon;
- double x, ITMAX;
- int n = 1;
- x = 0;
- epsilon = 0.001;
- ITMAX = 100;
- while ( (fabs(x*exp(x)-1) > epsilon ) && (n <= ITMAX)) {
- x = x - (func1(x) / func2(x));
- n = n + 1;
- }
- if (n > ITMAX) {
- cout << "In" << ITMAX << " iteratii nu a fost realizata aproximarea dorita";
- }
- else {
- cout << "Aproximarea obtinuta este: " << x;
- }
- _getche();
- }
- //#####################################################################################
- #pragma warning(disable:4996)
- #include <stdio.h>
- #include <conio.h>
- #include <stdlib.h>
- #include <iostream>
- #include <string>
- #include <math.h>
- #include <cmath>
- using namespace std;
- #define func
- void main() {
- double a=2,x=2,epsilon=0.001,ITMAX=100;
- double p=2;
- int n = 1;
- while (fabs(pow(x,p)-a) > epsilon && n <= ITMAX) {
- x = (1 / p) * ((p - 1)*x + a / (pow(x, p - 1)));
- n = n + 1;
- }
- if (n > ITMAX) {
- cout << "In" << ITMAX << "iteratii nu a fost realizata aproximarea dorita";
- }
- else {
- cout << "Aproximarea obtinuta este: " << x;
- }
- _getche();
- }
- //##############################################################################################
- #pragma warning(disable:4996)
- #include <stdio.h>
- #include <conio.h>
- #include <stdlib.h>
- #include <iostream>
- #include <string>
- #include <math.h>
- #include <cmath>
- using namespace std;
- double func(double x) {
- double xx = x;
- return xx*exp(xx) - 1;
- }
- void main() {
- double x,x_0, x_1, epsilon, ITMAX;
- int n;
- n = 2;
- epsilon = 0.001;
- x = x_0 = 0;
- x_1 = 1;
- ITMAX = 100;
- while (fabs(func(x_1)) > epsilon && n <= ITMAX) {
- x = x_1 - ((func(x_1)*(x_1 - x_0)) / (func(x_1) - func(x_0)));
- x_0 = x_1;
- x_1 = x;
- n = n + 1;
- }
- if (n > ITMAX) {
- cout << "in" << ITMAX << "iteratii nu a fost realizata aproximarea dorita";
- }
- else {
- cout << "Aproximarea obtinuta este:" << x;
- }
- _getche();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement