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, H, acc, delta, X[100], Y[100], derY1[100], derY2[100], derAppY1[100], derAppY2[100], pogr1[100], pogr2[100], inSredn, inTrap, inX[100], inY[100];
- int i, j, k, m, step, tochnost;
- void main(void)
- {
- const a=4;
- const b=7;
- 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; //kol-vo otrezkov
- for (i=0; i<=k; i++)
- {
- X[i]=a+i*h;
- Y[i]=exp(X[i])/pow(X[i],3)-pow(sin(X[i]),3);
- }
- //nachojdenie pervoi proizvodnoi
- for (i=0; i<=k; i++)
- {
- derY1[i]=( exp(X[i])*(X[i]-3)-3*pow(X[i],4)*pow(sin(X[i]),2)*cos(X[i]) )/pow(X[i],4);
- }
- cout<<"k-1 der1y:";
- printf("%10.10f\n",derY1[k-1]);
- derAppY1[0]=-(3*Y[0]-4*Y[1]+Y[2])/(2*h); //nachalo intervala
- derAppY1[k]=(Y[k-2]-4*Y[k-1]+3*Y[k])/(2*h); //konecs intervala
- for (i=1; i<k; i++)
- {
- derAppY1[i]=(Y[i+1]-Y[i-1])/(2*h);
- }
- //nachojdenie vtoroi proizvodnoi
- for (i=0; i<=k; i++)
- {
- derY2[i]=(3*pow(X[i],5)*pow(sin(X[i]),3)-6*pow(X[i],5)*sin(X[i])*pow(cos(X[i]),2)+exp(X[i])*(pow(X[i],2)-6*X[i]+12))/pow(X[i],5);
- }
- for (i=1; i<k; i++)
- {
- derAppY2[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(derAppY1[i]));
- pogr2[i]=fabs(fabs(derY2[i])-fabs(derAppY2[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",X[i],Y[i],derY1[i],derAppY1[i],pogr1[i],derY2[i],derAppY2[i],pogr2[i]);
- }
- //=========================================================|
- //==Integrirovanie--fynkcsii===============================|
- //=========================================================|
- //formyla_srednich
- m=20;
- do
- {
- inSredn=inTrap=0;
- H=double(b-a)/m;
- for (i=0; i<m; i++)
- {
- inX[i]=a+i*H;
- inY[i]=exp(inX[i])/pow(inX[i],3)-pow(sin(inX[i]),3);
- }
- for (i=1; i<=m; i++)
- {
- inSredn+=H*((inY[i]+inY[i-1])/2);
- }
- inTrap=H*(inY[0]+inY[m])/2;
- for (i=1; i<m-1; i++)
- {
- inTrap+=H*inY[i];
- }
- //cout<<inTrap<<" "<<inSredn;
- m=2*m;
- cout<<inSredn<<" "<<inTrap<<endl;
- acc=fabs(fabs(inSredn)-fabs(inTrap));
- }
- while(acc>=delta);
- cout<<"================================="<<endl;
- cout<<m<<" "<<H<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement