102
WebCab Functions for .NET v2.0

WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

  • Upload
    others

  • View
    28

  • Download
    0

Embed Size (px)

Citation preview

Page 1: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

WebCab Functions for .NET v2.0

Page 2: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Preface

This documentation accompanies the WebCab Functions .NET Service. This .NET Serviceoffers functionality related to the representation and analysis of functions. This includes:

� Interpolation and extrapolation - schemes which model a function between orbeyond the points as which it is known.

� Equation Sovler - implements various numerical procedures for solving linear equa-tions in one space variable, including Brent’s algorithm, interval bisection method,Newton-Raphson and Ridders’ method.

The first chapter of this documentation contains a brief introduction to the most impor-tant implemented features and related system requirements. In chapter two we let thedeveloper quickly get started with deploying the component by detailing deployment tech-niques on the most widely used application servers. Chapter three and four contains themathematical documentation, which represents the theoretical background of this com-ponent’s implemented features. Chapter five contains the programmer’s guide containinga road map for developers to take advantage of every feature and capability. In chaptersix, we detail the examples provided with this component. Finally, we introduce WebCabComponents, its philosophy and approach to serving the .NETTM development communitywith robust and powerful .NET Services.

If you have any questions or queries concerning the use of this component then pleasefeel free to contact us via our support forum at:

http://www.webcabcomponents.com/support/index.php

Good luck with your project and thank you for your interest in our components.

The WebCab Components Team

i

Page 3: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Contents

Preface i

1 Introduction 11.1 Product Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

1.1.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.1.2 Details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

1.2 Package Details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.3 Prerequisites and Compatibility . . . . . . . . . . . . . . . . . . . . . . . . 4

1.3.1 System Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . 41.3.2 Compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

2 Where do I Start? 52.1 What Type of User Are You? . . . . . . . . . . . . . . . . . . . . . . . . . 52.2 What Do I Need to Install and Where Can I Get It? . . . . . . . . . . . . 6

2.2.1 Installing the IIS Web server . . . . . . . . . . . . . . . . . . . . . . 72.2.2 What Do I Need if I am Using Windows 2003? . . . . . . . . . . . . 8

2.3 Deploying the .NET Service . . . . . . . . . . . . . . . . . . . . . . . . . . 102.3.1 Deploying a Component . . . . . . . . . . . . . . . . . . . . . . . . 102.3.2 Deploying an XML Web Service . . . . . . . . . . . . . . . . . . . . 11

2.4 Using the DLLs inside an IDE . . . . . . . . . . . . . . . . . . . . . . 132.4.1 Using the DLL within a Visual Studio .NET project . . . . . . . . . 132.4.2 Using the DLL within a Borland’s C# Builder project . . . . . . . . 13

2.5 Client Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142.5.1 Running the Console Client Example . . . . . . . . . . . . . . . . . 142.5.2 ASP.NET Client Example . . . . . . . . . . . . . . . . . . . . . . . 152.5.3 XML Web service examples . . . . . . . . . . . . . . . . . . . . . . 15

2.6 Testing the Component . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172.6.1 Accessing the Online ASP.NET Demo . . . . . . . . . . . . . . . . 172.6.2 Online XML Web service examples . . . . . . . . . . . . . . . . . . 182.6.3 Using .NET Web Service Studio . . . . . . . . . . . . . . . . . . . . 18

3 Interpolation Documentation 213.1 Polynomial Interpolation and Extrapolation . . . . . . . . . . . . . . . . . 21

3.1.1 Polynomial through N points and Lagrange’s formula . . . . . . . . 21

ii

Page 4: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

CONTENTS CONTENTS

3.1.2 Neville’s Algorithm (an alternative construction) . . . . . . . . . . . 223.2 Using Rational Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223.3 Cubic Spline Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . 243.4 Coefficients of an Interpolating Polynomial . . . . . . . . . . . . . . . . . . 253.5 Interpolation in Two Dimensions . . . . . . . . . . . . . . . . . . . . . . . 25

3.5.1 Higher Order for Accuracy . . . . . . . . . . . . . . . . . . . . . . . 263.5.2 Higher Order for Smoothness . . . . . . . . . . . . . . . . . . . . . 27

4 Equation Solver Documentation 284.1 Type of Problems we address . . . . . . . . . . . . . . . . . . . . . . . . . 28

4.1.1 One Dimensional Problems . . . . . . . . . . . . . . . . . . . . . . . 284.1.2 Multi-dimensional Problems . . . . . . . . . . . . . . . . . . . . . . 29

4.2 Deciding what approach to use? . . . . . . . . . . . . . . . . . . . . . . . . 304.2.1 Continuous Equations of One real variable . . . . . . . . . . . . . . 304.2.2 Guide to method selection for 1-dimensional problems . . . . . . . . 30

4.3 Interval Bisection Method . . . . . . . . . . . . . . . . . . . . . . . . . . . 314.4 Secant Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314.5 Method of Regula Falsi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314.6 Ridders’ Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324.7 Van Wijngaarden-Dekker-Brent Method . . . . . . . . . . . . . . . . . . . 324.8 Newton-Raphson Method . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

5 Programmer’s Guide for Microsoft Office 355.1 Developing with VBA from Office . . . . . . . . . . . . . . . . . . . . . . . 35

5.1.1 Open the Visual Basic Editor . . . . . . . . . . . . . . . . . . . . . 365.1.2 Add a Code Module . . . . . . . . . . . . . . . . . . . . . . . . . . 365.1.3 Declare a Subroutine . . . . . . . . . . . . . . . . . . . . . . . . . . 365.1.4 Declare a Class Instance Variable . . . . . . . . . . . . . . . . . . . 375.1.5 Create a Class Instance . . . . . . . . . . . . . . . . . . . . . . . . . 385.1.6 Call a Class Method . . . . . . . . . . . . . . . . . . . . . . . . . . 405.1.7 Display the Method Result . . . . . . . . . . . . . . . . . . . . . . . 415.1.8 Run the Subroutine . . . . . . . . . . . . . . . . . . . . . . . . . . . 415.1.9 A Generic VBA Example for Office . . . . . . . . . . . . . . . . . . 43

5.2 Integrating with Microsoft Excel . . . . . . . . . . . . . . . . . . . . . . . . 445.2.1 Open the Visual Basic Editor . . . . . . . . . . . . . . . . . . . . . 445.2.2 Add a Code Module . . . . . . . . . . . . . . . . . . . . . . . . . . 445.2.3 Declare a Function . . . . . . . . . . . . . . . . . . . . . . . . . . . 465.2.4 Declare a Class Instance Variable . . . . . . . . . . . . . . . . . . . 465.2.5 Create a Class Instance . . . . . . . . . . . . . . . . . . . . . . . . . 465.2.6 Call a Class Method . . . . . . . . . . . . . . . . . . . . . . . . . . 475.2.7 Store the Method Result as a Function Return Value . . . . . . . . 475.2.8 Insert the Function in your Worksheet . . . . . . . . . . . . . . . . 47

iii

Page 5: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

CONTENTS CONTENTS

6 Programmer’s Guide for Visual Studio 6 516.1 Developing with Visual Basic 6 . . . . . . . . . . . . . . . . . . . . . . . . 51

6.1.1 Declare a Class Instance Variable . . . . . . . . . . . . . . . . . . . 516.1.2 Create a Class Instance . . . . . . . . . . . . . . . . . . . . . . . . . 526.1.3 Call a Class Method . . . . . . . . . . . . . . . . . . . . . . . . . . 546.1.4 A Generic Visual Basic Example . . . . . . . . . . . . . . . . . . . 54

6.2 Developing with Visual C++ 6 . . . . . . . . . . . . . . . . . . . . . . . . 566.2.1 Open a New or Existing Project . . . . . . . . . . . . . . . . . . . . 566.2.2 Add ‘Include’ Declarations . . . . . . . . . . . . . . . . . . . . . . . 606.2.3 Call “CoInitialize” . . . . . . . . . . . . . . . . . . . . . . . . . . . 606.2.4 Create a Class Instance . . . . . . . . . . . . . . . . . . . . . . . . . 616.2.5 Obtain a Method ID . . . . . . . . . . . . . . . . . . . . . . . . . . 616.2.6 Declare the Parameter Values and Types . . . . . . . . . . . . . . . 626.2.7 Declare the Return Type . . . . . . . . . . . . . . . . . . . . . . . . 626.2.8 Call the Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . 626.2.9 Call “CoUninitialize” . . . . . . . . . . . . . . . . . . . . . . . . . . 636.2.10 A Generic Visual C++ Example . . . . . . . . . . . . . . . . . . . . 63

7 Programmer’s Guide for .NET 667.1 Developing with .NET Class Libraries . . . . . . . . . . . . . . . . . . . . . 66

7.1.1 Stand-alone C# .NET Applications . . . . . . . . . . . . . . . . . . 667.2 Developing with XML Web Services . . . . . . . . . . . . . . . . . . . . . . 68

7.2.1 Deploying the XML Web Services . . . . . . . . . . . . . . . . . . . 687.2.2 Writing XML Web Service Clients . . . . . . . . . . . . . . . . . . . 687.2.3 Writing Console XML Web Service Clients . . . . . . . . . . . . . . 697.2.4 Importing Web services into Visual Studio .NET projects . . . . . . 71

7.3 Connecting to a Database with our .NET Libraries . . . . . . . . . . . . . 727.3.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 727.3.2 The ADO Mediator . . . . . . . . . . . . . . . . . . . . . . . . . . . 72

8 Examples 788.1 Question and Answer (QA) Client Examples . . . . . . . . . . . . . . . . . 78

8.1.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 788.1.2 Structure of QA Examples Directory . . . . . . . . . . . . . . . . . 788.1.3 Quick Start Guide . . . . . . . . . . . . . . . . . . . . . . . . . . . 808.1.4 Explanation of the QA Directory Structure and its files . . . . . . . 808.1.5 Remarks on .NET compilers . . . . . . . . . . . . . . . . . . . . . . 82

8.2 Functions and Methods Considered . . . . . . . . . . . . . . . . . . . . . . 828.3 Detailed Analysis of the Performance of the four Test Functions . . . . . . 84

8.3.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 848.4 Testing Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 858.5 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85

8.5.1 Interval Bisection Method . . . . . . . . . . . . . . . . . . . . . . . 858.5.2 Secant Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86

iv

Page 6: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

CONTENTS CONTENTS

8.5.3 Method of False Position . . . . . . . . . . . . . . . . . . . . . . . . 878.5.4 Newton-Raphson Method . . . . . . . . . . . . . . . . . . . . . . . 888.5.5 Fail-Safe Newton-Raphson method . . . . . . . . . . . . . . . . . . 898.5.6 Ridders’ Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . 908.5.7 Brent’s Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91

8.6 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 928.7 Custom Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92

8.7.1 Database Example with JDBC Mediator . . . . . . . . . . . . . . . 92

9 Guide to WebCab Components 949.1 The Company . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 949.2 Presentation of Products . . . . . . . . . . . . . . . . . . . . . . . . . . . . 949.3 Supported Clients, IDEs, Containers and DBMSs . . . . . . . . . . . . . . 949.4 Transparent Functionality . . . . . . . . . . . . . . . . . . . . . . . . . . . 959.5 Company Culture and Activity . . . . . . . . . . . . . . . . . . . . . . . . 959.6 Product Life cycle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 959.7 Support, Warranty and Upgrades . . . . . . . . . . . . . . . . . . . . . . . 95

v

Page 7: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Chapter 1

Introduction

1.1 Product Description

1.1.1 Overview

We offer refined numerical procedures to either construct a function of one or two variablesfrom a set of points (i.e. interpolate), or solve an equation of one variable. The interpola-tion procedures provided include Newton polynomials, Lagrange’s formula, Burlisch-Stoeralgorithm, Cubic splines (natural and free), Bicubic interpolation and procedures for findthe interpolation functions coefficients. In order to solve an equation we provide the VanWijngaarden-Dekker-Brent algorithm, interval bisection method, secant and false position,Newton-Raphson method and Ridders’ method.

1.1.2 Details

This suite includes the following features:

Interpolation Module

� Polynomial Interpolation and extrapolation

– Lagrange’s formula - for interpolating a function known at N points with apolynomial of degree N − 1

– Burlisch-Stoer algorithm - interpolates functions using rational functions,this method gives error estimates

– Cubic Splines - we give algorithms for natural and clamped cubic splines

– Sorting - efficient techniques are used for finding tabulated values

� Coefficients of an Interpolating Polynomial

– Matrix method - this method relies upon diagonalizing a matrix (or solvinga system of equations), and is of the order N squared

1

Page 8: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Introduction Chapter 1

– Zero method - by evaluating the interpolating polynomial at particular valueswe deduce the coefficients, this method is of the order N cubed

� Interpolation and extrapolation in two or more dimensions

– Grid - functions can be interpolated on an n-dimensional grid

– Bilinear interpolation - we consider a multidimensional interpolation bybreaking the problem into successive one dimensional interpolations

– Accuracy - the use of higher order polynomials to obtain increased accuracy

– Smoothness - the use of higher order polynomials to enforce smoothness onsome of the derivatives

– Bicubic interpolation - finds an interpolating function with a specified deriva-tives and cross derivatives which vary smoothly at the grid points

– Bicubic spline - a special case of Bicubic interpolation involving the use ofsuccessive one-dimensional splines

Equation Solver Module

� Interval Bisection Method - A robust method that always finds a solution or asingularity inside a bracketed interval.

� Secant Method - Generally this procedure converges and is much faster than theinterval bisection method.

� Brent’s Algorithm - The method of choice to find a bracketed root of a one di-mensional equation when you cannot easily compute the function’s derivative.

� Ridders’ Method - Concise and almost as reliable as Brent’s Algorithm for findinga bracketed root of an equation.

� Method of Regula Falsi - This procedure uses a slight alteration on the secantmethod to ensure convergence. The procedure is generally faster than the intervalbisection method and slightly slower than the secant method.

� Newton-Raphson Method - Given a first approximation to a root and the differ-ential of the function this procedure will always produce a solution. We implementthis procedure for polynomial functions of one variable.

� Fail-Safe Newton-Raphson Method - This method combines the Newton-Raphsonmethod and the Interval Bisection Method in order to produce very stable and fastconvergence. Given a first approximation to a root and the differential of the functionthis procedure will always produce a solution.

This product also has the following feature:

2

Page 9: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Introduction Chapter 1

� ADO Mediator - The ADO Mediator assists the .NET developer in writing DBMSenabled applications by transparently combining the financial and mathematicalfunctionality of our .NET components with the ADO.NET Database Connectivitymodel.

� ASP.NET Web Application Examples - We provide an ASP.NET Web Appli-cation example which enables you to quickly test the functionality within this .NETService.

� ASP.NET Examples with Synthetic ADO.NET - we use a ASP.NET service toperform component calculations on SQL database columns from a remote DBMS. Weapply a component’s function to certain rows from the database and list the output inHTML format. This is a powerful feature since it allows you to perform calculationsin a DBMS manner without having to code the C#to SQL database transactionyourself as it is all done by the ASP within the .NET Framework managed serverside environment.

1.2 Package Details

This .NET Service package contains the following:

� Introductory Text File (README.TXT)

� License Agreement

� Documentation in PDF Format

– Product Description

– System Requirements

– Compatibility Issues

– Deployment Guide (How to get started?)

– Mathematical Documentation

– Programmer’s Guide

– Examples

– Guide to WebCab Components

� Class Documentation

– Class Descriptions

– Methods Descriptions

� Deployment Files (DLLs)

� Examples and Related Source Code Files

� WebCab Components Brochure

3

Page 10: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Introduction Chapter 1

1.3 Prerequisites and Compatibility

1.3.1 System Requirements

� Microsoft Windowsr

XP/2000/2003 family

� Pentium III 500 MHz

� 64MB RAM

� .NET Framework 1.0 (or higher)

1.3.2 Compatibility

Component Type

� ASP.NET XML Web service

� .NET Class Library

Built Using

� Microsoft .NET Framework SDK

� Borland C# Builder

4

Page 11: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Chapter 2

Where do I Start?

Start using the Functions for .NET v2.0 .NET Service right away by following the few quick andsimple steps described in this chapter. If you require additional information or have problemswith the installation and use of this .NET Service then please do not hesitate to contact us viaour support forum at: http://www.webcabcomponents.com/support/index.php

2.1 What Type of User Are You?

.NET Components or XML Web Services

The prerequisite Windows operating system components you will need to have installed onyour local machine will depend on the way in which you intend to use our .NET Service.In particular, there are two distinct deployment architectures in which our product can beused:

