Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Programa 3 (corregido)
//g++ 5.4.0 #include<math.h> #include <iostream> #include <iomanip> #include<stdlib.h> #include<stdio.h> #include<vector> using namespace std; int programa3(); int diferencias(vector<double>,vector<double>,int); int integral(vector<double>,vector<double>,int); int llenar_dat(vector<double>,vector<double>,int); int main() { cout<<fixed<<setprecision(6); programa3(); return 0; } int programa3(){ int t; vector<double> x; vector<double> fx; double d1, d2; //Lectura de los datos x.clear(); fx.clear(); cin>>t; x.resize(t); fx.resize(t); for(int i=0; i<t; i++){ cin>>d1; cin>>d2; x[i]=d1; fx[i]=d2; } integral(x,fx,t); diferencias(x,fx,t); return 0; } int diferencias(vector<double> x,vector<double> fx ,int t){ vector<double> dif,dif2; double h, a, b; cout<<"\nDiferenciacion numerica\n\n"; cin>>a;//Primer dato del intervalo cin>>b;//Segundo dato del intervalo dif.clear(); dif2.clear(); dif.resize(t); dif2.resize(t); h=x[1]-x[0]; for(int i=1; i<t-1; i++){ dif[i]=(fx[i+1]-fx[i-1])/(2*h); dif2[i]=(fx[i+1]-2*fx[i]+fx[i-1])/(h*h); } cout<<"-----------------------------------------\n"; cout<<"|x |"<<"f(x) |"<<"f'(x) |"<<"f''(x) |"<<"\n"; cout<<"-----------------------------------------\n"; for(int i=0; i<t; i++){ cout<<"|"<<x[i]<<" |"<<fx[i]<<" |"; if(x[i] >= a and x[i] <= b) cout<<dif[i]<<" |"<<dif2[i]<<"|\n"; else cout<<" | |\n"; } cout<<"-----------------------------------------\n"; return 0; } int integral(vector<double> x,vector<double> fx ,int t){ double suma=0,a,b,h,suma2=0; int lim_sup=0, lim_inf=0; bool normal=true; cout<<"\nIntegracion numerica\n\n"; cin>>a;//Primer dato del intervalo cin>>b;//Segundo dato del intervalo h=x[1]-x[0]; for(int i=0; i<t; i++){ if(a==x[i]) lim_inf=i; if(b==x[i]) lim_sup=i; } if(!((lim_inf-lim_sup)%2==0)) normal=false; if(normal){ suma=suma+fx[lim_inf]; suma=suma+fx[lim_sup-1]; for(int i=lim_inf+1; i<lim_sup-1; i++){ if(i%2!=0) suma=suma+4*fx[i]; if(i%2==0) suma=suma+2*fx[i]; } suma=suma*(h/3); } else{ suma=suma+fx[lim_inf]; suma=suma+fx[lim_sup-3]; for(int i=lim_inf+1; i<lim_sup-3; i++){ if(i%2!=0) suma=suma+4*fx[i]; if(i%2==0) suma=suma+2*fx[i]; } suma=suma*(h/3); cout<<fx[lim_sup-3]; suma2=suma2+fx[lim_sup-3]; suma2=suma2+fx[lim_sup]; suma2=suma2+3*(fx[lim_sup-2]+fx[lim_sup-1]); suma2=suma2*((3*h)/8); suma=suma+suma2; }cout<<"------------------------\n"; cout<<"|x |"<<"f(x) |\n"; cout<<"-------------------------\n"; for(int i=lim_inf; i<lim_sup; i++){ cout<<"|"<<x[i]<<" |"<<fx[i]<<" |\n"; } cout<<"--------------------------\n"; cout<<""<<suma<<"\n"; return 0; }
run
|
edit
|
history
|
help
0
F-Random Strings
typedef 2
Inventory
დიოფანტეს განტოლება
find-missing-number-arithmetic-progression
12535
str_to_int
MinCostKStops_DFS
шаблонизированное наследование
figa gratis