W
Web learner
I am trying to convert Simpson integration algorithm given in the second section of http://csharpcomputing.com/Tutorials/Lesson16.htm
from Console App to an ASP.NET 2.0 page.
Here is the code
<script runat="server">
protected void Page_Load(object sender, EventArgs e){
class Integral{
public delegate double Function(double x);
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)
sum = sum + step_size / 3 *(f(a + i * step_size) + 4 * f(a + (i + 1) * step_size) + f(a + (i + 2) * step_size));
return sum;
}
}
class Test{
//a simple function to be integrated
public static double f1(double x){
return (x * x);
}
Response.Write((Integral.integral(new Integral.Function(f1), 1, 10, 20)).ToString).;
}
}
</script>
I tried other way but erred. As beginner, I do not know what is wrong.
from Console App to an ASP.NET 2.0 page.
Here is the code
<script runat="server">
protected void Page_Load(object sender, EventArgs e){
class Integral{
public delegate double Function(double x);
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)
sum = sum + step_size / 3 *(f(a + i * step_size) + 4 * f(a + (i + 1) * step_size) + f(a + (i + 2) * step_size));
return sum;
}
}
class Test{
//a simple function to be integrated
public static double f1(double x){
return (x * x);
}
Response.Write((Integral.integral(new Integral.Function(f1), 1, 10, 20)).ToString).;
}
}
</script>
I tried other way but erred. As beginner, I do not know what is wrong.