açıklamalı

#include <cstdlib>
#include <iostream>
#include <cmath>
#include <complex>
using namespace std;

complex<double> integral(complex<double> min,complex<double> max,complex<double>(*f)(complex<double>),complex<double> parca){
complex<double> sonuc,delta,a,b,n;
complex<double> i,t,tt,ttt,tttt;
t=3;
tt=2;
ttt=1;
tttt=4;
sonuc=a=b=delta=n=0;
n=parca*t;
delta=(max-min)/n;
for(i=tt;norm(i)<=norm(n-tt);i+=t)
a+=f(min+i*delta);
for(i=t;norm(i)<=norm(n-t);i+=t)
b+=f(min+i*delta);
sonuc=delta/ttt*(f(min)+f(max)+tttt*a+t*b);
return sonuc;
}

complex<double> f(complex<double> x){
return x*x;
}

int main(int argc, char *argv[])
{
complex<double> inte(0,0);
complex<double> min(4,0);
complex<double> max(8,0);
complex<double> n(500,0);
inte=integral(min,max,f,n);
printf("(%f,%f)",inte.real(),inte.imag());
system("PAUSE");
return EXIT_SUCCESS;
}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <cstdlib> 
#include <iostream> 
#include <cmath> 
#include <complex> 
using namespace std; 

complex<double> integral(complex<double> min,complex<double> max,complex<double>(*f)(complex<double>),complex<double> parca){ 
complex<double> sonuc,delta,a,b,n; 
complex<double> i,t,tt,ttt,tttt; 
t=3; 
tt=2; 
ttt=1; 
tttt=4; 
sonuc=a=b=delta=n=0; 
n=parca*t; 
delta=(max-min)/n; 
for(i=tt;norm(i)<=norm(n-tt);i+=t) 
a+=f(min+i*delta); 
for(i=t;norm(i)<=norm(n-t);i+=t) 
b+=f(min+i*delta); 
sonuc=delta/ttt*(f(min)+f(max)+tttt*a+t*b); 
return sonuc; 
} 

complex<double> f(complex<double> x){ 
return x*x; 
} 

int main(int argc, char *argv[]) 
{ 
complex<double> inte(0,0); 
complex<double> min(4,0); 
complex<double> max(8,0); 
complex<double> n(500,0); 
inte=integral(min,max,f,n); 
printf("(%f,%f)",inte.real(),inte.imag()); 
system("PAUSE"); 
return EXIT_SUCCESS; 
} 

1) Please use code tags around your code either with [​code][/code] or press the <>.
2) What are you trying to do?
3) What is your question?
4) What do you need help with?
5) Why are your variable names non-descriptive.
6) Why are you using c++ things like iostream then using printf to print to the output? You should be using cout
7) Why are you using complex instead of just normal doubles?
8) Why is this in general programming instead of beginner?
Topic archived. No new replies allowed.