Click here to Skip to main content
Click here to Skip to main content

Smart Numerical Analysis Textbox (SNAT)

, 1 Aug 2007
Rate this:
Please Sign up or sign in to vote.
Helpfull control for solving a shared equation in textboxes.

Contents

  • Introduction
  • Using the control
    • Solving a shared equation
    • Solving single equation
    • Calculator
    • Numeric TextBox
  • How control works
  • Control properties
  • Control events
  • Sample program
  • Adding control to the project

Introduction

Suppose that you have this Equation:

Sin(z^2)+y/3+u*h-p^2-23*h^4+Atn(Cos(j*v))-23=0

And your program has 7 textboxes for parameters z, u, h, p, j, v and y.Your program should be able to evaluate the value of each parameter according to the value of other textboxes and current formula.You may try to find a relationship for each parameter according to other parameters.For example for y (which is easier than other) we have:

y = 3* (23*h^4-Sin(z^2)-u*h-p^2-Atn(Cos(j*v))+23)

And then you define corresponding properties for the values of textboxes.

Using the control

1. Solving a Shared Equation

Let's say that using SNAT you even do not need to evaluate such formulae and no need to make lots of properties and methods. NO CODE NEEDED you only:

  1. name the parameter property of all SNATs
  2. Set the value of Formula

Now just focus on the textbox you want and press F5 to evaluate the value. This also can be done using Solve method of SNAT.There are some points that user should remember: (Read Carefully)

1.1. Some equations may have more than one root. In the case you have to set the Shared_MIN & Shared_MAX properties of corresponding SNAT.

The control will automatically find the root (if available). For example you want a root between 10 and 500.SNAT starts with initial value of 255 for MULLER method. If it couldn't find the root the domain will be divided in two sub-domains and both of them will be examined for the root. These divisions are called Steps which is a property in SNAT and is equal to 4 by default. A SNAT with 4 steps will work to the final amount of 16 divisions.

For example the absolute pressure can not be negative and if you have p^2 in the equation you may get a negative value for the root. Just change the Shared_MIN and Shared_MAX properties to the values that you accept logically.

2. All parameters are case sensitive except X. Remember that x (or X) is always an unknown. So you can not use it as a parameter. For example if you have 4 SNATs with parameters y1, y2, z and t. you type "X*y1+z^2-t*y2" in another SNAT and press Enter. This will calculate the value of x and leave it in the current SNAT.

3. These functions are valid in SNAT: Sin, Cos, Tan, Atn, Abs, Int, Fix, Log, Exp, Sqr, Sgn (All VBA math module functions) For more functions such as Ln, Ei, Integration, … wait for next version of SNAT.

4. Remove all the possible infinite values of the equation For example if you have ((y^3+z-1)/(j*(t-1))) -2.5 this will return infinity when t=1 or j=0 just write the formula in a linear form. Like this: (y^3+z-1) -2.5*(j*(t-1))

5. SNAT is the fastest .Net control for solving such equations that's why it applies Visual FORTRAN DLL for this purpose. If it freezes in some cases that's the result of your Steps property that tries to find a root between shared_min and shared_max. This will raise the Step_Iteration event. If the function is not sinuous shaped with high frequency you do not need high Steps to get the goal. Any way ill separate its thread in the next version for better performance.

2. Solving Single Equation

The parameter x (or X) is reserved for this purpose. You just type the equation in the SNAT, press enter and see the result.You can use other SNAT parameters in your equation! all of them know each other and their values.

3. Calculator

Pressing enter results in direct evaluation of argument in the SNAT. You can use other SNAT parameters in this part too!

4. Numeric TextBox

If you set the calculator property of SNAT to false it will be an ordinary Numeric textbox which only accepts digits. It has also a dynamic decimal point. I mean if you go to the end of the digit and place a decimal point and go back to the starting point and place another decimal point, the first point will be removed. Also you can see all validated values of textbox using mouse wheel.

How Control Works

The greatest problem was that i coudnt send the address of a function in .Net to visual fortran.but it was possible using VB6.so Control has 3 main dlls:

  • .Net DLL
  • VB6 DLL
  • Visual Fortran DLL

the .Net dll gets the text box values and replaces the parameters in the function by their value and produces the raw equation.it sends this string to vb6 dll.this vb6 dll sets the value of a public string which is being evaluated for different values of x using vbscript.this evaluation occures in a function and vb6 dll sends the handle to this functions to visualfortran dll to evaluate unknown(x). vf dll sends evaluated value to vb6 and vb6 to .net and .net to the current textbox!

Conrol Properties:

Name

Description

Calculate

It can be OnEnter,OnValidate and OnBoth.

Calculator

Being true says that you want to use the calulational abilities of the control. if not it will be only a numerical textbox.

Formula

The shared formula between snats. it is needed in "solving a shared equation"

Initial

The initial value of "solving single equation" for MULLER method.

Parameter

The corresponding parameter of a SNAT for example: y1.t.r.hy.ff

Steps

Number of steps that SNAT progresses to find a root in the prefered boundary of user. just used in "solving a shared equation"

Shared_MIN

Minimum value of unknown in "solving a shared equation"

Shared_MAX

Maximum value of unknown in "solving a shared equation"

Conrol Events:

Name

Description

Solved

It will be raised when equation is solved.

Not_Solved

It will be raised when equation is not solved. it can be the result of no solution or bad form of equations that returns infinity and...etc

Steps_Iteration

In "solving shared equation" shows that one step is passed

Sample Program

Solving a shared equation

its funny to make a sample program in zip file ready to download. thats why SNAT needs no code but i show you where you have to set the properties to get the solution.here is the property window of a SNAT which solves the equation ((y^3+z-1)) -2.5*(j*(t-1)) = 0

Screenshot - snat2.jpg

and these are SNATs. in the last SNAT (j), F5 is pressed and j is evaluated:

Screenshot - snat1.jpg

Solving sinlgle euqations

type the equation in term of x(or X) and other SNAT parameters:

Screenshot - snatAlso.jpg

and press Enter:

Screenshot - SnatAlso2.jpg

Calculator:

type the argument:(here y*t+z)

Screenshot - calcu1.jpg

and press Enter:

Screenshot - calcu2.jpg

Adding Control to Project

  1. Download the zip file and extract it where your application runs. For example in …bin\debug folder where the application executes.
  2. Add SNAT.dll to your .NET toolbox.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Amir Emamjomeh
Engineer
Iran (Islamic Republic Of) Iran (Islamic Republic Of)
Amir Emamjomeh is a senior petroleum reservoir engineer and also programmer who has been involved in several industrial and research projects proposed by the petroleum industry of Iran since 2006. His programming experiences include C, C++, C# , VB.Net, MATLAB and Visual FORTRAN.

Comments and Discussions

 
GeneralSNAT.dll usage Pinmemberastatinn12-Mar-10 8:29 
RantRe: SNAT.dll usage Pinmemberaaroncampf10-Dec-10 12:46 
GeneralRe: SNAT.dll usage PinmemberAmir Emamjomeh Kuhbanani11-Dec-10 0:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 1 Aug 2007
Article Copyright 2007 by Amir Emamjomeh
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid