Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- double a,b,c,eps,c1, e, x, m, M,x1;
- int i,n,k;
- bool u;
- double f (double x)
- {
- return pow(x,4)-2*pow(x,2)-3;
- }
- double f1(double x){
- return 4*pow(x,3)-4*x;
- }
- void tang(double a, double b, double eps, double m1, double m2) {
- int k5=0;double x,x1,c=0;
- c = (a * f(b) - b * f(a))/(f(b)-f(a));
- if (f(a)*f(c)>0) { x = b;
- } else { x = a;
- }
- do {
- x1=x;
- x = x1 - f(x1)/f1(x1);
- k5++;
- }while(((m1*pow((x-x1),2))/(2*m2))>=eps);
- cout << " c : " << fixed << setprecision(15) << x << " f(c) : " << fixed << setprecision(15) << f(x) << " n : " << k5 << endl;
- }
- int main(){
- a=-2; b=-1;
- cout<<"a : "<<a<<" "<<" b : "<<b<<endl;
- m=pow(10,-15);
- eps=pow(10,-15);
- cout<<"tangenta aposteriori"<<endl;
- tang(a,b,eps,44,m);
- int a=1,b=2;
- cout<<"a : "<< a<<" "<<" b : "<<b<<endl;
- cout<<"tangenta aposteriori"<<endl;
- //tang(1.5,b,eps,44,7.5);
- m=pow(10,-15);
- tang(a,b,eps,44,m);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement