Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Metodos 2- programa3
//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(); } int programa3(){ int t; vector<double> x; vector<double> fx; double d1, d2, h; //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); } int diferencias(vector<double> x,vector<double> fx ,int t){ vector<double> dif,dif2; double d1, d2, 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"; } int integral(vector<double> x,vector<double> fx ,int t){ double suma=0,a,b,h,suma2=0; int lim_sup, lim_inf; 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[0]; suma=suma+fx[t-1]; for(int i=1; i<t-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[0]; suma=suma+fx[t-4]; for(int i=1; i<t-4; i++){ if(i%2!=0) suma=suma+4*fx[i]; if(i%2==0) suma=suma+2*fx[i]; } suma=suma*(h/3); suma2=suma2+fx[t-4]; suma2=suma2+fx[t-1]; suma2=suma2+3*(fx[t-3]+fx[t-2]); suma2=suma2*((3*h)/8); suma=suma+suma2; }cout<<"------------------------\n"; cout<<"|x |"<<"f(x) |\n"; cout<<"-------------------------\n"; for(int i=0; i<t; i++){ cout<<"|"<<x[i]<<" |"<<fx[i]<<" |\n"; } cout<<"--------------------------\n"; cout<<""<<suma<<"\n"; }
run
|
edit
|
history
|
help
0
simple serialization
C++ User Input #1
LIS
replace-30-Seconds-of-C++
1
Lazy String Tokenizer Class
SpiralMatrix
project: bank account
epsilon
dsu on tree (http://codeforces.com/contest/208/problem/E)