� Class Library - those wishing the use our .NET Components functionality directlywithin there .NET Applications. This category includes those who wish to use ourcomponent within Microsoft’s Visual Studio .NET or Borland’s C#Builder projects,or those who simply want to register the DLL class library onto there local machinefor consumption by local or remote applications.

� XML Web service/ASP.NET - those wishing to deploy either an ASP.NET basedClient server application and an XML Web service.

Chapter Overview

Within the remainder of this chapter we will detail how to install and configure the nec-essary Windows components, deploy the .NET Components or XML Web Services andfinally how to run examples associated within these two deployment scenarios1.

1Later within this PDF documentation within the Programmers Guide we will cover developmenttechniques which can be employed for either composing larger applications or building clients for thesedeployed components and Web services

5

Page 12: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Where do I Start? Chapter 2

The remainder of this chapter is structured in the following way, please feel free to skipany sections which are not relevant to you:

1. Configuration - Describes how to configure the Windows deployment/developmentplatform for .NET based applications, including Web Services.

2. Deployment - Details the deployment of the .NET Service as a .NET Componentor as a XML Web Service.

3. Using the DLLs inside an IDE - We detail here how to import the .NET ClassLibraries DLLs into Microsoft’s Visual Studio .NET and Borland’s C# Builder.

4. Clients - Explains client examples provided with this .NET Service

5. Live Demos - Details the functionality of the Online Web Application Demos.

2.2 What Do I Need to Install and Where Can I Get

It?

In order to deploy and then use a .NET Component within your applications you are re-quired to have (or install) the following Windows component onto your Windows operatingsystem:

� .NET Framework

If you wish to deploy either ASP.NET or XML Web services then you will also be requiredto install:

� Microsoft’s Internet Information Server (IIS)

In order to develop .NET based applications (i.e. compile C#.NET source code) you willalso need to have the following Windows Components installed:

� .NET Framework SDK

Getting the .NET Platform

The .NET Framework’s installation package comes in the following two flavors:

� .NET Framework SDK (approx. 110MB)

� .NET Framework, Redistribution package (approx. 23MB)

Those wishing to develop applications using the .NET Framework will require the .NETFramework and the .NET Framework SDK installed onto the development machine. Whereasthose who only wishing to deploy .NET Applications and Services will require only the.NET Framework (also known as the .NET Framework Redistribution package). The latestversion of these packages can be downloaded from http://msdn.microsoft.com/downloads.

In order to run our ASP.NET and Web service demos you are also required to have Mi-crosoft’s IIS Web server installed and started.

6

Page 13: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Where do I Start? Chapter 2

Installing the .NET Framework

Through the Add/Remove Programs feature of the Control Panel you are able to dis-cover which version (if any) of the .NET Framework you are currently running. If youintend to upgrade to a later version of the .NET Framework then you are presently run-ning then we strongly suggest that you first uninstall all previous versions of the .NETFramework first. This is due to the fact that some applications will use the earliest in-stalled version of the .NET Framework rather than the latest edition.

You can then proceed to install the latest version of the .NET Framework by just exe-cuting the .NET Framework installation package by following through the dialog withinthe installation program.

Remark Please note that Microsoft will ensure backward compatibility of the .NETFramework. That is, application developed under v1.0 for example will run and behave ina similar fashion under later releases of the .NET Framework.

2.2.1 Installing the IIS Web server

In order to deploy and run ASP.NET or XML Web services you are required to have therelevant pieces of the “Applications Server” stack installed onto the deployment Windowsmachine. The key piece of this infrastructure stack is Microsoft’s IIS Web server.

On any Windows machine you can check to see whether the IIS Web server is installed andrunning by opening the following page within a web browser http://localhost. If the IISWeb server is installed and running then you will be presented with either a placeholderpage similar to the following:

7

Page 14: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Where do I Start? Chapter 2

If you already have a web site deployed into the root directory of the IIS Web server thenthe home page of this web site will be displayed.

Remark By requesting the page http://localhost, the local IIS Web server will be auto-matically restarted if it is not already running.

Installation Process

If the IIS Web server is not installed onto your local machine then you may install itthrough using the Windows Program installation tool. To access this tool select:

Settings > Control Panel > Add or Remove Programs

Now click on the button, Add\Remove Windows Components. A window should pop-up in which a number of Windows components are listed, one of these items should readInternet Information Services (IIS). You should select the click box for this serviceand install it by clicking the Next button.

2.2.2 What Do I Need if I am Using Windows 2003?

Microsoft’s Windows 2003 is the first Windows operating system that has been designed ex-plicitly to host .NET Applications. Though, Windows 2003 has the .NET Framework v1.1embedded within the operating system you will still need to configure the IIS Web serveror the .NET Framework SDK if you intend to either deploy ASP.NET based Applicationsor use the Windows 2003 machine to develop .NET based Applications and Services.

8

Page 15: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Where do I Start? Chapter 2

Installing the IIS Web server onto Windows 2003

The IIS Web server for the Windows 2003 operating system is not installed by default.Therefore, if you did not explicitly request the deployment of the system component knownas ‘Application Server’ during the installation of Windows 2003. You will need to manu-ally install this Windows 2003, component if you wish to deploy ASP.NET or XML Webservices to your local machine. For all Windows platforms the deployment process of theIIS Web server proceeds in a similar fashion via the control panel interface.

In order to deploy the ‘Applications Server’ components first select Add/Remove Win-dows Components from the Add/Remove Programs control panel interface.

Once the ‘Application Server’ is selected by clicking on the Details button you will bepresented with:

9

Page 16: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Where do I Start? Chapter 2

Remarks

� As you can see from the above screen shot by default the ASP.NET, Enable net-work COM+ access and Internet Information Services (IIS) have been se-lected which is sufficient for the deployment of nearly all .NET Framework basedApplications and Services.

� The Windows 2003 platform contains a thoroughly updated infrastructure stack con-cerning the delivery of ASP.NET and XML Web services. This includes a newASP.NET container which is closely integrated with the IIS Web server. This updatecontains several enterprise level .NET related features concerning the managementof services (automatic startup, shutdown of services and the server itself), security(lockdown of ports and unused services), scalability (load balancing) and easier man-agement (Component services and IIS management console). In our opinion theWindows 2003 platform offers a significantly more robust platform than early ver-sions of the Windows platform in which to deploy .NET Applications and Services.

2.3 Deploying the .NET Service

If you installed this product using the MSI installer then the .NET Class Libraries DLLsshould already be registered within your global assembly cache. In order to use the corre-sponding XML Web Service implementation you will need to follow the deployment guidebelow.

In case you installed using a Zip package or wish to install the .NET Class Librariesonto another Windows machine we explain below how to manually deploy our .NET ClassLibraries.

2.3.1 Deploying a Component

Once the .NET Framework has been installed onto the deployment machine the component(i.e. the DLL), can be deployed and registered. By registering the component it will becomeavailable to local and remote .NET Applications and Services.

Making your components (locally) available

The easiest and quickest means to deploy the DLL component files, is to simply copy themto one of the following two directories on your Windows machine:

� WINDOWS\System

� Application directory - the directory in which the .NET Application which willconsume the component is located.

When your Application is executed Windows will automatically look in one of these loca-tions for the DLL file with it wishes to import.

10

Page 17: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Where do I Start? Chapter 2

Making the Components Globally available?

The above deployment technique is straightforward but has the restriction that is does notallow for any custom configuration of the deployment environment which may be requiredby the .NET Application which will consume the component. Moreover, such deploymenttechniques do not allow the components (i.e. DLL’s) to be effectively shared between twoor more applications. In order to allow the components to be used by several applicationsyou must deploy the components within the Global Assembly Cache.

Remark The Global Assembly Cache within the .NET Framework plays a similarrole to that of the CLASSPATH environment variable within the Sun Java platform.

A Component can be deployed to the Global Assembly Cache in one of two ways:

� Microsoft Windows Installer 2.0 - Recommended for use on production servers.

� Global Assembly Cache tool (Gacutil.exe) - Recommended only for use on develop-ment or test servers.

Please note, in order to use the Assembly Cache tool you are required to have the .NETFramework SDK installed and to create a Windows installer you will need the WindowsInstaller SDK v2.0. For further details concerning the Windows Installer technology werefer the interested reader to the Visual Studio .NET documentation or the MSDN sectionof Microsoft’s website.

The Global Assembly Cache Tool is run from the DOS command prompt. In order todeploy the assembly WebCab.Libraries.FunctionsDemo.dll, contained within the presentdirectory you must input the command:

Gacutil.exe /i WebCab.Libraries.FunctionsDemo.dll

Using the DLL within your own Applications

Within the Library directory of the installation package you will find the class libraryassembly (DLL) for Functions. There are several ways you may choose to use this DLLwithin your applications.

2.3.2 Deploying an XML Web Service

Once the .NET Framework and the IIS related infrastructure is installed the actual deploy-ment of an ASP.NET Application or an XML Web service just involves copying a DLL fileand several ASMX files into given directories within the IIS Web server root file directory.

Installation Process

11

Page 18: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Where do I Start? Chapter 2

Within the XML Web service folder within this installation package are the resourcesfor deploying the Web service of the Functions. In order to install and start using theXML Web service functionality you will need to perform the following steps:

� Deploy the XML Web service assembly (DLL) onto your local IIS Web server. Thisis accomplished by copying the contents of the ‘bin’ folder of the current directoryto the ‘bin’ folder of the local IIS root directory, which under the default installationis C:\Inetpub\wwwroot.

� Deploy all .asmx pages inside the IIS Web server, by copying all the folders locatedunder the XML Web service folder located under the current directory to the IISroot directory.

� Run the WSDL tool in order to generate all XML Web service proxies. This is doneby running the following line at the command prompt:

wsdl http://localhost/<directory name>/<XML Web service>.asmx

where <directory name> is the name of the subdirectory of the IIS root in whichthe XML Web service is deployed and <XML Web service> is the name of the Webservice which you wish to generate a proxy for.

Remarks

� All generated proxies are used as described in the CHM documentation of this prod-uct.

� If the Web service is not being locally run then the ‘localhost’ should be replacedwith the host name of the computer where the Web service is deployed and running.

� You may be using another equivalent ASP.NET Web server, in which case the abovedeployment procedure may differ slightly in detail but will still involve the same basicsteps.

Testing the Deployment

You can easily test an XML Web service deployment by using any compatible web browser.That is, to test the deployment open a compatible web browser (for example Internet Ex-plorer) and open the following page:

http://localhost/<directory name>/<filename>.asmx

where <directory name> is the name of the subdirectory of the IIS directory root wherethe Web services are located and <filename> is the name of one of the .asmx files locatedinside the <directory name> folder. As soon as the browser displays the page correctlyyou are sure that the corresponding XML Web service has been properly installed.

12

Page 19: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Where do I Start? Chapter 2

2.4 Using the DLLs inside an IDE

2.4.1 Using the DLL within a Visual Studio .NET project

If you are developing a Visual Studio .NET project and wish to use our DLLs componentsfunctionality then you may add the DLL to the project reference. This is performed byusing the Project > Add Reference... menu item.

2.4.2 Using the DLL within a Borland’s C# Builder project

If you are developing a C#Builder project and wish to use our DLLs components function-ality then you may deploy and then add the assembly to your project solely from withinC# Builder.

To deploy the DLL select from the menu, Component > Installed .NET Components Thenclick on the ‘Select an Assembly’, to select the DLL from the file system.

Once the DLL component is deployed you may add the DLL to your C# project by rightclicking on your project within the “Project Manager” and selecting “Add reference” asshow below:

13

Page 20: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Where do I Start? Chapter 2

Alternatively, you could use the equivalent link with the menu, Project > Add Reference.

Now an ‘Add reference’ window will pop-up, in which you should select the assemblyyou wish to add to your project and then click OK.

2.5 Client Examples

Within this section we describe the clients which have been provided with this .NETService. In particular, we will describe:

1. Console Client Examples

2. ASP.NET Client Examples

3. Web Service Client Examples

2.5.1 Running the Console Client Example

In order to run the console demonstration examples you must start a DOS CommandPrompt. On a Windows XP machine this can be achieved by:

START > Programs > Accessories > Command Prompt

Once the command prompt is started you should navigate to the Librares\Client sub-directory of the installation directory2 using the cd command. The Client subdirectoryis structured into subdirectories corresponding to client examples. Every client exampleshould be accompanied by a compile.cmd file, which when run will compile its corre-sponding client. After compilation, the only thing left to do is launch into execution thegenerated executable file(s).

For further technical details you should read the README.TXT files located insidethe Client subdirectories.

2Usually C:\Program Files\WebCab Components\Functions.

14

Page 21: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Where do I Start? Chapter 2

2.5.2 ASP.NET Client Example

Within the \ASP.NET Examples, folder of this package we have provided a set of tailormade ASP.NET examples for the WebCab Functions for .NET v2.0 .NET Service.

In order to start using these ASP.NET examples, please go through the following steps:

1. Deploy the ASP.NET Pages and Resources

(a) Copy the contents of the ‘Functions ASP.NET Examples’ folder located in thecurrent directory to a location under your IIS (or another compatible ASP.NETweb server) root directory. This is usually ‘C:\Inetpub\wwwroot’ or a similarpath with a different drive letter.

(b) Secondly, copy the contents of the ‘bin’ subfolder of the current directory to the‘bin’ subfolder of your IIS root directory. If the ‘bin’ directory does not existinside the IIS root directory, you will be required to create it.

2. Run the ASP.NET Examples

(a) Open an Internet browser3 and type in the following address:

http://localhost/Functions ASP.NET Examples/index.html

In case you chose to copy the ‘Functions ASP.NET Examples’ directory to asubdirectory of your IIS root directory, you will need to include the full path toit inside the above URL. Also, if you have deployed these ASP.NET examplesto another .NET machine, you should replace ‘localhost’ with the name of thatmachine.

Remark An online version of these ASP.NET examples can be found at:

webcabcomponents.com/dotNET

Using the Example

Further explanation regarding the use of this example can be found within the ‘Accessingthe Online Demo’, section of this guide which details the use of the online version of thisASP.NET example.

2.5.3 XML Web service examples

Within the directory \XML Web Services\Client\, you will find C# application clientexamples which make use of the financial and mathematical functionality provided by theXML Web services implementation of the WebCab Functions .NET Service.

3E.g. Internet Explorer, Opera, Mozilla.

15

Page 22: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Where do I Start? Chapter 2

Remark In order to run and access the Web service examples it is necessary to havethe IIS web server and a compatible internet browser (for example Internet Explorer 5 orhigher) installed onto your local machine.

Please go through the following steps in order to test these client examples:

1. Before running or even compiling these XML Web service client examples you willhave to deploy all Functions XML Web services located one directory level above toyour local IIS server or an IIS server your machine can connect to. This is accom-plished by copying the contents of the ‘bin’ folder, located one level above in the direc-tory structure, to the ‘bin’ folder of the IIS root directory, usually C:\Inetpubwwwroot.You will also need to copy the ‘FunctionsDemo’ folder to the IIS root directory.

2. Browse through each subfolder of the current directory and locate every ‘compile.cmd’compilation script file. There is one compilation script for every client example. Everyclient example requires certain XML Web services to connect to, which you maydetermine by running the compilation script. The reported errors should correspondto the XML Web services the client example requires.

3. Run the WSDL tool in order to generate XML Web service proxies for every XMLWeb service required by each client example. This is done by running the followingline at command prompt:

wsdl http://localhost/FunctionsDemo/<XMLWebservice>.asmx

where <XMLWebservice> is the name of the required XML Web service and ‘localhost’should is the host name of the computer where the IIS server is running, in case it’snot this machine.

Make sure you are running this command from directory containing the compila-tion script.

4. Run the ‘compile.cmd’ compilation script file again. If the right XML Web serviceproxies have been generated for its client examples, the compilation script will com-pile all source code files and generate a .NET executable file (.exe). If the script stillresults in an error, please go through the previous step again, making sure you gener-ate the XML Web service proxy classes required by the client example correspondingto this compilation script.

5. Run the generated executable files. Running the executable files will allow you totest the client examples.

You may compile the client examples (after having generated the XML Web service prox-ies) and run their executable files as you go through each subfolder, since every clientexample is independent of each other.

16

Page 23: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Where do I Start? Chapter 2

If you wish to customize a particular client example after having run it, please feel free toadapt its source code files accordingly and run the compilation script again. Note that youwill not need to regenerate the XML Web service proxy classes.

2.6 Testing the Component

2.6.1 Accessing the Online ASP.NET Demo

By far the easiest way to test the functionality of this .NET Service is to view the on-line demo. The online demo can be accessed from our .NET Homepage by clicking the‘[ASP.NET]’ link corresponding to this Application. Once you click on the link the follow-ing pop-up Window will appear:

Fig: Interface of the ASP.NET online Web Application

Compatible Web Containers

This demo runs inside an online web container and demonstrates the ASP.NET technology.The demo can be accessed through a web browser and is compatible with Internet Explorer5, Netscape Navigator 4, Netscape 6, Opera 5 and higher.

Selecting a method to test

After clicking on the ‘[ASP.NET]’ link for this application from our home page the Webdemo will launch within a new browser window. To order to select a method from thisapplication use the drop-down menu on the left hand side of the screen to navigate throughall implemented functions. The menu lists all the components on the first level and theircorresponding functions on the second and third level. Click on the plus icon in order toexpand the component menu and then click a function item to select it.

Inputting data

The selected function will be displayed on the right hand panel of the new window accom-panied by its description and parameter characterization. Once the nature of the method isclear you may test the method by inputting the parameters within the text boxes providedor associating a database table field using our database management tool.

Running the demo using text boxes

Please input the value of each parameters in to the corresponding text box while payingattention to each parameter description. When all the parameters has been input, pressthe “Get Result” button on the right-hand side and towards the bottom of the screen inorder to request the solution from the server-side component. If by chance any parametersare out of range you will be prompted to enter a correct value before proceeding.

17

Page 24: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Where do I Start? Chapter 2

2.6.2 Online XML Web service examples

The XML Web Services contained within this package have also been deployed online. TheWeb service demo is accessed through our .NET Homepage by clicking on the ‘[WSDL]’link corresponding to this Service. Once you click on the link the following pop-up Windowwill appear:

Fig: Interface of the Online Web Services

Remark In order to view the online demos you will require a compatible internet browser(for example Internet Explorer 5 or higher) with JavaScript enabled.

2.6.3 Using .NET Web Service Studio

You may wish to test the functionality of our XML Web services by using one of Mi-crosoft’s .NET tools made for testing XML Web services, .NET Web Service Studio2.0. A link to where you can directly download this tool is available on our onlineweb site at webcabcomponents.com/dotNET. Download and unzip the pack and run theWebServiceStudio\build.bat file. In order to start up the tool double-click the generatedWebServiceStudio.exe .NET executable file.

18

Page 25: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Where do I Start? Chapter 2

Deciding on an XML Web service

Click here in order to open the .NET Homepage of our web site. At the bottom of thepage you will notice a list of Online .NET Web Services with their corresponding ASP.NETExample page and their WSDL description page links. Click on the WSDL link next to:fullnamewithoutdotnet:. Move your mouse pointer above the left hand SIDE MENU andclick on an XML Web service name.

A new browser window will open and present you with the default IIS 6.0 ASP.NETXML Web service page. Inside the ‘Address’ bar of your browser you will be able to seethe fully qualified URL to the online WSDL for the corresponding XML Web service.

Connecting to an XML Web service

Copy from your browser’s Address bar the WSDL URL to the XML Web service you havechosen to test and paste it into the WSDL EndPoint text field inside WebService Studio.Click the Get button next to this text field and wait for the tool to establish a connectionto the XML Web service.

As soon as the connection has been established, you can start going through every availablewebmethod our XML Web service has to offer by clicking on the items in the left hand sideof the tool’s window. After clicking a web method’s name, look inside the Input panel forrequired parameters. You may recognize these parameters from the available API CHMdocumentation we have included inside this package4.

Sending in Web Method Parameters

Inside the Body tree of the Input panel you may click on every parameter type and thenset its value inside the Value panel to its right. This is accomplished by editing the rightside of the Value column in the right hand side Value panel.

If you are dealing with parameters of an array type (say a Double[] array), you will firstset its Length in the Value panel and then go through every of its tree children inside theInput panel and set their Value field back into the Value panel. The following two screenshots explain this process.

4Browse the API Reference by double-clicking the CHM file located inside the Documentation direc-tory of this Package.

19

Page 26: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Where do I Start? Chapter 2

WebService Studio: Setting the Length of a Double Array to 4

WebService Studio: Setting the Value of its First Element to 12

Invoking a Web Method

After having sent in the right parameter values5 click the Invoke button right below theValue panel on the right hand side of the window.

The Output panel below the Input panel will present you with the results of invokingthe corresponding Web Method of our online XML Web service over the Internet.

5You should refer to the corresponding API HTML Help documentation even when running this testtool. You could however send in some arbitrary values just to try out some of our simpler Web Methods.

20

Page 27: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Chapter 3

Interpolation Documentation

This is the mathematical documentation that accompanies the Interpolation module of theWebCab Functions .NET Service. Within this module we implement various numerical meth-ods for interpolating and extrapolating a function of one or two variables from a set of pointson which it is known.

The theory of Interpolation and Extrapolation forms a foundation for the developmentof methods in numerical integration and differentiation, approximation theory, and the nu-merical solution of differential equations. Its main concern is the estimation of the value ofa function f at an arbitrary point x by, in some sense, drawing a smooth curve through (orbeyond) some points xi. If the desired x is in between the largest and the smallest of thexi’s, the method is called interpolation; if x outside that range, it is called extrapolation.

3.1 Polynomial Interpolation and Extrapolation

3.1.1 Polynomial through N points and Lagrange’s formula

Since a polynomial of degree zero (also known as a line) is uniquely determined if it isrequired to go through two points. We can conclude that the (linear) interpolation be-tween two points is uniquely determined when a zero degree polynomial is used for theinterpolation. In a similar fashion, n − 1 points uniquely define a n degree polynomial ifwe insist that the n degree polynomial must pass through all n− 1 points.

The unique polynomial which passes through N points is given explicitly by Lagrange’sclassical formula. That is, if we have a polynomial of degree N − 1, which passes throughthe N points:

y1 = f(x1), y2 = f(x2), . . . , yn = f(xn) (3.1.1)

then this polynomial is given uniquely (up to scaling) explicitly by Lagrange’s classicalformula:

P (x) =(x− x2)(x− x3) . . . (x− xN)

(x1 − x2)(x1 − x3) . . . (x1 − xN)y1 +

(x− x1)(x− x3) . . . (x− xN)

(x2 − x1)(x2 − x3) . . . (x2 − xN)y2 + . . .

21

Page 28: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Interpolation Documentation Chapter 3

. . . +(x− x1)(x− x2) . . . (x− xN−1)

(xN − x1)(xN − x2) . . . (xN − xN−1)yN (3.1.2)

Remarks

� Established the converse statement and hence the uniqueness of Lagrange’s formula(up to scaling) is closely related to proving the ‘Fundamental Theorem of Algebra’,with the observation that if all an equations solutions are real then the equation isreal.

� In a trivial fashion in the general case we can construct the n degree polynomialwhich passes through the n− 1 points:

(x1, 0)), (x2, 0), . . . , (xn−1, 0))

