Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream.h>
- #include <iomanip.h>
- #include <math.h>
- #include <stdio.h>
- #include <stdlib.h>
- double h, acc, H, delta, Y[100], derY1[100], derY2[100], derApp1Y[100], derApp2Y[100], pogr1[100], pogr2[100], inSredn, inTrap, inX[100], inY[100], inYsr[100], inXsr[100] ;
- int i, j, k, step, tochnost;
- int m;
- int a=4;
- int b=7;
- //======================================================|
- double Function(double x)
- {
- double F=0;
- F=exp(x)/pow(x,3)-pow(sin(x),3);
- return F;
- }
- double Derivative1(double x)
- {
- double k=(b-a)/h;
- double FD1;
- FD1=(exp(x)*(x-3)-3*pow(x,4)*pow(sin(x),2)*cos(x))/pow(x,4);
- return FD1;
- }
- double Derivative2(double x)
- {
- double k=(b-a)/h;
- double FD2;
- FD2=(3*pow(x,5)*pow(sin(x),3)-6*pow(x,5)*sin(x)*pow(cos(x),2)+exp(x)*(pow(x,2)-6*x+12))/pow(x,5);
- return FD2;
- }
- /*double Srednie (double x, int m)
- {
- // double x;
- double inSredn=0;
- for (i=0; i<m; i++)
- {
- // x=a+H*(i-0.5);
- inSredn+=H*Function(x);
- }
- return inSredn;
- }
- double Trapecsii(double x, int m)
- {
- // double x;
- double inTrap=0;
- for (i=0; i<m; i++)
- {
- // x=a+H*i;
- inTrap+=H*Function(x);
- }
- return inTrap;
- }*/
- //======================================================|
- void main(void)
- {
- cout<<"Viberite shag differencsirovaniya: \n"<<"1) h=0.2\n"<<"2) h=0.1\n"<<"3) h=0.05\n";
- cin>>step;
- switch (step)
- {
- case 1:
- h=0.2; break;
- case 2:
- h=0.1; break;
- case 3:
- h=0.05; break;
- default:
- cout<<"Vibrano nevernoe znachenie!\n";
- }
- cout<<"Viberite tochnost' defferencsirovaniya: \n"<<"1) delta=0.1\n"<<"2) delta=0.01\n"<<"3) delta=0.001\n";
- cin>>tochnost;
- switch (tochnost)
- {
- case 1:
- delta=0.1; break;
- case 2:
- delta=0.01; break;
- case 3:
- delta=0.001; break;
- default:
- cout<<"Vibrano nevernoe znachenie!\n";
- }
- //--Differencsirovanie--fynkcsii------------------------|
- k=(b-a)/h;
- for (i=0; i<=k; i++)
- {
- double x=a+h*i;
- Y[i]=Function(x);
- }
- //__1-ya__proizvodnaya_______________________________|
- for (i=0; i<=k; i++)
- {
- double x=a+h*i;
- derY1[i]=Derivative1(x);
- }
- derApp1Y[0]=-(3*Y[0]-4*Y[1]+Y[2])/(2*h); //nachalo intervala
- derApp1Y[k]=(Y[k-2]-4*Y[k-1]+3*Y[k])/(2*h); //konecs intervala
- for (i=1; i<k; i++)
- {
- derApp1Y[i]=(Y[i+1]-Y[i-1])/(2*h);
- }
- //__2-ya__proizvodnaya________________________________|
- for (i=0; i<=k; i++)
- {
- double x=a+h*i;
- derY2[i]=Derivative2(x);
- }
- for (i=1; i<k; i++)
- {
- derApp2Y[i]=(Y[i-1]-2*Y[i]+Y[i+1])/pow(h,2);
- }
- //__Pogreshnost'______________________________________|
- for (i=0; i<=k; i++)
- {
- pogr1[i]=fabs(fabs(derY1[i])-fabs(derApp1Y[i]));
- pogr2[i]=fabs(fabs(derY2[i])-fabs(derApp2Y[i]));
- }
- //__Vivod__Tablicsi___________________________________|
- printf("X\tY\tder1Y\tderA1Y\tpogr1\tder2Y\tderA2Y\tpogr2\n");
- for (i=0; i<=k; i++)
- {
- printf("%2.2f\t%4.3f\t%4.3f\t%4.3f\t%5.4f\t%4.3f\t%4.3f\t%5.4f\n",a+i*h,Y[i],derY1[i],derApp1Y[i],pogr1[i],derY2[i],derApp2Y[i],pogr2[i]);
- }
- //========================================================|
- //=Integrirovanie--fynkcsii===============================|
- //========================================================|
- m=2;
- do
- {
- inSredn=inTrap=0;
- H=double(b-a)/m;
- double x1, x2;
- for (i=1; i<=m; i++)
- {
- x1=a+H*(i-0.5);
- inSredn+=H*Function(x1);
- }
- inTrap=H*((Function(a)+Function(b))/2);
- for (i=1; i<m-1; i++)
- {
- x2=a+H*i;
- inTrap+=H*Function(x2);
- }
- m=2*m;
- acc=fabs(fabs(inTrap)-fabs(inSredn));
- cout<<"Sredn="<<inSredn<<" "<<"Trap="<<inTrap<<endl;
- }
- while (acc>=delta);
- cout<<m<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement