Results 1 to 3 of 3

Thread: how do you do Integration in vb?

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2000
    Location
    derby,UK
    Posts
    38

    Post

    how do you do Integration in vb?

    i dont know where to start can you help?

  2. #2
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089

    Post

    I think You've probably bitten off more than most people would like to chew. The way I See it there are 2 ways to go about this without haveing to teach your machine all the rules of integration (I have here a book about 2 inches thick which contains about half the rules of integration)

    First you need to get hold of a Maths Parser which is something that translates maths equations into computer code at runtime (So you can just type in your equation to a text box and vb will work it out for you) I think these cost about $100 US for a good one but the web is a big place and there might be someone giving them away. (If you find one put a message up cos quite a few people will want one myself included) or you could try to program your own.
    There are some general tips for this at the bottom.


    I'm assuming now you have a function F(x) in your Code which you want to integrate and you can easily get the value F(x) for any x in its domain (I always get range and domain confused so i might mean for any value in its range)


    The first way is by numerical approximation. Try this code.

    Code:
    Private Function F(x As Double) As Double
    
    'Put the code for your functio in here
    'eg F = Cos(X)
    
    End Function
    
    
    
    Public Function IntegrateFofX(LowerBound As Double, _
                                  UpperBound As Double, _
                                  StepWidth As Double) As Double
    
    
    Dim x As Double
    Dim Result As Double
    
    Result = 0
    
    For x = LowerBound To UpperBound Step StepWidth
    
        Result = Result + (F(x) * StepWidth)
    
    Next x
    
    IntegrateFofX = Result
    
    End Function

    The second method is hard, very hard indeed. but it will give you indefinate integrals

    Your going to have to find some guy who's very good at maths and get him to explain the basics of Taylor Approximations and a good algorithm to find solutions to non linear simultanious equations You should probably buy him a few pints and try to persuade him to help you write your code.

    now you've learnt how to do hard sums you're ready to start.
    I'm going to assume your fairly good at these because otherwise this post is going to end up like a book and I dont know how to solve nonlinear systems of equations anyway.

    write down all the simple functions you can think of Cos(AX+B)exp(AX+B) make the polynomials inside the functions as big as your maths can handle (3 or four should do for most integrals) and make them the same degree in all the functions you will also need a polynomial in the form AX^2+BX+1 as one of your functions (make it of degree one more than the polynomials

    next count up all the functions you've writeen down and multiply by the degree of that last polynomial I mentioned ie one more than the degrees of the polynomial and call it n

    work out the taylor approximations of all the functions to degree n and write them down


    I dont know but I think theres a method of reducing that lot to something called canonical form, ask your maths freind, this will help the program run faster but the maths is starting to get a little more than I can handle so I don't know, Don't work if it isn't possible .

    Basicly what youre trying to do is work out the taylor approximation of your function to degree n by finding F(0) F'(0), F''(0) etc by numerical methods and integrate it call this integral G(x) As the taylor approximation is a polynomial and solve the ystem of nonlinear equations

    G(x)=ACos(BX+c)+CSin(DX+E) etc

    using these taylor approximations. you worked out above

    This should give you the indefinate Integral of most functions and will give an approximation to the integral of functions which can't be integrated.


    I Hope this helps but the maths is very hard and I don't claim that I would be able to code it myself and I don't even know if it would work.


    Here are some tips for that maths Parser

    1. Don't try to write something that goes from an equation in a text box to code in one go start off by restricting the user as much as you can and gradually build up the code to give the user more freedom

    2. VB doesnt have very many maths functions and you may have to write your own or buy some from a third party developer. Use Taylor approximations to these functions to do it (This is much easier than above so don't be scared of them just cos I used them in an evil way)

    3 one good method might be to write it fo it functions like a calculator eg start with x let the user add things multiply by things and get the results of functions on the total then remember these steps to do the calculations eg cos(3x+4) would be

    x
    *3
    +4
    Cos(Answer)

    I hope all this helps

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2000
    Location
    derby,UK
    Posts
    38

    Post

    thank you sam, thats helped me to understand, how simple mental tasks, are very hard for a computer to do,,

    Paul Barnes

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width