By the polynomial:

f(x, 0) = (x1 − x)(x2 − x) . . . (xn−1 − x)

In order to construct the Lagrange formulae now for a general function f(x), wecan “continuously map the x-axis” onto the function f(x), which will “deform thefunction f(x,0)” into the Lagrange formula.

� One major disadvantage of Lagrange’s formula is that the resulting algorithm doesnot yield any error estimates.

3.1.2 Neville’s Algorithm (an alternative construction)

Another approach to the construction of the same unique interpolation polynomial asyielded by Lagrange’s Formula known as Neville’s algorithmleads to an algorithm whichis more straightforward to implement. Neville’s algorithm uses a recursive relation for theapproximation by constructing an interpolation polynomial of degree N , for some n ∈ N,which passes through N +1 points, from a polynomial of degree N−1 which passes throughN points. The basis for this inductive construction is given by setting the zero degree poly-nomials needed to be constant functions equal to the function being interpolated, evaluatedat the interpolating points.

We denote by Pi,i+1,...,i+l, the polynomial which passes through the l points, {xi, xi+1, . . . , xi+l}.Then the foundation of Neville’s Algorithm is the following recursive relation:

Pi,(i+1)...,(i+l) =(x− xi+l)Pi,(i+1),...,(i+l−1) + (xi − x)P(i+1),(i+2),...,(i+l)

xi − xi+l

(3.1.3)

3.2 Using Rational Functions

If the function being interpolated has a pole (i.e. a type of singularity) then it is naturalthat a polynomial will not be ideal as an interpolating function in a neighborhood of the

22

Page 29: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Interpolation Documentation Chapter 3

pole (or more generally, the singularity). Since any polynomial defined on R, do not havepoles or in fact any type of singularity.

In the case of interpolating a function with a pole a rational function (that is, the quotientof two polynomials) would appear to be a good class of functions to construct a interpo-lation from. Since a rational function can be constructed to have a finite number of polesof any degrees at any points on the real line.

We approximate the function f(x) passing through N points (x1, y1), . . . , (xN , yN) by arational function. We denote by Ri(i+1)...(i+m) the rational function passing through m + 1points (xi, yi), . . . , (xi+m, yi+m); that is:

Ri(i+1)...(i+m) =p0 + p1x + · · ·+ pµx

µ

q0 + q1x + · · ·+ qσxσ(3.2.4)

Remarks

� Even if a function only has a pole in the complex plain after it has been analyticallycontinued, a rational function may still be more suitable than a polynomial for itsinterpolation. The reasons for this lie in the fact that a Mobius transformation canbe used to map the pole of an analytic function onto the real line and this Mobiustransformation will preserve the functional properties of the analytic function. Thisalso indicates why a pole in the complex plain can prevent us from obtaining a goodinterpolating polynomial when the function considered is a real function.

� Also note that any polynomial is bounded when the modulus of the variable isbounded, contrary to rational functions. The consequence of this is that if the poly-nomial interpolating function is made to ”fit” the function well around its pole thenthe error away from the pole which be much harder to control. The converse situationalso applies.

To compute Ri(i+1)...(i+m) we use the Burlisch-Stoer algorithm (which is an analogue ofNeville’s algorithm) which produces the so-called diagonal rational function. We start bysetting:

Ri = yi (3.2.5)

and apply the recursive formula:

Cm,i = Ri...(i+m) −Ri...(i+m−1)Dm,i = Ri...(i+m) −R(i+1)...(i+m) (3.2.6)

where

Dm+1,i =Cm,i+1(Cm,i+1 −Dm,i)(

x−xi

x−xi+m+1

)Dm,i − Cm,i+1

Cm+1,i =

(x−xi

x−xi+m+1

)Dm,i(Cm,i+1 −Dm,i)(

x−xi

x−xi+m+1

)Dm,i − Cm,i+1

(3.2.7)

Remark This procedure will converge to an interpolation function and for this interpo-lation function we will have an explicit error estimate.

23

Page 30: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Interpolation Documentation Chapter 3

3.3 Cubic Spline Interpolation

Consider a tabulated function yi = y(xi), i = 1, . . . , N . On a given interval [xj, xj+1] (i.e.for some fixed j) if we consider the linear interpolation we have:

y = Ayj + Byj+1 (3.3.8)

where,

A =xj+1 − x

xj+1 − xj

, B = 1− A =x− xj

xj+1 − xj

Remark It is the aim of cubic interpolation to get a interpolation function which issmooth in the first derivative and continuous in the second derivative.

If in addition to the tabulated values of yj, we also have the tabulated values for the

second derivatives, y(2), that is a set of numbers y(2)i , then we construct a cubic polynomial

which has zero second derivatives at xj and xj+1. Since we have three restraints this willdefine a unique cubic polynomial. This unique cubic polynomial is given by:

y = Ayj + Byj+1 + Cy(2)j + Dy

(2)j+1 (3.3.9)

where

C =1

6(A3 − A)(xj+1 − xj)

2, D =1

6(B3 −B)(xj+1 − xj)

2

and A, B are the same as above.

The only assumption we make here is that we assume that the second derivative existsat the interpolation points that is, it is continuous. Well the interpolation function whichwe constructed (3.3.9) can be seen by direct calculation to satisfy the relation:

xj − xj−1

6y

(2)j−1 +

xj+1 − xj

3y

(2)j +

xj+1 − xj

6y

(2)j+1 =

yj+1 − yj

xj+1 − xj

− yj − yj−1

xj − xj−1

(3.3.10)

Hence, the second derivative does exist even at the end point and is uniquely defined byone of the following two boundary conditions at x1 and xN :

� Set one or both of y(2)1 and y

(2)N are equal to zero, giving the so-called natural cubic

spline, which will have zero second derivatives on one or both of its boundaries

� Set the first derivative of the interpolating function have a specified value on eitheror both boundaries points, known as a clamped cubic spline

To summaries, cubic polynomials have the following property. If we interpolate two pointsusing a cubic polynomial then clearly the interpolating function is not unique because wehave only set two restraints on an equation with three unknowns. But we are ensureduniqueness under the conditions mentioned above, further by our explicit construction weknow that such an interpolating function exists.

24

Page 31: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Interpolation Documentation Chapter 3

3.4 Coefficients of an Interpolating Polynomial

You may wish to know not the value of the interpolating polynomial that passes througha (small) number of points, but the coefficients of that polynomial.

Remarks

� Generally speaking the coefficients of the interpolating polynomial can be determinedmuch less accurately than its value at a desired abscissa. Therefore it is not a goodidea to determine the coefficients only for use in calculating interpolating values.

� The interpolating polynomial (and its coefficients) is not the same thing as the poly-nomial of best fit through a data set. Interpolating is a process which smooths theoriginal data set, this is inevitable since the number of fitted coefficients is typicallymuch less than the number of data points. Therefore, fitted coefficients can be accu-rately and stably determined even in the presence of statistical errors in the tabulatedvalues.

We provide two methods of calculating the coefficients of the interpolating polynomial:

� Matrix Method The first method is of order N2 and uses the fact that to calculatethe coefficients {ci : i = 1, . . . , N} for:

y(xi) = c0 + c1x + c2x2 + . . . + cNxN (3.4.11)

we need to solve a system of linear equations. That is to diagonalize a matrix.

� Zero Method The second method is of order N3 and makes use of values whichthe interpolating function takes. We must assume that the coefficients of the in-terpolating function are unique. If we evaluate the interpolation (or extrapolation)polynomial at x = 0, then the value it takes will correspond to c0. Now we cansubtract c0 from each yi, make a change of variables x → x− c1, and divide throughby corresponding x − c1. Now by setting x = c1. Throwing out one point (the onewith smallest xi is a good candidate), we can repeat the procedure to find c1, and soon.

3.5 Interpolation in Two Dimensions

Here we will consider interpolation in 2-dimensions, the methods presented include:

1. Bicubic Interpolation

2. Bicubi Spline

Notation From now on will will use the notation f(. . .), to denote a function whichwill generally act on two independent variables. Since we will be working in the two di-mensional case.

25

Page 32: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Interpolation Documentation Chapter 3

Remark In multidimensional interpolation, we find an estimate of f(x1, x2, . . . , xn) froman n-dimensional grid of tabulated values f and n one-dimensional vectors giving the tab-ulated values of each of the independent variables x1, . . . , xn.

We will consider the case of two dimensions, the cases of three or more dimensions be-ing analogous in every way. In two dimensions we are given a matrix of functional valuesya[1 . . . m][1 . . . n]. We are also given an array x1a[1 . . . m], and an array x2a[1 . . . n]. Therelation of these input quantities to an underlying function y(x1, x2) is:

ya[j][k] = f(x1a[j], x2a[k]) (3.5.12)

We estimate, by interpolation, the function f at some un-tabulated point (x1, x2).

Fig: A typical grid cell for a two dimensional function.

We have two distinctly different directions that we can take in going beyond bilinearinterpolation to higher-order methods:

� Use higher order polynomials to obtain increased accuracy for the interpolated func-tion (for sufficiently smooth functions), without necessarily trying to fix up the con-tinuity of the gradient and higher derivatives

� Make use of higher order polynomials to enforce smoothness of some of these deriva-tives as the interpolating point crosses grid-square boundaries.

We will consider each of these two directions.

3.5.1 Higher Order for Accuracy

The basic idea is to break up the problem into a succession of one-dimensional interpola-tions. If we want to do m− 1 order of interpolations in the x1 direction, and n− 1 order

26

Page 33: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Interpolation Documentation Chapter 3

in the x2 direction, we first locate a m × n sub-block of the tabulated function matrixthat contains our desired point (x1, x2). We then do m one dimensional interpolations inthe x2 direction (i.e. on the rows of the sub-block), to get function values at the points(x1a[j], x2), for {j : 1 ≤ j ≤ m}. Finally, we do the last interpolation in the x1 directionto get the interpolation function.

