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, Y[100], dY1[100], dY2[100], dA1Y[100], dA2Y[100], pog1[100], pog2[100], inY1, inY2, Int, pogInt;
- int i, k, shag, otrezki;
- int m;
- int a=5;
- int b=8;
- //======================================================|
- double Fun(double x)
- {
- double F=0;
- F=pow(x,0.5)-pow(cos(x),2);
- return F;
- }
- double D1(double x)
- {
- double k=(b-a)/h;
- double Diff1;
- Diff1=1/(2*pow(x,0.5))+sin(2*x);
- return Diff1;
- }
- double D2(double x)
- {
- double k=(b-a)/h;
- double Diff2;
- Diff2=2*cos(2*x)-1/(4*pow(x,1.5));
- return Diff2;
- }
- //======================================================|
- void main(void)
- {
- cout<<"Viberite shag differencsirovaniya: \n"<<"1) h=0.2\n"<<"2) h=0.1\n"<<"3) h=0.05\n";
- cin>>shag;
- switch (shag)
- {
- 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 chislo shagov integrirovaniya: \n"<<"1) m=10\n"<<"2) m=20\n"<<"3) m=40\n";
- cin>>otrezki;
- switch (otrezki)
- {
- case 1:
- m=10; break;
- case 2:
- m=20; break;
- case 3:
- m=40; 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]=Fun(x);
- }
- //__1-ya__proizvodnaya__|
- for (i=0; i<=k; i++)
- {
- double x=a+h*i;
- dY1[i]=D1(x);
- }
- dA1Y[0]=-(3*Y[0]-4*Y[1]+Y[2])/(2*h); //nachalo intervala
- dA1Y[k]=(Y[k-2]-4*Y[k-1]+3*Y[k])/(2*h); //konecs intervala
- for (i=1; i<k; i++)
- {
- dA1Y[i]=(Y[i+1]-Y[i-1])/(2*h);
- }
- //__2-ya__proizvodnaya__|
- for (i=0; i<=k; i++)
- {
- double x=a+h*i;
- dY2[i]=D2(x);
- }
- for (i=1; i<k; i++)
- {
- dA2Y[i]=(Y[i-1]-2*Y[i]+Y[i+1])/pow(h,2);
- }
- //__Pogreshnost'__|
- for (i=0; i<=k; i++)
- {
- pog1[i]=fabs(dY1[i]-dA1Y[i]);
- pog2[i]=fabs(dY2[i]-dA2Y[i]);
- }
- //__Vivod__Tablicsi__|
- cout<<"=============================================================="<<endl;
- printf("X\tY\td1Y\tdA1Y\tpog1\td2Y\tdA2Y\tpog2\n");
- cout<<"______________________________________________________________"<<endl;
- 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],dY1[i],dA1Y[i],pog1[i],dY2[i],dA2Y[i],pog2[i]);
- }
- //=Integrirovanie--fynkcsii===============================|
- inY1=inY2=0;
- H=double(b-a)/m;
- double x1, x2;
- for (i=1; i<=m; i++)
- {
- x1=a+H*(i-0.5)+(h/2)*0.5773502692;
- inY1+=(H/2)*Fun(x1);
- }
- for (i=1; i<=m; i++)
- {
- x2=a+H*(i-0.5)-(h/2)*0.5773502692;
- inY1+=(H/2)*Fun(x2);
- }
- Int=inY1+inY2;
- pogInt=fabs(6.067-Int);
- cout<<"=============================================================="<<endl;
- cout<<"Znachenie integrala="<<Int<<endl;
- cout<<"Tochnoe znachenie integrala=6.067"<<endl;
- cout<<"=============================================================="<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement