PDA

توجه ! این یک نسخه آرشیو شده میباشد و در این حالت شما عکسی را مشاهده نمیکنید برای مشاهده کامل متن و عکسها بر روی لینک مقابل کلیک کنید : برنامه حل انتگرال توسط #c



M.A.H.S.A
08-01-2011, 10:31 AM
روش انتگرال گیری سیمپسون


//Simpson integration algorithm
using System;
//calculate the integral of f(x) between x=a and x=b by spliting the interval in step_number steps
class Integral
{
public delegate double Function(double x); //declare a delegate that takes and returns double
public static double integral(Function f,double a, double b,int step_number)
{
double sum=0;
double step_size=(b-a)/step_number;
for(int i=0;i<step_number;i=i+2) //Simpson algorithm samples the integrand in several point which significantly improves //precision.
sum=sum+(f(a+i*step_size)+4*f(a+(i+1)*step_size)+f (a+(i+2)*step_size))*step_size/3; //divide the area under f(x) //into step_number rectangles and sum their areas
return sum;
}
}

class Test
{
//simple functions to be integrated
public static double f1( double x)
{
return x*x;
}

public static double f2(double x)
{
return x*x*x;
}

public static void Main()
{//output the value of the integral.
Console.WriteLine(Integral.integral(new Integral.Function(f1),1,10,20));
}
}