3.5.2 Higher Order for Smoothness

We give two methods that are in common use and which are themselves not unrelated.The first is usually called bicubic interpolation. The other common technique for obtainingsmoothness in two-dimensional interpolation is the bicubic spline.

Bicubic Interpolation

Bicubic interpolation requires the user to specify at each grid point not just the functiony(x1, x2), but also the gradients ∂y/∂x1, ∂y/∂x2 and the cross derivative ∂2y/∂x1∂x2. Wefind an interpolating function with the following properties:

� the values of the function and the specified derivatives are reproduced exactly on thegrid points

� the values of the function and the specified derivatives change continuously as theinterpolating point crosses from one grid square to another

Bicubic Spline

This technique is equivalent to a special case of bicubic interpolation. To interpolate onefunctional value we will perform m one-dimensional splines across the rows of the table,followed by one additional one-dimensional spline down the newly created column. Insteadof pre-computing and storing all the derivative information (as in bicubic interpolation),we will pre-compute and store only one auxiliary table, of second derivatives in one direc-tion only. Then we need only to do spline evaluations (not constructions) for the m rowsplines; we must still do a construction and an evaluation for the final column spline.

Remark A spline construction is a process of order N , while a spline evaluation isonly of order log N .

27

Page 34: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Chapter 4

Equation Solver Documentation

This is the mathematical documentation that accompanies the Equation Solver module ofthe WebCab Functions .NET Service. Within this module we implement various numericalmethods for finding the solutions to equations in one or many real variables. These includeInterval Bisection method, Secant Method, Method of False Position, Ridders’ Method, Brent’sand Newton-Raphson.

4.1 Type of Problems we address

4.1.1 One Dimensional Problems

As mentioned above we consider the problem of finding solutions to equations of one realvariable which are continuous on a bracketed interval. That is, we wish to find solutionsto equations of the following form:

f(x) = 0

where x ∈ R (i.e. a real number). Such problems are known as 1-dimensional since thesolution will be found within a 1-dimensional space, namely the real number line.

Examples:

Polynomial and Rational Functions

1. f(x) = x2 − 2, continuous and differentiable on the whole of the real line and hassolutions ±

√2.

2. f(x) = (x− 2)2x, continuous and differentiable on the whole of the real line and hasa double root at 2, with another root at the origin.

3. f(x) = (x − 1)/(x − 2), continuous and differentiable at all points of the real lineexcept 2, and has one solution at 1.

Trigonometric Functions

28

Page 35: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Equation Solver Documentation Chapter 4

1. f(x) = sin x cos x, is continuous and differentiable on the real line and has solutionsat {πn

2: n ∈ Z}(i.e.0, ±π

2,±π,±3π2, . . .).

2. f(x) = tan x(:= sin x

cos x

), is continous and differentiable for all points where cos x 6= 0,

and has solutions at the points where sin x = 0.

4.1.2 Multi-dimensional Problems

In the multi-dimensional case there are two distinct types of problems:

1. Multi-dimensional Systems of equations: f(x, y, . . . , z) = 0

2. Systems of nonlinear multi-dimensional Equations (Not covered in this release):we are seeking solutions of systems of the following type:

f1(x, y, . . . , z) = 0

f2(x, y, . . . , z) = 0

...

fn(x, y, . . . , z) = 0

Examples:

Multi-Dimensional Equations

1. f(x, y) = yx− x2 + 1, has a infinite number of solutions

2. f(x, y) = y2 + x2, has a double solution x = y = 0

Multi-dinemsional Systems of Equations (not covered in this release)

1. This system has a solution at x = −2, y = 12:

x + 2 = 0

xy + x + 1 = 0

2. The independance of the equations ensure that determining even if a solution existsis non-trivial.

xy3 + x2 +√

y = 0

x2 + y = 0

x + y = 0

29

Page 36: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Equation Solver Documentation Chapter 4

4.2 Deciding what approach to use?

4.2.1 Continuous Equations of One real variable

Braketing Methods

In one dimension, apart from the Newton-Raphson approach each method proceeds in thefollowing way:

1. Bracket a solution, i.e. find two point where the function is positive and negativeand hence since the function is continuous, at least one solution must exist withinthe interval.

2. Iteratively srinks the solution interval down until the solution is found to a givenaccuracy level.

Therefore, the applicability of such methods will depend on our ability to find an inter-val in which a solution exists. With this component we provide advice (see below) andfunctionality to assist in finding a solution interval.

Newton-Raphson

The Newton-Raphson method though not needing the solution to be bracketed does requirethat a good initial estimate of the solution is given and moreover that the derivative ofthe equation can be evaluated. The Newton-Raphson method can be faster than all thebracketing methods but has the distinct disadvantage that is can diverge, particularly ifan inappropriate initial points is chosen.

4.2.2 Guide to method selection for 1-dimensional problems

Below to offer a quick guide which though not infallible does offer a quick and reasonablyreliable means in which to selected a suitable method for your intended purpose:

1. Brent’s Algorithm is the method of choice for finding a solution of a one-dimensionalequations when the function derivative is differcult to compute. Ridders Methodhowever should be considered a close competitor.

2. Newton-Raphson Algorithm approach is however preferred in the 1-dimensionalcase when the derivative can be evaluated, a good initial starting point can be foundand the function itself is know to behave well under this approach (for example it isconcave). Under these conditions this approach is the fastest.

3. Fail-Safe Newton-Raphson approach in our view combines the best of the Brack-eting and Newton-Raphson approach and will always converge to a solution. Thisapproach should be used when the differential it not expensive to evaluate, a braket-ing interval in known and you are not sure whether the function being consideredbehaves well under a Newton-Raphson only approach.

interval may be known a priori.

30

Page 37: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Equation Solver Documentation Chapter 4

4.3 Interval Bisection Method

Given a bracketed interval the interval bisection method will always converge to a solution.Given an interval (x1, x2) we choose a point halfway between x1 and x2, and evaluate thefunction. We replace either x1 or x2 depending upon which point given the same sign whenthe function is evaluated there. And so on. . .

Clearly after n iterations the root is known to lie within an interval of width εn where:

εn =|x1 − x2|

2n(4.3.1)

Thus, we have:

n = log2

|x2 − x1|ε

(4.3.2)

where ε is the desired ending tolerance.

4.4 Secant Method

Again we need to bracket the root [x1, x2], before applying the secant method. The func-tion needs to be evaluated at the bounds of the bracketed interval. The main idea is toassume that the function is linear in the neighborhood of interest. Then we use a linearapproximation of the function and get an improved bound by replacing one of the brack-eted bounds with the root of the equation.

Formally, we use the following relationship to calculate successive approximations:

xn = xn−1 −f(xn−1)× (xn−1 − xn−2)

f(xn−1)− f(xn−2)for n > 2 (4.4.3)

until the desired level of tolerance has been achieved.

It can be shown that the order of convergence is the ‘golden ratio” 1.618..., so that:

limk→∞|εk+1| ≈ const × |εk|1.618 (4.4.4)

where εn is the order of error after the n iteration.

Remark The disadvantage with the secant method is that if the equation is insufficientlylinear in the neighborhood of interest then the root may not lie within the bracketed regionand hence the method will not always converge.

4.5 Method of Regula Falsi

The regula falsi (or false position) method is based on the same algorithm implementedby the secant method. The only difference between the methods is that secant retains the

31

Page 38: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Equation Solver Documentation Chapter 4

most recent of the prior estimates; this requires an arbitrary choice on the first iteration,while false position retains that prior estimate for which the function value has oppositesign from the function value at the current best estimate of the root, so that the two pointscontinue to bracket the root.

For functions that are not sufficiently continuous the algorithm is not guaranteed to con-verge. The term ‘false position” refers to the fact that the method can use an older ratherthan newer function evaluation and hence has a lower order of convergence. Since the newerfunction value will sometimes be kept, the method is often superlinear but estimation ofits exact order cannot be generally determined.

4.6 Ridders’ Method

A powerful variant on the Secant method was developed by C.J.F.Ridders in the article:

Ridders, C.J.F. 1979, IEEE Transactions on Circuits and Systems, vol. CAS-26, pp. 979-980

If the root is bracketed between x1 and x2, Ridders’ method first evaluates function atthe midpoint:

x3 =(x1 + x2)

2(4.6.5)

Then we update our initial bracketed interval by:

x4 = x3 + (x3 − x1)sign[f(x1)− f(x2)]f(x3)√

f(x3)2 − f(x1)f(x2)(4.6.6)

Remark The new estimate x4 is guaranteed to lie in the bracketed interval.

The speed at which Ridders’ method converges is given by:

limk→∞|εk+1| ≈ cont × |εk|√

2 (4.6.7)

where εn is the order of the error after n iterations.

4.7 Van Wijngaarden-Dekker-Brent Method

Brent’s method combines root bracketing, bisection, and inverse quadratic interpolationto converge from the neighborhood of a zero crossing. While the false position and secantmethods assume approximately linear behavior between two prior root estimates, inversequadratic interpolation uses three prior points to fit an inverse quadratic function (x as aquadratic function of y) whose value at y = 0, is taken as the next estimate of the root x. Ofcourse one must have contingency plans for what to do if the root falls outside the brackets.

32

Page 39: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Equation Solver Documentation Chapter 4

Brent’s method takes care of all that. If the three point pairs are [a, f(a)], [b, f(b)], [c, f(c)]then the interpolation formula is:

x =[y − f(a)][y − f(b)]c

[f(c)− f(a)][f(c)− f(b)]+

[y − f(b)][y − f(c)]a

[f(a)− f(b)][f(a)− f(c)]+

[y − f(c)][y − f(a)]b

[f(b)− f(c)][f(b)− f(a)](4.7.8)

Setting y to zero gives a result for the next root estimate, which can be written as:

x = b +P

Q(4.7.9)

where, in terms of:

R ≡ f(b)

f(c), S ≡ f(b)

f(a), T ≡ f(a)

f(c)(4.7.10)

we haveP = S[T (R− T )(c− b)− (1−R)(b− a)] (4.7.11)

Q = (T − 1)(R− 1)(S − 1) (4.7.12)

Thus, Brent’s method combines the sureness of bisection with the speed of a higher-ordermethod when appropriate. It is recommended as the method of choice for general one-dimensional root finding where a function’s values only (and not its derivative or functionalform) are available.

4.8 Newton-Raphson Method

The Newton-Raphson method is the best known method for finding the roots of an equa-tion. This procedure can be generalized in various directions, in particular it can be appliedto finding solutions of non-linear equations. The reader should note that the assumptionsrequired by the Newton-Raphson method differ from the Bisection method in the followingways:

� The solution does not need to be bracketed but a point sufficiently close to a solutionmust be chosen

� The derivative of the interpolated function needs to be evaluated at a sequence ofpoints

� The method may not converge if the initial point is not sufficient close to a solutionor the interpolated function has certain pathological features such as it oscillates veryquickly close to a solution

Assuming that an initial estimate x0 of the solution to an equation f(x) = 0 is known, theNewton-Raphson method will produce a sequence of values {xn : n ∈ N}, which will shouldconverge. In particular, when f(x) is a rational function and x0 is chosen sufficiently well

33

Page 40: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Equation Solver Documentation Chapter 4

this sequence will always converge. If the algorithm fails to give a solution which in thecase of polynomials means xn → ±∞ or the sequence is stuck in something like a loop, thenwe repeat the process with another initial point. By calculating the derivative f ′(x)|x=x0

at the point x0, we draw the tangent to the curve at x0 and then trace this line down tothe x-axis which will give us our second point x1. Repetition of this process results in thedesired convergent sequence. In short, we use this iterative formula:

xn+1 = xn −f(xn)

f ′(xn), n ≥ 0 (4.8.13)

34

Page 41: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Chapter 5

Programmer’s Guide for Microsoftr

Office

This chapter describes the steps to take in order to integrate WebCab Functions with most Officedocuments, such as Excel worksheets, and Access documents. The integration is achieved boththrough VBA (Visual Basic for Application) code and features specific to the Office Applicationyou are using to write your documents. The information in this chapter applies equally toMicrosoft Office 2000, XP, and 2003 Applications and documents.

5.1 Developing with VBA from Office

This section describes how to write a VBA client for a business class documented in theAPI Reference for this product. The steps below are the same across all Microsoft OfficeApplications (Word, Excel, Access etc.) and involve using the Visual Basic Editor andwriting several lines of code:

1. Open the Visual Basic Editor

2. Add a Code Module

3. Declare a Subroutine

4. Declare a Class Instance Variable

5. Create a Class Instance

6. Call a Class Method

7. Display the Method Result

8. Run the Subroutine

35

Page 42: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Programmer’s Guide for Microsoft Office Chapter 5

Fig. 5.1: Starting the Visual Basic Editor in Excel

5.1.1 Open the Visual Basic Editor

In order to add VBA code to your Office document, you will first need to open the VisualBasic Editor, by going to the Tools | Macro | Visual Basic Editor menu, as shown in figure5.1.

5.1.2 Add a Code Module

In the upper-left corner of the Visual Basic Editor window, you can find all Office objectsassociated with your document. Right click any of the objects and select Insert | Module,as shown in Fig. 5.2 in order to add a new VBA module to your project. A code windowwill appear, where you will be writing the code to use this product’s functionality.

5.1.3 Declare a Subroutine

The first step in writing the code, which makes use of the functionality provided by thisproduct is to declare a subroutine, which can then be run directly from your Office Appli-cation. To declare a subroutine, use the Sub and End Sub keywords and the name you wishto assign to this subroutine. For example, in order to declare a subroutine named run, youwould write the code displayed in Fig. 5.3.

36

Page 43: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Programmer’s Guide for Microsoft Office Chapter 5

Fig. 5.2: Adding a module to a VBAProject

Fig. 5.3: Declaring a subroutine named “run” in VBA

5.1.4 Declare a Class Instance Variable

The API Reference for this product details all business classes, their methods and prop-erties, and gives advice on how to use each of them. You can browse the API Referencefrom the Start Menu at Programs | WebCab Components | Functions for .NET. In order tocall methods of a business class listed in the API Reference, you need to create a variableto hold a reference to its instance.

37

Page 44: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Programmer’s Guide for Microsoft Office Chapter 5

Fig. 5.4: Opening the “References” window in the Visual Basic Editor for Office

Declare a variable of type Object, regardless of the class you are going to call. For example,in order to declare a variable named instance, you would write the following line:

Dim instance As Object

5.1.5 Create a Class Instance

In order to create an instance of a business class listed in the API Reference, you will haveto write code that connects to its corresponding COM server1. There are two approachesin order to connect to a COM server.

� Using the ‘New BusinessClass’ CommandFirst go to the Tools | References... menu as shown in Fig. 5.4 in order to open

the “References” dialog window. Scroll down and select the entry named WebCabFunctions Demo from the list of available references in the dialog window and thenclick OK, as shown in Fig. 5.5. Adding a reference to this product is required onlyonce per document.

In order to create an instance of a business class, you must use the Set keywordin order to assign the class instance to the variable you have declared in the previousstep. The Set keyword is required in object assignments and omitting this keywordwill result in a run-time error. The reference assigned to this instance is createdby writing the New keyword, followed by the name of the business class you wish toconnect to.

For example, assume you wish to create an instance of a business class named Inter-polation, which is located in the WebCab Functions for .NET product. Figure 5.6

1“COM server” is a generic name for all COM classes, which provide functionality to VB and VBAapplications.

38

Page 45: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Programmer’s Guide for Microsoft Office Chapter 5

Fig. 5.5: Selecting a reference to a WebCab product, here ‘Functions’

Fig. 5.6: Creating a class instance by using the “New” command

shows how to create an instance of this class and how to assign it to the instance

variable declared in the step above.

� Using the ‘CreateObject’ CommandThere is another way to connect to a COM server, which does not involve adding

references to this product. It involves writing the full name of the business class

39

Page 46: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Programmer’s Guide for Microsoft Office Chapter 5

Fig. 5.7: Creating a class instance by using the “CreateObject” command

as declared within the API Reference, and sending this name to the CreateObject

command. The full name of a business class contains the namespace, followed by aperiod and the name of the class itself.

In order to create an instance of a business class, you must use the Set keywordin order to assign the class instance to the variable you have declared in the previousstep. The Set keyword is required in object assignments and omitting this keywordwill result in a run-time error. The CreateObject command will return a referenceto the business class instance, which will be assigned to the corresponding variable.

