Click here to Skip to main content
Licence 
First Posted 11 Jan 2005
Views 47,296
Bookmarked 28 times

Library for non linear algebraic system of equations in C#.NET

By | 11 Jan 2005 | Article
Library for numerical methods such as newton raphson and quasi newton methods.

Introduction

The article presents a library used for non linear system of algebraic equations. Such a library is of immense use for process and civil and computational engineers, for example, in problems related to fluid system simulation. This library uses Newton Raphson and Quasi Newton methods to solve non linear system of equations. It uses an equation parser class and linear algebra class which are presented before. Both the Newton Raphson and Quasi Newton methods are quite stable and can be applied to large systems.

Background

This library is developed while developing an application for a pipe network simulation program, but it finds use in many fields. The trial values for the variables are set randomly, which is not a good idea, but these trail values can be updated when needed. The following figure shows the convergence of a variable in Quasi Newton scheme.

Sample Image - maximum width is 600 pixels

Using the code

Consider a system of non linear equations as mentioned below:

A^2+B^3+logC-445 = 0   
A^3+B^2+C-1149 = 0
A+2B^2+3C = 408

The following snippet of code obtains the value of variables as A=10, B=7 and C=100.

using System;
using VIJAY.MATH; 
namespace Solver
{    
    class solver
    {        
        [STAThread]
        static void Main(string[] args)
        {
            string s1= "x0^2+x1^3+log(x2)-445";
            string s2= "x0^3+x1^2+x2-1149";
            string s3= "x0+(2*x1^2)+(3*x2)-408";        
            string[] S = {s1,s2,s3};
            NonLinear.SetSystem (S);
            double[] results=NonLinear.NewtonRapson();             
        }
    }
}

Note that, the variables are identified as x0,x1,x2…etc by the system. The trail values for these variables are generated randomly. The number of iterations, accuracy required, and editing the trail values can be done as shown below:

Data.iterations=30;
Data.accuracy =0.001;
NonLinear.EditVariable ("x2",70);

Points of Interest

Both Quasi Newton and Newton Raphson schemes are stable. However, Quasi Newton Scheme is recommended when logarithmic functions are present in the system. The current library supports functions such as sin(), cos(), tan(), log(), ln(), exp() and the operators such as ^ (power). The function list can be further expanded. For some systems, the number of iterations and convergence criteria must be explicitly specified.

To Do

An exception handling mechanism must be included in order to deal with inconsistent systems.

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

VijayaSekhar Gullapalli



Sweden Sweden

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralTwo years later.... PinmemberHerbert Sauro17:19 1 Jun '07  
GeneralRe: Two years later.... PinmemberBob McGwier13:27 9 Jun '07  
GeneralSource Code PinmemberJaseNet22:33 26 May '07  
GeneralRe: Source Code PinmemberMember 30670944:28 2 Apr '09  
GeneralVisual Studio (VB2005) Pinmemberspranto4:45 16 May '07  
QuestionSurprising results PinmemberAriadne4:29 19 Oct '06  
GeneralQuestion. PinmemberLesha23:00 12 Oct '06  
GeneralVery Good - How should I reference the lib in my code PinmemberCarvalhoPC16:15 8 Oct '06  
GeneralThank u PinmemberVijayaSekhar Gullapalli0:16 18 Mar '06  
GeneralFurther development PinmemberTom the Coder3:03 15 Mar '06  
GeneralGreat Contribution PinmemberJayTau13:34 15 Jan '06  
GeneralStill no source code PinmemberHerbert Sauro16:44 27 Jun '05  
GeneralSuggestions PinmemberJeffrey Sax3:33 12 Jan '05  
GeneralA little disappointing PinmemberNik Vogiatzis18:46 11 Jan '05  

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.

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120517.1 | Last Updated 11 Jan 2005
Article Copyright 2005 by VijayaSekhar Gullapalli
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid