A simple Console Application to ASP.NET application

Discussion in 'ASP .Net' started by Web learner, Jan 26, 2006.

  1. Web learner

    Web learner Guest

    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.
    Web learner, Jan 26, 2006
    #1
    1. Advertising

  2. You can try the following in the code behind model, I'm not sure how to write
    it as inline script. I think part of the problem was trying to declare the
    class inside the Page_Load event handler. Since the Response.Write(...) line
    replaces the Console.WriteLine(...) code from the example, you should just
    keep the f1 definition in the same class. Hope that helps - Chase

    protected void Page_Load(object sender, EventArgs e)
    {
    Response.Write((Integral.integral(new Integral.Function(f1), 1, 10,
    20)).ToString());
    }

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


    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;

    }

    }

    "Web learner" wrote:

    > 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
    =?Utf-8?B?Q2hhc2U=?=, Jan 27, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike
    Replies:
    9
    Views:
    1,398
    Robbe Morris [C# MVP]
    Nov 30, 2005
  2. Ben Finney
    Replies:
    2
    Views:
    991
    Egor Bolonev
    Jun 30, 2003
  3. Egor Bolonev
    Replies:
    0
    Views:
    477
    Egor Bolonev
    Jun 30, 2003
  4. Serge Terekhoff
    Replies:
    0
    Views:
    643
    Serge Terekhoff
    Jun 30, 2003
  5. Miktor
    Replies:
    7
    Views:
    12,040
    Joe Bacigalupa
    Aug 9, 2005
Loading...

Share This Page