For example, in order to invoke a business class named Interpolation inside theWebCab Functions for .NET product, you would first find out its namespace fromits API Reference. The namespace is WebCab.Libraries.Math.Interpolation, meaningits full name is WebCab.Libraries.Math.Interpolation.Interpolation. In order to createan instance of this class using the CreateObject command, you would write the VBAcode shown in figure 5.7.

5.1.6 Call a Class Method

In order to call a method belonging to a business class for which you have created aninstance, you can use the name of the method as listed in the API Reference and appendit to the name of the variable that holds the class instance, separating it with a period.For example, in order to call a method named MyMethod, you could write the followingline of code:

result = instance.MyMethod (parameter-values)

40

Page 47: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Programmer’s Guide for Microsoft Office Chapter 5

where parameter-values are the ordered values of the parameters separated by a comma.The actual type of these parameters and that of the results variable depends on the signa-ture (i.e. the return type and parameter types) of the MyMethod method.

Remark For a more detailed Visual Basic example of how to invoke a method, seesection 5.1.9.

5.1.7 Display the Method Result

To see what the result of the method call was, you can display it inside a window by callingthe MsgBox function, as shown below:

MsgBox "The result of the method call was " & result

This line of code will display a small dialog window containing the result of the methodcall.

5.1.8 Run the Subroutine

After having finished writing the subroutine code as described in the steps below, you canrun the subroutine. There are several ways to run a subroutine, two of which are describedbelow:

1. Type F5 in the Visual Basic EditorYou can run your subroutine by placing the editing cursor within its body (i.e.between the Sub and End Sub keywords) and pressing the F5 key. This will instantlyexecute the subroutine, bringing up the result window.

2. Run the soubroutine as a macroYou can run the subroutine even after having closed the Visual Basic Editor, directlyfrom the Office Application you are using. Go to the Tools | Macro | Macros... menu,as shown in Fig. 5.8 to open the “Macro” dialog window. Select the macro, whichhas the same name as your subroutine and click Run (see Fig. 5.9).

41

Page 48: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Programmer’s Guide for Microsoft Office Chapter 5

Fig. 5.8: Opening the “Macro” window from the menu in Excel.

Fig. 5.9: Running a subroutine macro named run from Office.

42

Page 49: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Programmer’s Guide for Microsoft Office Chapter 5

' Declaring a subroutine named `run'Sub run()

Dim instance As Object' Creating an instance using `CreateObject'Set instance = CreateObject( _

"WebCab.Libraries.Math.Interpolation.Interpolation")

' Declaring the first parameter (a double array)Dim x(0 To 4) As Doublex(0) = 1x(1) = 2x(2) = 3x(3) = 4x(4) = 5

' Declaring the second parameter (a double array)Dim y(0 To 4) As Doubley(0) = 3y(1) = 2.4y(2) = 1.7y(3) = 1.4y(4) = 0.7

' Declaring the variable to hold the method resultDim result As Double

' Calling the `CubicSplinePointwise' method. All other' parameter values are being written here. The result' is stored in the `result' variable.result = instance.CubicSplinePointwise(x, y, -0.6, -0.7, 1.2)

' Printing the result inside a dialog windowMsgBox "The result of the method call was " & result

End Sub

Table 5.1: Generic Office VBA Example

5.1.9 A Generic VBA Example for Office

In this section we provide the complete VBA source code for a subroutine named run,which makes a call to a method in a business class and prints the result of the method callinside a window. The same steps mentioned above are being followed in this example.

The code in table 5.1 calls a method named CubicSplinePointwise, belonging to the Interpo-lation business class in the WebCab Functions product. This method takes five parameters,

43

Page 50: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Programmer’s Guide for Microsoft Office Chapter 5

of which the first two are one-dimensional arrays and the last three are double values. Themethod returns a double value.

5.2 Integrating with Microsoft Excel

This section is dedicated exclusively to Microsoft Excel users, who wish to tightly andseamlessly integrate the functionality provided by this product directly into Excel. At theend of this section, you will have learned how to create your own user-defined functions,which you can call directly from your worksheets as formulas or from the Insert | Function...menu. The following steps describe completely how to achieve integration of this product’sfunctionality within Excel:

1. Open the Visual Basic Editor

2. Add a Code Module

3. Declare a Function

4. Declare a Class Instance Variable

5. Create a Class Instance

6. Call a Class Method

7. Store the Method Result as a Function Return Value

8. Insert the Function in your Worksheet

5.2.1 Open the Visual Basic Editor

First you will need to open the Visual Basic Editor, by going to the Tools | Macro | VisualBasic Editor menu, as shown in figure 5.10. The Visual Basic Editor will allow you to writethe necessary VBA code that uses the functionality provide by this product.

5.2.2 Add a Code Module

In the upper-left corner of the Visual Basic Editor window, you can find all Microsoft Excelobjects associated with your workbook. Right click any of the objects and select Insert |Module, as shown in Fig. 5.11 in order to add a new VBA module to the existing VisualBasic project. A code window will appear, where you will be writing the code to use thisproduct’s functionality.

44

Page 51: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Programmer’s Guide for Microsoft Office Chapter 5

Fig. 5.10: Starting the Visual Basic Editor from Excel

Fig. 5.11: Adding a module to an Excel VBAProject

45

Page 52: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Programmer’s Guide for Microsoft Office Chapter 5

Fig. 5.12: Declaring a function named “MyFunction” in VBA

5.2.3 Declare a Function

In the source code window, declare a function using the Function and End Function key-words. You can pick any name you wish for this function, as you will be able to call itdirectly from a worksheet, like a regular Excel formula. You can change the name of thefunction at any later time, by simply editing the function declaration. Figure 5.12 showshow to declare a function named MyFunction.

5.2.4 Declare a Class Instance Variable

The API Reference for this product details all business classes, their methods and prop-erties, and gives advice on how to use each of them. You can browse the API Referencefrom the Start Menu at Programs | WebCab Components | Functions for .NET. In order tocall methods of a business class listed in the API Reference, you need to create a variableto hold a reference to its instance.

Declare a variable as an Object, regardless of the class you are going to call. For ex-ample, in order to declare a variable named instance, write the following line of code:

Dim instance As Object

5.2.5 Create a Class Instance

In order to create an instance of the business class you wish to use, you will need to pro-vide its “full name” to a special VBA method named CreateObject. The “full name” ofa business class is the name of its namespace (which you can find at the bottom of itsoverview page) followed by a period and the name of the business class.

46

Page 53: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Programmer’s Guide for Microsoft Office Chapter 5

For example, the Interpolation business class inside the WebCab.Libraries.Math.Interpolationnamespace has the following full name: WebCab.Libraries.Math.Interpolation.Interpolation.In order to create an instance of this class and assign it to the variable we have declaredin the previous step, we would write the following VBA code:

Set instance = CreateObject( _"WebCab.Libraries.Math.Interpolation.Interpolation")

5.2.6 Call a Class Method

In order to call a method belonging to a business class for which you have created aninstance, you can use the name of the method as listed in the API Reference and appendit to the name of the variable that holds the class instance, separating it with a period.For example, in order to call a method named MyMethod, you would write the followingline of code:

instance.MyMethod (parameter-values)

where parameter-values are the ordered values of the parameters separated by a comma.The actual type of these parameters and that of the results variable depends on the signa-ture (i.e. the return type and parameter types) of the MyMethod method.

Remark For a more detailed Visual Basic example of how to invoke a method, seethe next section, 5.2.7.

5.2.7 Store the Method Result as a Function Return Value

The result of the method call must be stored as the method’s return value, by assigningthe method’s result to the the the name of the function itself, as shown below:

MyFunction = instance.MyMethod (parameter-values)

The complete source code of a function named MyFunction is shown in table 5.2. Theexample calls the same method as the generic VBA example in section 5.1.9.

5.2.8 Insert the Function in your Worksheet

Switch back to the worksheet window and open the “Insert Function” window from theInsert | Function... menu (see Fig. 5.13). From the dialog window, click the drop-down listthat lists all the categories, and select the category named “User Defined”, as shown infigure 5.14.

47

Page 54: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Programmer’s Guide for Microsoft Office Chapter 5

' Declaring a function named `MyFunction'Function MyFunction()

Dim instance As Object' Creating an instance of the `Interpolation' business classSet instance = CreateObject( _

"WebCab.Libraries.Math.Interpolation.Interpolation")

' Declaring the first parameter (a double array)Dim x(0 To 4) As Doublex(0) = 1x(1) = 2x(2) = 3x(3) = 4x(4) = 5

' Declaring the second parameter (a double array)Dim y(0 To 4) As Doubley(0) = 3y(1) = 2.4y(2) = 1.7y(3) = 1.4y(4) = 0.7

' Calling the `CubicSplinePointwise' method. All other' parameter values are being written here. The result' is stored as a return value for this function.MyFunction = instance.CubicSplinePointwise(x, y, -0.6, -0.7, 1.2)

End Function

Table 5.2: The VBA code for a user-defined function in Excel

The name of your function will appear in the list of user-defined functions. Select itand click the OK button (Fig. 5.15). A window named “Function Arguments” will appear,asking for values for the arguments. In case your function takes no arguments, as in ourexample above, simply click OK, as shown in figure 5.16.

The current cell value will contain the value of a formula, which calls the “MyFunction”function with no parameters. The result of the formula, listed in the fx formula bar, willbe printed inside the cell, as shown in figure 5.17. You can change the formula directlyfrom the formula bar, or by opening again the “Insert Function” window.

You can also add a reference to the formula directly from the worksheet, by typing thevalue of the formula directly into the cell, without opening the “Insert Function” window,the same way you would call a standard Excel formula.

48

Page 55: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Programmer’s Guide for Microsoft Office Chapter 5

Fig. 5.13: How to open the “Insert Function” window in Excel

Fig. 5.14: Selecting the “User Defined” category

49

Page 56: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Programmer’s Guide for Microsoft Office Chapter 5

Fig. 5.15: Selecting the “MyFunction” user-defined function

Fig. 5.16: Inserting the “MyFunction” user-defined function into the worksheet

Fig. 5.17: The value returned by the “MyFunction” formula in an Excel worksheet

50

Page 57: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Chapter 6

Programmer’s Guide for VisualStudio 6

This chapter is dedicated to Visual Studio 6 developers, programming with either or both of theVisual Basic 6 and Visual C++ 6 languages. Using WebCab Functions from these languagescomes down to connecting to a COM server and making calls to it. The first section is forVisual Basic 6 developers, while the second section is for Visual C++ 6 developers.

6.1 Developing with Visual Basic 6

This section describes the steps required to use this product from VB6. These steps arealways the same, irrespective of the type of project you are developing. In an example atthe end of this section, we also provide a generic Visual Basic example of how to connectto our components from a “Standard EXE” Project.

Assuming you have already started a new project or opened an existing project, hereare the steps required to connect and use a WebCab Functions COM server:

1. Declare a Class Instance Variable

2. Create a Class Instance

3. Call a Class Method

6.1.1 Declare a Class Instance Variable

The API Reference for this product details all business classes, their methods and prop-erties, and gives advice on how to use each of them. You can browse the API Referencefrom the Start Menu at Programs | WebCab Components | Functions for .NET. In order tocall methods of a business class listed in the API Reference, you need to create a variableto hold a reference to its instance.

Declare a variable of type Object or Variant, regardless of the class you are going to

51

Page 58: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Programmer’s Guide for Visual Studio 6 Chapter 6

Fig. 6.1: Opening the “References” window in Visual Basic 6

call. For example, in order to declare a variable named instance of Object type, you canwrite the following line:

Dim instance As Object

6.1.2 Create a Class Instance

In order to create an instance of a business class listed in the API Reference, you will haveto write code that connects to its corresponding COM server. There are two approachesin order to connect to a COM server.

� Using the ‘New BusinessClass’ CommandFirst go to the Project | References... menu as shown in Fig. 6.1 in order to open

the “References” dialog window. Scroll down and select the entry named WebCabFunctions Demo from the list of available references in the dialog window and thenclick OK, as shown in Fig. 6.2. Once the reference has been added to your project,you do not need to add it again, no matter how many times or how many businessclasses you are going to call from your VB6 application. However, this step is re-quired before creating an instance of a business class using the New command.

In order to create an instance of a business class, you must use the Set keywordin order to assign the class instance to the variable you have declared in the previousstep. The Set keyword is required in object assignments and omitting this keywordwill result in a run-time error. The reference assigned to this instance is createdby writing the New keyword, followed by the name of the business class you wish to

52

Page 59: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Programmer’s Guide for Visual Studio 6 Chapter 6

Fig. 6.2: Selecting a reference to a WebCab product, here ‘Functions’

connect to.

For example, assume you wish to create an instance of a business class named Inter-polation, which is located in the WebCab Functions for .NET product. The followingline of code will create an instance of this class and assign it to the instance variabledeclared in the step above:

Set instance = New Interpolation

To avoid name clashing with other classes that may be named the same as thebusiness class you are instantiating, you can prefix the name of the business classwith the name VB6 assigns to the COM reference to this product. The name of thisreference in our example is WebCab_Libraries_FunctionsDemo:

Set instance = New WebCab_Libraries_FunctionsDemo.Interpolation

� Using the ‘CreateObject’ CommandThere is another way to connect to a COM server which does not involve addingreferences to this product. It involves writing the full name of the business classas declared within the API Reference, and sending this name to the CreateObject

command. The full name of a business class contains the namespace, followed by a

53

Page 60: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Programmer’s Guide for Visual Studio 6 Chapter 6

period and the name of the class itself.

In order to create an instance of a business class, you must use the Set keywordin order to assign the class instance to the variable you have declared in the previousstep. The Set keyword is required in object assignments and omitting this keywordwill result in a run-time error. The CreateObject command will return a referenceto the business class instance, which will be assigned to the corresponding variable.

For example, in order to invoke a business class named Interpolation inside theWebCab Functions for .NET product, you would first find out its namespace from itsAPI Reference. The namespace is WebCab.Libraries.Math.Interpolation, meaning itsfull name is WebCab.Libraries.Math.Interpolation.Interpolation. To create an instanceof this class, using the CreateObject command, you would write the following pieceof code:

Set instance = CreateObject( _"WebCab.Libraries.Math.Interpolation.Interpolation")

6.1.3 Call a Class Method

In order to call a method belonging to a business class for which you have created aninstance, you can use the name of the method as listed in the API Reference and appendit to the name of the variable that holds the class instance, the same way you would calla method or property in Visual Basic. For example, in order to call a method namedMyMethod, you could write the following line of code:

result = instance.MyMethod (parameter-values)

where parameter-values are the ordered values of the parameters separated by a comma.The actual type of these parameters and that of the results variable depends on the signa-ture (i.e. the return type and parameter types) of the MyMethod method.

Remark For a more detailed Visual Basic example of how to invoke a method see thefollowing section, 6.1.4.

6.1.4 A Generic Visual Basic Example

In this section we provide a generic VB6 client example, which invokes a method of a busi-ness class and prints the result to the screen. Although it might not directly apply to thisproduct, this example uses a real WebCab product, a real business class, and a real methodname, so that you can test it for yourself by downloading the corresponding Demo package.

The code below calls a method named CubicSplinePointwise, belonging to the Interpola-

54

Page 61: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Programmer’s Guide for Visual Studio 6 Chapter 6

Private Sub Form_Load()Dim instance As ObjectSet instance = CreateObject( _

"WebCab.Libraries.Math.Interpolation.Interpolation")

' Declaring the first parameter (a double array)Dim x(0 To 4) As Doublex(0) = 1x(1) = 2x(2) = 3x(3) = 4x(4) = 5

' Declaring the second parameter (a double array)Dim y(0 To 4) As Doubley(0) = 3y(1) = 2.4y(2) = 1.7y(3) = 1.4y(4) = 0.7' Declaring the variable to hold the method resultDim result As Double

