Numerical Integration (Quadrature)


Problem 1
Cree a program called IntegralTest using Wintempla to compute the integral of y = sin( x) from 0 to 3.1416.
Cree un programa llamado IntegralTest usando Wintempla para calcular la integral de y = sin( x) desde 0 a 3.1416.

IntegralTestRun

IntegralTest.h
#pragma once //______________________________________ IntegralTest.h
#include "Resource.h"
class IntegralTest: public Win::Dialog, public Math::IFunction
{
public:
     IntegralTest()
     {
     }
     ~IntegralTest()
     {
     }
     void UpdateValues();
     //______________________________________ Math::IFunction
     double EvaluateFunc(const double x);
     ...
};


IntegralTest.cpp
...
void IntegralTest::Window_Open(Win::Event& e)
{
     //________________________________________________________ sldSteps
     sldSteps.SetRange(1, 100);
     sldSteps.Position = 25;
     tbxSteps.IntValue = 25;
     UpdateValues();
}

void IntegralTest::sldSteps_Hscroll(Win::Event& e)
{
     const int position = sldSteps.HasPositionChanged();
     if (position < 0) return;
     tbxSteps.IntValue = position;
     UpdateValues();
}

double IntegralTest::EvaluateFunc(const double x)
{
     return sin(x);
}

void IntegralTest::UpdateValues()
{
     const int N = tbxSteps.IntValue;
     const double a = 0.0;
     const double b = M_PI;
     double error = 0.0;
     tbxSimpson.Text = Sys::Convert::ToString(Math::NumericIntegration::Simpson(*this, a, b, error), L"%.12f");
     tbxSimpson1_3.Text = Sys::Convert::ToString( Math::NumericIntegration::Simpson(*this, a, b, N, error), L"%.12f");
     tbxSimpson3_8.Text = Sys::Convert::ToString(Math::NumericIntegration::Simpson3_8(*this, a, b, N), L"%.12f");
     tbxClenshaw.Text = Sys::Convert::ToString(Math::NumericIntegration::ClenshawCurtis(*this, a, b, N), L"%.12f");
     tbxAdaptiveSimpson.Text = Sys::Convert::ToString(Math::NumericIntegration::AdaptiveSimpson(*this, a, b, 1.e-10, 100), L"%.12F");
}



© Copyright 2000-2019 Wintempla selo. All Rights Reserved. Sep 05 2019. Home