' Calling the `CubicSplinePointwise' method. All other' parameter values are being written here. The result' is stored in the `result' variable.result = instance.CubicSplinePointwise(x, y, -0.6, -0.7, 1.2)

' Printing the result in a Message BoxMsgBox "The value of the function at the point 1.2 is " & result

End Sub

Table 6.1: A generic Visual Basic client example

tion business class in the WebCab Functions product. This method takes five parameters,of which the first two are one-dimensional arrays and the last three are double values. Themethod returns a double value.

You can use the code in table 6.1 by copy-pasting it inside any of your subroutines orfunctions. In our example, we placed the code inside the Form_Load subroutine, which isbeing triggered at the time the Application Form is first started.

55

Page 62: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Programmer’s Guide for Visual Studio 6 Chapter 6

6.2 Developing with Visual C++ 6

In order to connect and make calls to our COM servers from Visual C++ 6, you will needto write late-binding code. Since C++ is not as seamlessly integrated with COM as VisualBasic, we will need to go into more details regarding the use of COM servers. Although thebasic steps are the same, there are extra intermediate steps, which need to be performedin order to make successful calls to the COM server.

The steps are as follows:

1. Open a New or Existing Project

2. Add ‘Include’ Declarations

3. Call “CoInitialize”

4. Create a Class Instance

5. Obtain a Method ID

6. Declare the Parameter Values and Types

7. Declare the Return Type

8. Call the Method

9. Call “CoUninitialize”

6.2.1 Open a New or Existing Project

You can start a new Visual C++ Project by going to the File | New... menu (see Fig. 6.3),which will bring up the “New” dialog window. From this window, choose the “Projects”tab and select the Win32 Console Application. Type in the name of your project in theProject name text box (for example, Project1) and click OK, as shown in Fig. 6.4. In thenext window, select “A simple application” (see Fig. 6.5), click the Finish button, and clickOK in the next window as well. From the left hand side of the screen, switch to “FileView”and select the .cpp file with the same name as your project – as seen in Fig. 6.6. Notethat the source code snippets in this section apply both to a new project and to one ofyour existing projects.

56

Page 63: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Programmer’s Guide for Visual Studio 6 Chapter 6

Fig. 6.3: Starting a new project

57

Page 64: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Programmer’s Guide for Visual Studio 6 Chapter 6

Fig. 6.4: Starting a Console Application named “Project1”

58

Page 65: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Programmer’s Guide for Visual Studio 6 Chapter 6

Fig. 6.5: Creating a simple Console Application

59

Page 66: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Programmer’s Guide for Visual Studio 6 Chapter 6

Fig. 6.6: Location of the main C++ source code file, Project1.cpp

6.2.2 Add ‘Include’ Declarations

COM specific calls will require that the header file objbase.h is included within your project.This header offers functionality to enable C++ to interoperate with COM servers. To in-clude this header file within your project you will need to add at the top of your mainsource code file the following line:

#include "objbase.h"

6.2.3 Call “CoInitialize”

In order to allow Visual C++ clients to connect to a COM server, you need to make a callto a function named CoInitialize, which belongs to the objbase.h header file, mentionedabove. The call to the function must be made as shown below:

CoInitialize(NULL);

60

Page 67: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Programmer’s Guide for Visual Studio 6 Chapter 6

6.2.4 Create a Class Instance

In order to create an instance of a WebCab Functions business class, you will need toprovide the full name (i.e. the ProgId) of the business class, as declared within the APIReference. The full name of a business class contains the namespace, followed by a periodand the name of the class itself.

The C++ code below returns an instance of the Interpolation business class, located insideWebCab Functions for .NET. Its namespace is WebCab.Libraries.Math.Interpolation, mean-ing its full name is WebCab.Libraries.Math.Interpolation.Interpolation. You can easily adaptthe code below to create an instance of another business class, by replacing the ProgIdbelow with the full name of the class you wish to use.

CLSID clsid;CLSIDFromProgID(OLESTR( // Get the CLSID of the ProgId

"WebCab.Libraries.Math.Interpolation.Interpolation"),&clsid);

LPDISPATCH instance = NULL; // the COM `instance'LPUNKNOWN punk = NULL;

CoCreateInstance (clsid, NULL, CLSCTX_INPROC_SERVER,IID_IUnknown, (void**) &punk);

punk->QueryInterface(IID_IDispatch, (void**) &instance);punk->Release();

The variable named “instance” will hold the connection to the “Interpolation” COM server.

6.2.5 Obtain a Method ID

In order to call a method using the instance created above, you will need to obtain a ref-erence to its ID. Use the code below to obtain the ID of the method you wish to call, byreplacing the generic method name “MyMethod” with the name of the method you wishto call. The variable “methodID” will hold the reference to the method.

DISPID methodID; // The ID of the method

/** Replace `MyMethod ' with the name of the method you wish to call*/

unsigned short *methodName = L"MyMethod";instance->GetIDsOfNames(IID_NULL, &methodName, 1, LOCALE_USER_DEFAULT,

&methodID);

61

Page 68: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Programmer’s Guide for Visual Studio 6 Chapter 6

6.2.6 Declare the Parameter Values and Types

For every parameter, you will need to declare a variable of type VARIANT, whose type willbe set to the type of the parameter, and its value will correspond to the value you wishthe parameter to take. The code below shows how to declare the parameter values for amethod that takes two double parameters.

int noParameters = 2; // the number of parameters// 1st parameterVARIANTARG parameter1;parameter1.vt = VT_R8; // 8-bit real typeparameter1.dblVal = 100.0; // 100.0// 2nd parameterVARIANTARG parameter2;parameter2.vt = VT_R8; // 8-bit real typeparameter2.dblVal = 95.0; // 95.0

DISPPARAMS parameters; // the list of parametersmemset(&parameters, 0, sizeof(DISPPARAMS));parameters.cArgs = noParameters;parameters.rgvarg = new VARIANTARG[noParameters];memset(parameters.rgvarg, 0, sizeof(VARIANT) * noParameters);

// Add the parameters in reverse orderparameters.rgvarg[1] = parameter1;parameters.rgvarg[0] = parameter2;

For information about how to set other types of parameters, such as integers, booleanvalues, and arrays; we refer the read to this MSDN link.

6.2.7 Declare the Return Type

A VARIANT variable needs to be declared for the return value of the method as well. Thetype of the VARIANT will be automatically set by the method invocation, so you will onlyneed to initialize its type to VT_EMPTY by calling the VariantInit function.

VARIANTARG result; // Variable to hold the resultVariantInit(&result);

6.2.8 Call the Method

Calling the method comes down to using all the variables declared in the previous steps (theinstance, the method ID, the parameters, and the return value) in one call, as shown below:

62

Page 69: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Programmer’s Guide for Visual Studio 6 Chapter 6

// Call the underlying methodinstance->Invoke(methodID, IID_NULL, LOCALE_SYSTEM_DEFAULT,

DISPATCH_METHOD, &parameters, &result, 0, NULL);

The return value of the method is stored in the result variable, in the field correspondingto the method’s return type. For example, if the method returns a double, you will writethe following code in order to store the result in a double variable named “resultAsDouble”:

// Get the result as doubledouble resultAsDouble = result.dblVal;

6.2.9 Call “CoUninitialize”

In order to free generic COM related resources held by a C++ client, you must make acall to the CoUninitialize function. The call to this function can be made right before theend of your application or when your client no longer requires to use COM resources. Theline of code which releases all COM resources is:

CoUninitialize();

6.2.10 A Generic Visual C++ Example

In this section we provide a generic Visual C++ example of a simple Console Application,which connects to one of our business classes, invokes one of its methods and prints theresult in a window. The source code below works with a new Win32 Console Application,which can be created as described in section 6.2.1. Since this example’s structure in notspecific to the method being invoked, you may adapt this example to whatever businessclass, product, and method you wish to call.

This C++ application calls a method named Kairi, belonging to the MovingAverage busi-ness class in the WebCab Technical Analysis for .NET product. This method takes twodouble parameters and returns a double value.

63

Page 70: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Programmer’s Guide for Visual Studio 6 Chapter 6

// Project1.cpp, a Simple Win32 Console Application//

#include "stdafx.h"#include "objbase.h"#include "stdio.h"

int main(int argc, char* argv[]){

CoInitialize(NULL); // Enable C++ to COM interoperability

CLSID clsid;CLSIDFromProgID(OLESTR( // Get the CLSID of the ProgId

"WebCab.Libraries.Finance.Trading.Indicators.MovingAverage"),&clsid);

LPDISPATCH instance = NULL; // the COM `instance'LPUNKNOWN punk = NULL;

CoCreateInstance (clsid, NULL, CLSCTX_INPROC_SERVER,IID_IUnknown, (void**) &punk);

punk->QueryInterface(IID_IDispatch, (void**) &instance);punk->Release();

DISPID methodID; // The ID of the method

// The method name is `Kairi'unsigned short *methodName = L"Kairi";instance->GetIDsOfNames(IID_NULL, &methodName, 1, LOCALE_USER_DEFAULT,

&methodID);

int noParameters = 2; // the number of parameters// 1st parameterVARIANTARG parameter1;parameter1.vt = VT_R8; // 8-bit real typeparameter1.dblVal = 100.0; // 100.0// 2nd parameterVARIANTARG parameter2;parameter2.vt = VT_R8; // 8-bit real typeparameter2.dblVal = 95.0; // 95.0

Table 6.2: Generic VC++ example – Part 1

64

Page 71: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Programmer’s Guide for Visual Studio 6 Chapter 6

DISPPARAMS parameters; // the list of parametersmemset(&parameters, 0, sizeof(DISPPARAMS));parameters.cArgs = noParameters;parameters.rgvarg = new VARIANTARG[noParameters];memset(parameters.rgvarg, 0, sizeof(VARIANT) * noParameters);

// Add the parameters in reverse orderparameters.rgvarg[1] = parameter1;parameters.rgvarg[0] = parameter2;

VARIANTARG result; // Variable to hold the resultVariantInit(&result);

// Call the `Kairi' methodinstance->Invoke(methodID, IID_NULL, LOCALE_SYSTEM_DEFAULT,

DISPATCH_METHOD, &parameters, &result, 0, NULL);delete [] parameters.rgvarg;

// Get the result as doubledouble percentage = result.dblVal;// Print the result inside a MessageBoxchar text[200];sprintf(text, "The percentage is %lf", percentage);MessageBox(NULL, text, "Method result", MB_OK);

CoUninitialize(); // Free all COM specific resourcesreturn 0;

}

Table 6.3: Generic VC++ example – Part 2

65

Page 72: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Chapter 7

Programmer’s Guide for .NET

This chapter describes development techniques for various business solutions that make useof the functionality provided by our .NET Service. We analyze both standard and enterprisesolutions, including stand-alone applications, ASP.NET pages, and XML Web services.

7.1 Developing with .NET Class Libraries

The .NET Edition of this product offers core-level functionality to the .NET developerallowing the implementation of fully personalized components and applications for specificbusiness problems on a variety of deployment environments. Irrespective of the complexityof the project a programmer may be working on, this .NET Service can be integrated inan equally straightforward manner by providing the needed functionality in a compact andprecise way.

The Functions for .NET v2.0 component comes as a collection of DLL files. Each DLL is apacked collection of classes that provide the functionality offered by this .NET Service asdocumented inside the API reference directory of this package. Depending on the type of.NET solution you are developing, you will be using these DLL files in a specific way. Onceyou have chosen a particular implementation of a deployment framework, the structure ofyour source code will need to adapt accordingly. In the following discussion we describeseveral basic .NET implementation examples that can be used to make use of our product’sfunctionality.

7.1.1 Stand-alone C# .NET Applications

A stand-alone C# application is a C# class which acts as a client for the deployed .NETcomponents (i.e. DLLs). The source code listed below defines a standard stand-aloneapplication skeleton which communicates with a class within a .NET Component. By cre-ating an instance, calling a method, sending in a set of parameters and then retrieving thereturned result of the method call. As soon as the method call has gone through success-fully the method continues by displaying its result on the screen.

66

Page 73: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Programmer’s Guide for .NET Chapter 7

/*

* The class we are is located inside the WebCab.Libraries.NetService

* namespace.*/

using System;

using WebCab.Libraries.NetService;

public class StandAloneExample {

public static void Main () {

/*

* Creates an instance of the NetClass class*/

NetClass instance = new NetClass ();

/*

* Defines the method parameter.*/

double parameter = 25;

/*

* Invokes a method with the specified parameter* and puts the result in the result variable.*/

double result = instance.ComputeResult (parameter);

/*

* Prints out the retrieved result.*/

Console.WriteLine ("Method ’ComputeResult’ in class NetClass

returned " + result + ".");

}

}

If the method ComputeResult of the NetClass class returned 100, this stand-alone appli-cation would print the following:

Method ’ComputeResult’ in class NetClass returned 100.

67

Page 74: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Programmer’s Guide for .NET Chapter 7

7.2 Developing with XML Web Services

This component has been XML Web service enabled and the relevant deployment files canbe deployed which means that you may deploy the Application as a web service and makethe methods contained therein available as XML Web service methods.

7.2.1 Deploying the XML Web Services

Using Windows XP with .NET Framework and IIS installed

In order to deploy this .NET Service as an XML Web service you will need to go throughthe following steps:

� Copy DLL Files - copy the DLL files provide into the bin directory of the IIS serversdirectory. On the standard install this is located at:

C:\Inetpub\wwwroot\bin

� Copy asmx Files - now copy the asmx files included into the folder:

C:\Inetpub\wwwroot\

Now the web service can be accessed through the URL:

http://localhost/WebServices/filename.asmx

Remarks

1. If you prefer to change the URL in which the XML Web service can be accessedthen just create and then copy the asmx files into another subfolder of the ‘wwwroot’directory, in which case the corresponding URL of the web service will correspondingchange.

2. In order to copy the installation files to your IIS location you will need to haveappropriate read and write access to the folder under question.

7.2.2 Writing XML Web Service Clients

The building of an XML Web service client will require the following steps:

� Create a proxy class for the XML Web service.

68

Page 75: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Programmer’s Guide for .NET Chapter 7

� Reference the proxy class in the client code.

� Create an instance of the proxy class in the client code.

� Call the method on the proxy class corresponding to the XML Web service methodyou want to communicate with.

For most clients, these steps differ only on how the proxy class is referenced and how theXML Web services are deployed.

7.2.3 Writing Console XML Web Service Clients

An XML Web service client may take a number of forms including a console application,ASP.NET page, HTML page, Windows Form, Java Applet/Frame and any other XMLWeb service enabled client technology.

Here in order to illustrate the core step involved in making a client we describe the stepsrequired to build a console application. Creating other types of clients will involve similarsteps. We assume that you have the .NET Framework installed (on the client and server)and that the IIS server has (been installed and) started on the server.

To create a console XML Web service client application you must:

� Deploy the DLL provided into a bin which you need to create somewhere in a subdi-rectory of the IIS web server you plan to use. The default location for this web serveron your local machine is ‘C:\Inetpub\wwwroot’. The DDL is the required XML Webservice .NET assembly file.

� Deploy the web service descriptor ‘Classname.asmx’ provided, into a IIS web-serversubdirectory.1 Note that we will assume below that the URL of the deployed Class-name.asmx file is:

http://yourserver/Webservices/Classname.asmx

� Create a XML Web service proxy by using the WDLS command line tool. Enter aDOS prompt in the directory where you intend to (develop and) run your consoleapplication from and type at the command line:

Wsdl.exe http://yourserver/Webservices/Classname.asmx

1The purpose of the asmx file is to tell the server that the XML Web service exists so that it may startsearching for the relevant classes within the DLL files in the bin directory. Hence, the asmx file is verysimple and consists of the one line:

<%@ WebService language="C# " class="Classname" %>

and is saved as a TXT file with an extension .asmx.

69

Page 76: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Programmer’s Guide for .NET Chapter 7

That is ‘Wsdl’ followed by the URL of the asmx file for the XML Web service. Thisutility will generate a C# file which will be written to the present directory (whichshould be the clients directory)2. The WSDL file is an interface (in OOP terminology)or proxy for the DLL C# implementation of the XML Web service.

� Write a console application in the standard way and instantiate the WebService meth-ods (as if the DLL is hosting locally) using the WSDL proxy. See the below template:

using System;

public class ClassnameClient {/// <remarks>

/// The Main method ensures that the console will run.

/// </remarks>

static void Main() {/*

* We instantiate the "object" represented by

* the proxy class.

*/

Classname classnameObject = new Classname();

/*

* We invoke the ‘Compose’ method of the

* Classname XML Web service

*/

Console.WriteLine("XML Web service method Compose

applied to 7.0 and 3.9 is " +

classnameObject.Compose(7, 3.9));

}}

2WSDL is a standard by which all XML Web services are described. See http://www.w3.org/TR/wsdl

70

Page 77: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Programmer’s Guide for .NET Chapter 7

7.2.4 Importing Web services into Visual Studio .NET projects

Fig: Adding a Web reference.

Fig: Adding a Web reference.

71

Page 78: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Programmer’s Guide for .NET Chapter 7

7.3 Connecting to a Database with our .NET Libraries

7.3.1 Overview

Most of the financial and mathematical functionality provided by this .NET Service is in-tended for use within a multi-tier environment where the back-end role is taken by an SQLDatabase server. By packaging this functionality within .NET components such as XMLWeb services and .NET Class Libraries we separate the business logic from the databaselogic, allowing you to customize the way you access the database and the way the retrieveddata is sent to the business methods.

In order to assist you in developing DBMS based .NET solutions, we provide the ADOMediator as a standardized way of using our .NET components with an SQL Databaseserver. The ADO Mediator is also a .NET component, which sits on the same level as theother financial and mathematical .NET components and is a seamlessly integrated compo-nent of this .NET Service. While reducing the amount of DBMS code you have to type, itallows you to concentrate on the SQL queries and procedure calls to the Database serverand map the stored data directly to the business methods of this .NET Service.

The ADO Mediator’s functionality has been enabled for use with the following modulescontained within the WebCab Functions for .NET v2.0:

� The “Interpolation and Extrapolation” Module

7.3.2 The ADO Mediator

There is one ADOMediator class for every module in this .NET Service. You will use thecorresponding ADOMediator class for performing Database operations with classes of a cer-tain module. The ADO Mediator class is located inside the ‘ADO’ subnamespace of itscorresponding module. For example if a module contains the:

WebCab.Libraries.Finance.Trading

namespace, its ADOMediator class will be found under:

WebCab.Libraries.Finance.Trading.ADO.ADOMediator.

Configuring the ADO Mediator

There are three steps to perform in order to start using an ADO Mediator class:

1. Specify the ADO.NET DriverThe constructor accepts an input connection and an output connection. There is norestriction that you should provide both an input and an output connection. Youmay choose to read data and display it inside your Application, compute data andwrite it into the database, or read and write to and from the database, and specifyonly the input or output database connection.

72

Page 79: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Programmer’s Guide for .NET Chapter 7

Connecting to your database requires an ADO.NET Driver. This driver is a .NETclass which is part of a DLL file provided by your Database vendor. You specifythe driver you wish to use by sending in to the ADOMediator constructor its run-timetype. That is, if your driver class name is System.Data.SqlClient.SqlConnection3,its run-time type under C# is specified by typing inside your source code:

typeof (System.Data.SqlClient.SqlConnection)

2. Provide the input/output ConnectionString propertyThe ConnectionString property is a piece of text which describes the Database servermachine address, the credentials, and additional information required in order toobtain access to certain parts of your Database server. This piece of text is alwaysdocumented by the provider of the ADO.NET Driver and should be used as suchwhen submitting it to an ADOMediator constructor. An example for the previousADO.NET SQL Server driver would be:

"Initial Catalog=Northwind;Data Source=localhost;Integrated Security=true;"

You may easily notice that the string above describes the machine name and theinitial catalog to connect to. The Integrated Security=true bit enables you toconnect to the SQL Server 2000 by using the current Windows login username andpassword.

3. Assign a business .NET componentThe previous two steps are part of creating an instance of an ADOMediator class andtaking care of the Database connections. This third step involves specifying the busi-ness class belonging to this module which deals with the financial and mathematicalfunctionality. Choose a class of the corresponding module and assign an instance ofthis class to the UnderlyingInstance property of the previously created ADOMediator

instance.

For example, if the name of the class you choose is TradingClass, you could writethe following C# code4:

TradingClass aTradingClassInstance = new TradingClass ();adoInstance.UnderlyingInstance = aTradingClassInstance;

Using the ADO Mediator

Once these three steps have been performed, you may use the created ADOMediator instanceto perform Database related calculations using the assigned .NET business class. There

3The built-in ADO.NET driver class name for connecting to the MS SQL Server4We assume adoInstance is the name of the previously created ADOMediator instance.

73

Page 80: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Programmer’s Guide for .NET Chapter 7

are several methods which you may use with your ADO Mediator instance. Some methodsallow you to read from the database and perform calculations for every retrieved row, andthen store the result in a .NET variable. Other methods allow you to specify the inputvalues and write the result in the database. There are also methods which allow you toread the input parameters from the database and write the method results back into thedatabase in one go.

The basic methods of the ADO mediator are:

� Select Method - Allows you to retrieve the results of a method of your choice be-longing to the underlying business class instance, applied to every row of an SQLSELECT query.

� Update Method - Directly updates values inside your database, as returned by amethod belonging to the underlying business class instance.

� SelectAndUpdate Method - Allows you to combine the two methods mentioned aboveby selecting the data, computing the results and writing it back to the database,according to your own criteria.

A complete API reference for these methods is found inside the Documentation folder ofthis pack. The Windows Installer (MSI) for this .NET Service has also created a short cutto this documentation from the Start Menu.

How the ADO Mediator Works

The way the ADO Mediator processes requests from the client and transfers them to the.NET components and the Database is shown in the diagram below.

74

Page 81: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Programmer’s Guide for .NET Chapter 7

Fig: This diagram describes how the ADO Mediator passes onto the Database andthe .NET components its client requests.

C# Source Code Example

The following C# source code makes use of the ADO Mediator’s functionality in order toread and update the database according to a known algorithm. We use the standard SQLServer ADO.NET Driver to connect to a fictitious table named TRADES, and invoke theTradingMethod method of the TradingClass business class.

75

Page 82: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Programmer’s Guide for .NET Chapter 7

using System;using System.Data.SqlClient;using WebCab.Libraries.Finance.Trading;using WebCab.Libraries.Finance.Trading.ADO;...try {.../** We specify the same driver and connection string for both the input and output* connections to the SQL Server 2000 Database server.*/

ADOMediator adoInstance = new ADOMediator (typeof (SqlConnection), // Input

"Initial Catalog=Northwind;Data Source=localhost;Integrated Security=true;",typeof (SqlConnection), // Output

"Initial Catalog=Northwind;Data Source=localhost;Integrated Security=true;");

/** We assign an instance of the TradingClass business class to the newly created* instance of this ADO Mediator.*/

adoInstance.UnderlyingInstance = new TradingClass ();

/** We invoke the SelectAndUpdate method which will populate the table according to* the result of the method and the position of the input values in the database.*/

adoInstance.SelectAndUpdate ("TradingMethod","SELECT C ID, SHARES, VALUE FROM TRADES", // Select"UPDATE CUSTOMER SET MONEY=@MONEY WHERE C ID=@C ID", // Update"@MONEY", // Maps the ‘TradingMethod’ method result to @MONEY{new Object[] {"@C ID", "C ID"}}, // Maps C ID to @C IDfalse); // True when updating with a stored procedure

}catch (ADOMediatorException e) {Console.WriteLine (e);

}

Using ADO Mediator with SQL Server 2000

The ADO Mediator instance above requires the same information as in the case of writingyour own ADO.NET source code. The difference lies in the fact that you do not have tomanually control the driver specific operations such as opening and closing a connection,and only concentrate on your SQL queries and the functionality of our business classes.You start by following the three steps mentioned above5 and continue by making calls toany ADOMediator methods.

5Specifying the input and/or output ADO.NET drivers and their connection strings and assigning aninstance of the fictitious TradingClass business class.

76

Page 83: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Programmer’s Guide for .NET Chapter 7

As you may notice, the SelectAndUpdate method above follows a logical pattern of de-scribing how the data should be read from the database, computed, and written back,with special care to the use of named parameters. You do not require previous experiencein dealing with named parameters, as they are basically a way to substitute real values withnames inside SQL queries. You may have spotted the @MONEY and @C ID named parametersin our UPDATE statement above. These named parameters will be replaced with real values,taken either from the TradingMethod’s result, or directly from a column returned by theSELECT query.

In our case, we replace @MONEY with the result of applying the TradingMethod method6

to the values of the SHARES and VALUE columns returned by the SELECT query. The sec-ond named parameter (@C ID) is replaced directly by the value of the C ID column of theSELECT query. For more information about named parameters you may wish to consult yourADO.NET driver’s manual. Most special cases are related to the use of named parametersand have been covered by the current version of the ADO Mediator.

6Which in our example belongs to the fictitious TradingClass business class.

77

Page 84: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Chapter 8

Examples

Within this chapter we illustrate how the Functions Component can be applied to solvereal life problems. We provide with this Component examples of two types:

1. QA Examples

2. Custom Examples

8.1 Question and Answer (QA) Client Examples

8.1.1 Overview

Within this folder we offer client examples written using a number of .NET compliantlanguages for the .NET Business Components provided within this package. In particular,for each business method contained within each business Component we provide an exampleimplemented within C# , VB.NET and C++.NET; which illustrates how functionalitycontained within this component can be applied to solve real world problems. In addition,to these examples we also include custom applications which solve some of the genericproblems which this Component is designed to address.

8.1.2 Structure of QA Examples Directory

By drilling down the QA Client directory structurr you will find the following six directorylevels:

1. Client Level2. Language Level3. Business Module Level4. Business Class Level5. Example Level6. Custom Example Level

which have the structure as shown in the following diagrams.

78

Page 85: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Examples Chapter 8

Top Three levels of the QA Directory Structure

(Client Level) (Language Level) (Business Module Level)

QAClients +

|

+ C# ------------------------+

| |

+ VB.NET --+... + ‘Business Module 1’ ----------

| |

+ C++.NET --+... + ‘Business Module 2’ --+...

| |

+ QALibrary.dll + ...

|

+ QALibraryModule.netmodule

|

+ Readme.txt

Bottom Three levels of the QA Directory Structure

(Business Class Level) (Example Level) (Custom Example Level)

--+

|

+ ‘Business Class 1’ --------+

| |

+ ‘Business Class 2’ --+... + ‘BusinessClass’.exe.conf

| |

+ ... + ‘BusinessClass’.cs

|

+ compile.bat

|

+ run.bat

|

+ run_gui.bat

|

+ ‘CustomClient’ -------+ ‘CustomClient’.cs

| |

+ ... + compile.bat

|

+ run.bat

79

Page 86: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Examples Chapter 8

8.1.3 Quick Start Guide

Browse down to the particular client within the business module for the given .NET com-patible language which you are interested in. Run the compile.bat, script in order tocompile the example and then run the run.bat, script in order to run the example.

8.1.4 Explanation of the QA Directory Structure and its files

1. Client Level

The directory containing the Questions and Answer Examples is named ‘QAClients’.This directory can be located by using the Readme.html file, which is presented atthe end of the installation process, by selecting:

Run Examples > Run .NET Class Library Examples

The Readme.html file can also be opened from the shortcut:

Start > Programs > WebCab Components > ‘Name of Components Package’ > Readme.html

2. Language Level

Within the ‘QAClients’ folder is the Language level of the QA directory structure.Within this folder you will find 3 sub-directories: C# , VB.NET and C++.NET;which contain examples written in each of the .NET languages C# , VB.NET andC++.NET respectively. Within this folder you will also find the following three files:

� QALibrary and QALibraryModule.netmodule - contain utility function-ality necessary for running the clients. If you wish to run these examples fromwithin Visual Studio .NET (for example) then you will need to register this DLLwithin your VS.NET project.

� Readme.txt - this Readme file.

As mentioned above within the overview we provide an implementation of each ‘Ques-tion and Answer’ example as three eqivalent implementations, namely: a C# client,a VB.NET client and a C++.NET client. Selecting one of the three folders C# ,VB.NET or C++.NET; in order to view the client implementated within the corre-sponding language.

3. Business Module Level

After selecting one of the sub-folders C# , VB.NET, C++.NET at the ‘LanguageLevel’ (see (2) above) you will enter a folder which contains a sub-folder for each ofthe modules contained within this component package. The modules are convenientcollections of business classes containing the business functionality offered by thiscomponent. Each module has a sub-folder which contains the ‘Question and Answer’examples of each method of the classes which it contains.

80

Page 87: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Examples Chapter 8

4. Business Class Level

At the business class level under the module level we are presented with one sub-folderfor each of the classes within the business module. Each of these folders contains thefiles of the examples for each of the methods contained with the respective class.

5. Example Level

At the Example level you will be presented with the files which allow you to compileand then run the examples of the application of the Business methods of the respec-tive class. The files within this directory which constitute the Client example are asfollows:

� Source Code File(s) - Depending on the .NET compatible language selectedat the ‘Language Level’ this folder will contain a source code file(s) with theextension .cs, .vb or .cpp corresponding respectively to the C# , VB.NET orC++.NET client.

� Configuration File - Apart from the main source code file the folder willalso contain a configuration file with the extension .conf, this file contains theinformation concerning the location of the DLLs which the example will require.You may add more references as needed but you should not remove the referencesalready contained within this file.

� Compile Batch File - Assuming that you have access to the relevant C# ,VB.NET or C++.NET compiler the compile batch file (compile.bat) once runwill compile the client example from the folders source code file. Below weinclude some remarks on how to obtaining suitable .NET compilers in order tobe able to compile and then run these C# , VB.NET and C++.NET examples.

� Run Batch File - The run batch file (run.bat) will run the examples executablefile (exe) which is generated from the compilation of the source code file. If theexample over runs your console screenful then press space in order to page down.

6. Custom Example Level

At the Custom Example level you will find a source code file containing the im-plementation of the Application which addresses a typical question for which theComponent is designed. The source code has a linear structure with full inline com-mentary. By just running the compile and then run scripts contained within thisdirectory you will be able to solve to given problems view the results obtained. Thefiles contained within each Custom Client Example directory are as follows:

� Source Code File(s) - Depending on the .NET compatible language selectedat the ‘Language Level’ this folder will contain a source code file(s) with theextension .cs, .vb or .cpp corresponding respectively to the C# , VB.NET orC++.NET client.

81

Page 88: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Examples Chapter 8

� Compile Batch File - Assuming that you have access to the relevant C# ,VB.NET or C++.NET compiler the compile batch file (compile.bat) once runwill compile the client example from the folders source code file. Below weinclude some remarks on how to obtaining suitable .NET compilers in order tobe able to compile and then run these C, VB.NET and C++.NET examples.

� Run Batch File - The run batch file (run.bat) will run the examples executablefile (exe) which is generated from the compilation of the source code file. If theexample over runs your console screenful then press space in order to page down.

8.1.5 Remarks on .NET compilers

1. Required compilers and how to test for them

In order to compile the C# , VB.NET or C++.NET examples you will require foreach of these .NET languages a suitable compiler. The easiest way in which to testwhether you have access to the three main .NET language compilers at your com-mand prompt is to type the follow commands at the command line:

csc - Invokes the C# compilervbc - Invokes the VB.NET compilercl - Invokes the C++.NET compiler

2. How to obtain the required compilers

Compilers for the C# and VB.NET .NET compatible languages are provided withinthe .NET SDK v1.0 (or higher). At the time of writing within the standard Microsoft.NET SDK the C++ compiler is enabled only as a C compiler.

In order to obtain the C# and VB.NET command line compilers you simply needto download and install the .NET SDK available from the Micrsoft site. In orderto obtain a fully functional C++.NET compiler you can either download and installMicrosoft’s feeely available and fully functional Visual C++ Toolkit 2003, availablefrom: http://msdn.microsoft.com/visualc/vctoolkit2003/; or use the C++ compilerwhich is provided with Microsoft’s Visual Studio .NET IDE.

8.2 Functions and Methods Considered

Within the QA Clients for the Equation Solver module we consider example which findthe solution to the corresponds equations f(x) = 0, for the following functions:

Test FunctionsThese functions performance is examined in detail below (see (8.3)).

82

Page 89: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Examples Chapter 8

1. TestFunction1: f(x) = exp(x)−3x2, both functions are smooth and there is going tobe two solutions, one positive and the other negative. By evaluating f(−10), f(0),and f(10), you can see that both solutions will lie in the interval [−10, 10]. Thisinterval such be used however in our examples we use the interval [2, 4], so that thereis only one solution within this interval of the equation f(x) = exp(x)− 3x2 = 0.

2. TestFunction2: f(x) = −x3 + x2 + x + 1, a reasonable interval to consider is [−2, 2],since the two solutions lie within this interval. In order to consider an interval inwhich only one solutions exists we consider the function on the interval [1.2].

3. TestFunction3: f(x) = exp(x)− 11+x2 , here we use the interval [−1, 2] which contains

one solution to the equation f(x) = 0.

4. TestFunction4: f(x)x+x−x2cos(x), for this function we consider the interval [−10, 10].

Other Functions used in the Examples

1. QuadraticDistinctSolutions: f(x) = x2 + 2, where the interval [−2.5, 2.5] is givenwhen required.

2. QuadraticDoubleSolution: f(x) = x2, where the interval [−5, 5] is given when re-quired.

3. RapidlyOscillatory: f(x) = sin(1/(x + 0.1)), where the interval [−1, 1] is givenwhen required.

4. RationalFunction: f(x) = (x−1)(x−2)

, where the interval [−1, 1] is given when required.

5. SumOfExponentials1: f(x) = 2 exp(x)+3 exp(2x)+4 exp(4x)−9, where the interval[−5, 5] is given when required.

6. SumOfExponentials2: f(x) = 2 exp(−x) + 3 exp(−2x) + 4 exp(−4x) − 9, where theinterval [−5, 5] is given when required.

7. SumOfExponentials3: f(x) = 2 exp(−x) + 3 exp(−2x) + 4 exp((0.1)x)− 9, where theinterval [−5, 5] is given when required.

8. SumOfLogarithms1: f(x) = 2 log(x) + 3 log(2x) + 4 log(4x), where the interval [0, 5]is given when required.

9. SumOfLogarithms2: f(x) = 2 log(−x) + 3 log(−2x) + 4 log(−4x), when the interval[−5, 0] is given when required.

10. SumOfLogarithms3: f(x) = 2 log(−x)+3 log(−2x)+4 log(−(0.1)x), when the interval[−5, 0] is given required.

For each one of these functions we apply each the equation solver procedures containedwithin the Equation Solver module.

1. Bisection Procedure without interval given: Bisection(double precision)

83

Page 90: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Examples Chapter 8

2. Bisection Procedure with interval given: Bisection(double beginningOfInterval,

double endOfInterval, double precision, long noOfIterations)

3. Secant Procedure without interval given: Secant(double precision)

4. Secant Procedure with interval given: Secant(double beginningOfInterval, double

endOfInterval, double precision, long noOfIterations)

5. Brent Procedure without interval given: Brent(double precision)

6. Brent Procedure with interval given: Brent(double beginningOfInterval, double

endOfInterval, double precision, long noOfIterations)

7. Regula Falsi Procedure without interval given: (double precision)

8. Regula Falsi Procedure with interval given: RegulaFalsi(double beginningOfInterval,

double endOfInterval, double precision, long noOfIterations)

9. Ridders Procedure without interval given: Ridders(double precision)

10. Ridders Procedure with interval given: Ridders(double beginningOfInterval, double

endOfInterval, double precision, long noOfIterations)

11. Newton-Raphson Procedure without interval given: NewtonRaphson(double precision)

12. Newton-Raphson Procedure with interval given: NewtonRaphson(double startingPoint,

double precision, long noOfIterations)

13. Newton-Raphson Fail Safe Procedure without interval given: NewtonRaphsonFailSafe(doubleprecision)

14. Newton-Raphson Fail Safe Procedure with interval given: NewtonRaphsonFailSafe(doublebeginningOfInterval, double endOfInterval, double precision, long noOfIterations)

8.3 Detailed Analysis of the Performance of the four

Test Functions

This section provides examples of the application of the equations solver module to find thesolutions of the four Test functions using all the procedures implemented within the EquationSolver module of this .NET Service.

8.3.1 Overview

For the below listed four Test Functions we performed benchmark tests in order to find thenumber of iterations required to order to find the given solution of the given function to thegiven level of precision.

84

Page 91: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Examples Chapter 8

We which the find the real roots of the following equations, where the precision usedis varied between the three values 10−3, 10−5 or 10−7:

ex − 3x2 = 0 (8.3.1)

x3 = x2 + x + 1 (8.3.2)

ex =1

1 + x2(8.3.3)

Also, we find the solution to the following equation:

x + e−x2

cos(x) = 0 (8.3.4)

That is, we consider the equation solver problems corresponding to the functions given by:

1. TestFunction1: f(x) = exp(x)− 3x2

2. TestFunction2: f(x) = −x3 + x2 + x + 1

3. TestFunction3: f(x) = exp(x)− 11+x2

4. TestFunction4: f(x)x + x−x2cos(x)

8.4 Testing Procedure

We have applied all numerical methods to each of the previously listed functions and eval-uated their convergence, precision and speed. We have chosen a bracketing interval [x1, x2]for the bisection, secant, Regula Falsi, Fail-Safe Newton-Raphson, Ridders’ and Brent’smethods and a starting point x0 for the Newton-Raphson method.

With every test we did, we monitored the precision of the found solution and the numberof iterations each method took to complete. We marked each successful test with a ‘Yes’and the methods that did not converge with a ‘No’.

8.5 Results

8.5.1 Interval Bisection Method

Theoretically, the bisection method will always converge for a continuous function as longas the accuracy and the size of the search interval are reasonably adjusted. There is aresult table corresponding to each function we tested.

Equation: ex − 3x2 = 0, x ∈ [2, 4]

Requested Accuracy Number of Bisections Convergence

10−3 11 Yes10−5 18 Yes10−7 25 Yes

85

Page 92: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Examples Chapter 8

Equation: x3 = x2 + x + 1, x ∈ [1, 2]

Requested Accuracy Number of Bisections Convergence

10−3 10 Yes10−5 17 Yes10−7 24 Yes

Equation:

ex =1

1 + x2, x ∈ [−1, 2]

Requested Accuracy Number of Bisections Convergence

10−3 12 Yes10−5 19 Yes10−7 25 Yes

Equation: x + e−x2cos(x) = 0, x ∈ [−10, 10]

Requested Accuracy Number of Bisections Convergence

10−3 15 Yes10−5 21 Yes10−7 28 Yes

8.5.2 Secant Method

The secant method performed quite fast and delivered very precise solutions for most equa-tions. For the third equation however, it didn’t converge.

Equation: ex − 3x2 = 0, x ∈ [2, 4]

Requested Accuracy Successive Approximations Convergence

10−3 8 Yes10−5 9 Yes10−7 10 Yes

Equation: x3 = x2 + x + 1, x ∈ [1, 2]

Requested Accuracy Successive Approximations Convergence

10−3 5 Yes10−5 6 Yes10−7 7 Yes

86

Page 93: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Examples Chapter 8

Equation:

ex =1

1 + x2, x ∈ [−1, 2]

Requested Accuracy Successive Approximations Convergence

10−3 1262 No10−5 1262 No10−7 1262 No

Equation: x + e−x2cos(x) = 0, x ∈ [−10, 10]

Requested Accuracy Successive Approximations Convergence

10−3 6 Yes10−5 6 Yes10−7 7 Yes

8.5.3 Method of False Position

The Method of False Position kept delivering solutions within the requested accuracy forall equations. The solution returned for the third equation was not very precise.

Equation: ex − 3x2 = 0, x ∈ [2, 4]

Requested Accuracy Successive Approximations Convergence

10−3 8 Yes10−5 10 Yes10−7 13 Yes

Equation: x3 = x2 + x + 1, x ∈ [1, 2]

Requested Accuracy Successive Approximations Convergence

10−3 5 Yes10−5 7 Yes10−7 9 Yes

87

Page 94: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Examples Chapter 8

Equation:

ex =1

1 + x2, x ∈ [−1, 2]

Requested Accuracy Successive Approximations Convergence

10−3 28 ≈ 10−2

10−5 42 ≈ 10−4

10−7 56 ≈ 10−6

Equation: x + e−x2cos(x) = 0, x ∈ [−10, 10]

Requested Accuracy Successive Approximations Convergence

10−3 6 Yes10−5 6 Yes10−7 7 Yes

8.5.4 Newton-Raphson Method

The Newton-Raphson method converged very quickly towards a highly accurate solutionin most cases. For large values of B in the last equation, it took a very long time to converge.

Equation: ex − 3x2 = 0, x0 = 4

Requested Accuracy Derivative Approximations Convergence

10−3 4 Yes10−5 4 Yes10−7 5 Yes

Equation: x3 = x2 + x + 1, x0 = 2

Requested Accuracy Derivative Approximations Convergence

10−3 3 Yes10−5 4 Yes10−7 4 Yes

88

Page 95: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Examples Chapter 8

Equation:

ex =1

1 + x2, x0 = 2

Requested Accuracy Derivative Approximations Convergence

10−3 6 Yes10−5 7 Yes10−7 7 Yes

Equation: x + e−x2cos(x) = 0, x0 = 10

Requested Accuracy Derivative Approximations Convergence

10−3 7 Yes10−5 11 Yes10−7 14 Yes

8.5.5 Fail-Safe Newton-Raphson method

The Fail-Safe Newton-Raphson method generally converged slower than the plain Newton-Raphson method, but could yielded a solution in anomalous situations when the Newtonmethod failed. Whenever the convergence of the Newton-Raphson method is too slow orout of bounds, we take a bisection step in order to correct the error.

Equation: ex − 3x2 = 0, x ∈ [2, 4]

Requested Accuracy Derivative Approximations Convergence

10−3 6 Yes10−5 7 Yes10−7 7 Yes

Equation: x3 = x2 + x + 1, x ∈ [1, 2]

Requested Accuracy Derivative Approximations Convergence

10−3 4 Yes10−5 5 Yes10−7 5 Yes

89

Page 96: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Examples Chapter 8

Equation:

ex =1

1 + x2, x ∈ [−1, 2]

Requested Accuracy Derivative Approximations Convergence

10−3 4 Yes10−5 5 Yes10−7 6 Yes

Equation: x + e−x2cos(x) = 0, x ∈ [−10, 10]

Requested Accuracy Derivative Approximations Convergence

10−3 6 Yes10−5 10 Yes10−7 13 Yes

8.5.6 Ridders’ Method

Ridders’ method converged in a fast manner and yielded very precise solutions. Note thatan iteration step performed by this method takes a lot more time to compute than a regularNewton-Raphson or secant approximation.

Equation: ex − 3x2 = 0, x ∈ [2, 4]

Requested Accuracy Iteration Sequences Convergence

10−3 4 Yes10−5 4 Yes10−7 5 Yes

Equation: x3 = x2 + x + 1, x ∈ [1, 2]

Requested Accuracy Iteration Sequences Convergence

10−3 3 Yes10−5 4 Yes10−7 5 Yes

90

Page 97: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Examples Chapter 8

Equation:

ex =1

1 + x2, x ∈ [−1, 2]

Requested Accuracy Iteration Sequences Convergence

10−3 4 Yes10−5 4 Yes10−7 4 Yes

Equation: x + e−x2cos(x) = 0, x ∈ [−10, 10]

Requested Accuracy Iteration Sequences Convergence

10−3 4 Yes10−5 5 Yes10−7 5 Yes

8.5.7 Brent’s Method

Brent’s method delivered solutions just within the requested precision in a very flexiblemanner. You may notice that higher accuracy doesn’t necessarily mean increased numberof steps, whereas if the accuracy gets extremely high, the method may not be able to yieldwithin the precision anymore. Please note that an iteration step performed by Brent’smethod is very complex and cannot be equally compared to a secant or Newton approxi-mation.

Equation: ex − 3x2 = 0, x ∈ [2, 4]

Requested Accuracy Iteration Sequences Convergence

10−3 8 Yes10−5 8 Yes10−7 9 Yes

Equation: x3 = x2 + x + 1, x ∈ [1, 2]

Requested Accuracy Iteration Sequences Convergence

10−3 5 Yes10−5 11 Yes10−7 7 Yes

91

Page 98: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Examples Chapter 8

Equation:

ex =1

1 + x2, x ∈ [−1, 2]

Requested Accuracy Iteration Sequences Convergence

10−3 10 Yes10−5 11 Yes10−7 12 Yes

Equation: x + e−x2cos(x) = 0, x ∈ [−10, 10]

Requested Accuracy Iteration Sequences Convergence

10−3 7 Yes10−5 7 Yes10−7 8 Yes

8.6 Conclusion

As expected, the bisection method and the more advanced methods like Brent’s and Rid-ders’ could handle all the equations, even for higher degrees of accuracy. For certain typesof equations, the secant method and the Fail-Safe Newton-Raphson can prove very fastand accurate. The Newton-Raphson with analytical derivative is an efficient alternativewhen such a derivative can easily be calculated.

8.7 Custom Examples

8.7.1 Database Example with JDBC Mediator

The Database Example is located inside the Client/Interpolation/DatabaseExample direc-tory. The following steps are required before running the Database example.

1. Installing our Tables (MySQL Only)In order to create the database structure from which you are able to load the outputresults, you will need to run the ‘create.sql’ scripts in the ‘Data’ subdirectory. Openthe MySQL prompt from the ‘Data’ subdirectory and:

� Select (or create and then select) a database you can spare for a table namedPOINTS. For example, if you have decided using the ‘test’ database, you wouldoptinally type the SQL command to create it (unless it already exists):

CREATE DATABASE test;

and then, you would type the following to select it:

92

Page 99: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Examples Chapter 8

USE DATABASE

� Run the ‘create.sql’ SQL script located in the ‘Data’ subdirectory of the currentdirectory by typing at the same MySQL prompt the following:

source create.sql

If this fails, make sure you have started the MySQL prompt from the ‘Data’subdirectory (this is where the database files for this example are stored).

2. Configuring the Database ConnectionEdit the Java source code file by filling out JDBC information about your database,such as:

(a) Driver Name (e.g. com.jdbc.mysql.Driver)

(b) JDBC Url (e.g. jdbc:mysql://localhost/test)

(c) Username and Password

If you are unsure whether you have a JDBC Driver for your Database, skip this stepand try running the example with the predefined values. If that fails, you will needto probably download the latest driver.

3. Running the example

Run the ‘compile’ script (compile.sh for Linux, compile.bat for Windows) to compilethe Java source code, and then the ‘run’ script to see the results.

Uninstalling the Source Data

To delete all the tables used in this example, open the MySQL prompt from the ‘Data’subdirectory, select the database where you created the tables, and run the following:

source delete.sql

93

Page 100: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Chapter 9

Guide to WebCab Components

9.1 The Company

WebCab is a privately owned British company that has built business solutions since itsinception in 1999. We continue to refine and develop our Mathematical and FinancialFramework which we have implemented on the J2SE, J2EE and .NET platforms.

9.2 Presentation of Products

Our aim is to provide good quality, useful information to help you decide which componentbest suits your development needs. WebCab is committed to honesty and realism whenpresenting our products. In order to achieve this a detailed, clear and factual style forpresentation is adopted within our documentation and marketing material.

9.3 Supported Clients, IDEs, Containers and DBMSs

By supporting all major development, server and client side technologies we preserve thedevelopers flexibility in making architecture decisions. In particular, each product containsdetailed examples and advice concerning the integration and use of our modules withinexisting infrastructure. Our documentation provides the information that the developerneeds to get their applications up and running as quickly and as easily as possible.

We detail exactly how the developer can use our .NET Services and API with the fol-lowing technologies:

� Client containers - Internet Explorer, Netscape, Mozilla

� IDEs - Microsoft’s Visual Studio .NET, Borland’s C#Builder, .NET Framework SDK,.NET Framework Web Matrix

� Client Side Technologies - Application Clients, ASP.NET, C#, VB.NET, WindowsForms

94

Page 101: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Guide to WebCab Components Chapter 9

� XML Web services

� DBMS - Oracle, IBM DB2, SQL Server, Sybase, MySQL

� Platforms - Windows 2003/XP/2000/NT

For these technologies we include all installation scripts and template examples which willhelp the developer quickly and easily assemble their multi-tier enterprise application.

9.4 Transparent Functionality

All technical and business intelligence incorporated within our products is described withinthe associated documentation. This allows the developer to see the nature of the method-ology implemented within our proprietary algorithms.

9.5 Company Culture and Activity

WebCab Components is focused solely on the production of high quality software moduleswithin our Financial and Mathematical Framework. The WebCab team contains a widerange of expertise and experience from the academic, investment banking and softwaredevelopment worlds.

Within the company there exists significant internal competitive pressures with constantpeer review and evaluation, resulting in higher quality products, which adhere to highprofessional standards and offer extended functionality.

9.6 Product Life cycle

We continuously add value to our products by evolving them according to new .NETFramework specifications, customer feedback and market demands. We give particularemphasis to incorporating our clients suggested modifications and additions into our prod-uct development cycle.

9.7 Support, Warranty and Upgrades

WebCab warrants that each component will perform substantially in accordance with theaccompanying written material. We provide with all our products without charge sixty(60) days product support services including fixing bugs, compatibility issues and othertechnical support issues.

All maintenance updates (including service packs) will be distributed free of additionallicense cost.

95

Page 102: WebCab Functions for .NET v2 - ComponentSourceThis documentation accompanies the WebCab Functions .NET Service. This .NET Service offers functionality related to the representation

Guide to WebCab Components Chapter 9

Dr Ben Fairfax

Founder and CEO

WebCab Components - From Developer, To Developer

.NET and all .NET-based marks are trademarks or registered trademarks of Microsoft Corporation,

Inc. in the U.S. and other countries.

96