help in VB coding: solving math equations, or find OCX that's equation solver
Author Message
help in VB coding: solving math equations, or find OCX that's equation solver

it turns out that i'm an aweful programmer. this is what i need to do
involving math:

Sample:
5x + y =10
x + 3y  = 7
Find x and y.

you have 2 unknowns and 2 equations. solving for x and y is possible. but
i'm too stupid and  can't code it in vb so that it will solve. is there an
OCX somewhere that handles something like this?
this is just the beginning.  there could be more unknowns and more
complicated expressions.  i went to bookstores and tried to look for books
that would help to do this but unsuccessfull. all of them talk about
web-building and data stuff.

or somebody give me a sample code and maybe i can learn from there and build
myself up.

dumb idea:
i was thinking something like FOR and Loop. example, Loop i until LHS equals
RHS. this would be purely iterative approach but i think it won't work when
you have tons of equations. also, it'll probably give more than solution
since you are looking at only equation at a time.  i am so lost...

thanks.

Wed, 12 Oct 2005 22:17:51 GMT
help in VB coding: solving math equations, or find OCX that's equation solver
Where does the 5x + y =10 and x + 3y  = 7 come from?
Is it a user's input in a text-box?

Johan.

PS:
x=1,642857143
y=1,785714286

Quote:
> it turns out that i'm an aweful programmer. this is what i need to do
> involving math:

> Sample:
> 5x + y =10
> x + 3y  = 7
> Find x and y.

> you have 2 unknowns and 2 equations. solving for x and y is possible. but
> i'm too stupid and  can't code it in vb so that it will solve. is there an
> OCX somewhere that handles something like this?
> this is just the beginning.  there could be more unknowns and more
> complicated expressions.  i went to bookstores and tried to look for books
> that would help to do this but unsuccessfull. all of them talk about
> web-building and data stuff.

> or somebody give me a sample code and maybe i can learn from there and
build
> myself up.

> dumb idea:
> i was thinking something like FOR and Loop. example, Loop i until LHS
equals
> RHS. this would be purely iterative approach but i think it won't work
when
> you have tons of equations. also, it'll probably give more than solution
> since you are looking at only equation at a time.  i am so lost...

> thanks.

Wed, 12 Oct 2005 23:03:21 GMT
help in VB coding: solving math equations, or find OCX that's equation solver

Quote:

> it turns out that i'm an aweful programmer. this is what i need to do
> involving math:

> Sample:
> 5x + y =10
> x + 3y  = 7
> Find x and y.

> you have 2 unknowns and 2 equations. solving for x and y is possible. but
> i'm too stupid and  can't code it in vb so that it will solve. is there an
> OCX somewhere that handles something like this?
> this is just the beginning.  there could be more unknowns and more
> complicated expressions.  i went to bookstores and tried to look for books
> that would help to do this but unsuccessfull. all of them talk about
> web-building and data stuff.

> or somebody give me a sample code and maybe i can learn from there and build
> myself up.

> dumb idea:
> i was thinking something like FOR and Loop. example, Loop i until LHS equals
> RHS. this would be purely iterative approach but i think it won't work when
> you have tons of equations. also, it'll probably give more than solution
> since you are looking at only equation at a time.  i am so lost...

Well, that's certainly one possible way--as you surmise, not very
efficient and can be fraught with difficulties--things like starting
points for estimates, etc., are not necessarily easy to determine, for
example.  That technique is known by the name of "minimization".  What
you're really doing is trying to minimize a simultaneous set of
conditions, F(x,y)=0.

What you're actually looking for is known as basic linear algebra.  In
theory, one can use matrix algebra and solve a set of equations A x = y
by inverting the coefficient matrix A, and multiplying by it to find the
result.  However, this is not a very good way in general for actually
coding the problem owing to numerical issues.  As an example of one
better way, try

http://mathworld.wolfram.com/GaussianElimination.html

I'm sure somebody has probably implemented BLAS and or LAPACK in VB, but
I use it in fortran as a DLL to VB.  A link to BLAS is
http://www.netlib.org/blas/ while LAPACK is at
http://www.netlib.org/lapack/

Wed, 12 Oct 2005 23:50:00 GMT
help in VB coding: solving math equations, or find OCX that's equation solver
You are looking for a matrix solver. The simplest is perhaps the Gauss or
Gauss-Jordan methods, with partial or full pivoting. There are many of these
routines available, mostly in fortran. If I were you, I would get one of
these from the web or from books (Numerical Recipes for example) and
translate it to VB.

Quote:
> it turns out that i'm an aweful programmer. this is what i need to do
> involving math:

> Sample:
> 5x + y =10
> x + 3y  = 7
> Find x and y.

> you have 2 unknowns and 2 equations. solving for x and y is possible. but
> i'm too stupid and  can't code it in vb so that it will solve. is there an
> OCX somewhere that handles something like this?
> this is just the beginning.  there could be more unknowns and more
> complicated expressions.  i went to bookstores and tried to look for books
> that would help to do this but unsuccessfull. all of them talk about
> web-building and data stuff.

> or somebody give me a sample code and maybe i can learn from there and
build
> myself up.

> dumb idea:
> i was thinking something like FOR and Loop. example, Loop i until LHS
equals
> RHS. this would be purely iterative approach but i think it won't work
when
> you have tons of equations. also, it'll probably give more than solution
> since you are looking at only equation at a time.  i am so lost...

> thanks.

Wed, 12 Oct 2005 23:30:52 GMT
help in VB coding: solving math equations, or find OCX that's equation solver

Quote:
>it turns out that i'm an aweful programmer. this is what i need to do
>involving math:

>Sample:
>5x + y =10
>x + 3y  = 7
>Find x and y.

>you have 2 unknowns and 2 equations. solving for x and y is possible. but
>i'm too stupid and  can't code it in vb so that it will solve. is there an
>OCX somewhere that handles something like this?
>this is just the beginning.  there could be more unknowns and more
>complicated expressions.  i went to bookstores and tried to look for books
>that would help to do this but unsuccessfull. all of them talk about
>web-building and data stuff.

>or somebody give me a sample code and maybe i can learn from there and build
>myself up.

>dumb idea:
>i was thinking something like FOR and Loop. example, Loop i until LHS equals
>RHS. this would be purely iterative approach but i think it won't work when
>you have tons of equations. also, it'll probably give more than solution
>since you are looking at only equation at a time.  i am so lost...

>thanks.

Actually,  some form of "LU Decomposition"  is probably best ( and easiest )
for your needs.   You can essentially do Gaussian Elimination using
decomposition techniques.

Do some web searches.  Here is one site I quickly pulled up.

http://csep10.phys.utk.edu/guidry/phys594/lectures/linear_algebra/lan...
node3.html

At very least,  I would imagine there are probably freely available routines
out there you can find.  I do this type of thing a lot using fortran which
could easily be translated.  However,  I'm usually solving a specific type of
simultaneous equations ( yours are of a general nature ).

I "think" I have a QuickBasic general solution code around somewhere,  but,  I
haven't looked for it in several years.

Dan  :-)

Thu, 13 Oct 2005 00:47:09 GMT
help in VB coding: solving math equations, or find OCX that's equation solver

Quote:

>it turns out that i'm an aweful programmer. this is what i need to do
>involving math:

>Sample:
>5x + y =10
>x + 3y  = 7
>Find x and y.

If your problem is always like the one you posted think of it as:-

a1*x + b1*y = c1
a2*x + b2*y = c2

In this case a1=5, b1=1, c1=10, a2=1, b2=3, c2=7

x=(b2*c1-a2*c2)/(a1*b2-a2*b1)
y=(a1*c2-a2*c1)/(a1*b2-a2*b1)

In VB:-

a1 = 5: b1 = 1: c1 = 10: a2 = 1: b2 = 3: c2 = 7
x = (b2 * c1 - a2 * c2) / (a1 * b2 - a2 * b1)
y = (a1 * c2 - a2 * c1) / (a1 * b2 - a2 * b1)
Debug.Print x, y

Had to go to my 40 year old maths lecture notes for that. Does anyone
ever throw them out :-)

HTH.

--
Martin Trump

Thu, 13 Oct 2005 03:27:27 GMT
help in VB coding: solving math equations, or find OCX that's equation solver
well, math hasn't changed in 100 years or so:)

Quote:

> >it turns out that i'm an aweful programmer. this is what i need to do
> >involving math:

> >Sample:
> >5x + y =10
> >x + 3y  = 7
> >Find x and y.

> If your problem is always like the one you posted think of it as:-

> a1*x + b1*y = c1
> a2*x + b2*y = c2

> In this case a1=5, b1=1, c1=10, a2=1, b2=3, c2=7

> x=(b2*c1-a2*c2)/(a1*b2-a2*b1)
> y=(a1*c2-a2*c1)/(a1*b2-a2*b1)

> In VB:-

> a1 = 5: b1 = 1: c1 = 10: a2 = 1: b2 = 3: c2 = 7
> x = (b2 * c1 - a2 * c2) / (a1 * b2 - a2 * b1)
> y = (a1 * c2 - a2 * c1) / (a1 * b2 - a2 * b1)
> Debug.Print x, y

> Had to go to my 40 year old maths lecture notes for that. Does anyone
> ever throw them out :-)

> HTH.

> --
> Martin Trump

Thu, 13 Oct 2005 08:20:11 GMT
help in VB coding: solving math equations, or find OCX that's equation solver
listen, the example was just for a simple general case.
i have no trouble with the math. it's the programming part that i'm
learning.

Quote:
> Where does the 5x + y =10 and x + 3y  = 7 come from?
> Is it a user's input in a text-box?

> Johan.

> PS:
> x=1,642857143
> y=1,785714286

> > it turns out that i'm an aweful programmer. this is what i need to do
> > involving math:

> > Sample:
> > 5x + y =10
> > x + 3y  = 7
> > Find x and y.

> > you have 2 unknowns and 2 equations. solving for x and y is possible.
but
> > i'm too stupid and  can't code it in vb so that it will solve. is there
an
> > OCX somewhere that handles something like this?
> > this is just the beginning.  there could be more unknowns and more
> > complicated expressions.  i went to bookstores and tried to look for
books
> > that would help to do this but unsuccessfull. all of them talk about
> > web-building and data stuff.

> > or somebody give me a sample code and maybe i can learn from there and
> build
> > myself up.

> > dumb idea:
> > i was thinking something like FOR and Loop. example, Loop i until LHS
> equals
> > RHS. this would be purely iterative approach but i think it won't work
> when
> > you have tons of equations. also, it'll probably give more than solution
> > since you are looking at only equation at a time.  i am so lost...

> > thanks.

Thu, 13 Oct 2005 08:23:48 GMT
help in VB coding: solving math equations, or find OCX that's equation solver
thanks.
this was useful.

Quote:
> You are looking for a matrix solver. The simplest is perhaps the Gauss or
> Gauss-Jordan methods, with partial or full pivoting. There are many of
these
> routines available, mostly in fortran. If I were you, I would get one of
> these from the web or from books (Numerical Recipes for example) and
> translate it to VB.

> > it turns out that i'm an aweful programmer. this is what i need to do
> > involving math:

> > Sample:
> > 5x + y =10
> > x + 3y  = 7
> > Find x and y.

> > you have 2 unknowns and 2 equations. solving for x and y is possible.
but
> > i'm too stupid and  can't code it in vb so that it will solve. is there
an
> > OCX somewhere that handles something like this?
> > this is just the beginning.  there could be more unknowns and more
> > complicated expressions.  i went to bookstores and tried to look for
books
> > that would help to do this but unsuccessfull. all of them talk about
> > web-building and data stuff.

> > or somebody give me a sample code and maybe i can learn from there and
> build
> > myself up.

> > dumb idea:
> > i was thinking something like FOR and Loop. example, Loop i until LHS
> equals
> > RHS. this would be purely iterative approach but i think it won't work
> when
> > you have tons of equations. also, it'll probably give more than solution
> > since you are looking at only equation at a time.  i am so lost...

> > thanks.

Thu, 13 Oct 2005 08:24:09 GMT
help in VB coding: solving math equations, or find OCX that's equation solver
hmmm.
i'm trying to avoid matrix methods. actually, i don't even think it can work
for my particular application.
i know it works for my simple example case, but this is hardly the
representative case for my problem. (for a number of reasons, i can't
exactly lay out the problem for you guys to see.)
i think i'll consult the fortran numerical books.

thanks.

Quote:

> > it turns out that i'm an aweful programmer. this is what i need to do
> > involving math:

> > Sample:
> > 5x + y =10
> > x + 3y  = 7
> > Find x and y.

> > you have 2 unknowns and 2 equations. solving for x and y is possible.
but
> > i'm too stupid and  can't code it in vb so that it will solve. is there
an
> > OCX somewhere that handles something like this?
> > this is just the beginning.  there could be more unknowns and more
> > complicated expressions.  i went to bookstores and tried to look for
books
> > that would help to do this but unsuccessfull. all of them talk about
> > web-building and data stuff.

> > or somebody give me a sample code and maybe i can learn from there and
build
> > myself up.

> > dumb idea:
> > i was thinking something like FOR and Loop. example, Loop i until LHS
equals
> > RHS. this would be purely iterative approach but i think it won't work
when
> > you have tons of equations. also, it'll probably give more than solution
> > since you are looking at only equation at a time.  i am so lost...

> Well, that's certainly one possible way--as you surmise, not very
> efficient and can be fraught with difficulties--things like starting
> points for estimates, etc., are not necessarily easy to determine, for
> example.  That technique is known by the name of "minimization".  What
> you're really doing is trying to minimize a simultaneous set of
> conditions, F(x,y)=0.

> What you're actually looking for is known as basic linear algebra.  In
> theory, one can use matrix algebra and solve a set of equations A x = y
> by inverting the coefficient matrix A, and multiplying by it to find the
> result.  However, this is not a very good way in general for actually
> coding the problem owing to numerical issues.  As an example of one
> better way, try

> http://mathworld.wolfram.com/GaussianElimination.html

> I'm sure somebody has probably implemented BLAS and or LAPACK in VB, but
> I use it in Fortran as a DLL to VB.  A link to BLAS is
> http://www.netlib.org/blas/ while LAPACK is at
> http://www.netlib.org/lapack/

Thu, 13 Oct 2005 08:29:57 GMT
help in VB coding: solving math equations, or find OCX that's equation solver
folks, the problem is not straight forward like 50 equations and 50
unknowns. in this case, yes, just use the matrix methods and solve it.

unfortunately, for some of my equations you have to iterate to a solution -
that's the only way. and this is just the beginning of the problem. the math
part i can do. i know exactly what to do in my head. the problem is that i
can't get the computer to do what i want. the last time i did actual
programming was in high school. just can't get the darn thing to do what i
want.

i'll take your advice and look up fortran. fortran was my initial choice
anyway.

remember, the problem has already been solved by hand. solution is long and
tideous. just trying to make my life a little easier by programming the
solution.

thanks for yall help.

Quote:
> it turns out that i'm an aweful programmer. this is what i need to do
> involving math:

> Sample:
> 5x + y =10
> x + 3y  = 7
> Find x and y.

> you have 2 unknowns and 2 equations. solving for x and y is possible. but
> i'm too stupid and  can't code it in vb so that it will solve. is there an
> OCX somewhere that handles something like this?
> this is just the beginning.  there could be more unknowns and more
> complicated expressions.  i went to bookstores and tried to look for books
> that would help to do this but unsuccessfull. all of them talk about
> web-building and data stuff.

> or somebody give me a sample code and maybe i can learn from there and
build
> myself up.

> dumb idea:
> i was thinking something like FOR and Loop. example, Loop i until LHS
equals
> RHS. this would be purely iterative approach but i think it won't work
when
> you have tons of equations. also, it'll probably give more than solution
> since you are looking at only equation at a time.  i am so lost...

> thanks.

Thu, 13 Oct 2005 08:38:25 GMT
help in VB coding: solving math equations, or find OCX that's equation solver
Why--it's the most powerful technique for linear equations there is.

It certainly <can> (and will) work <if> your problem is (as you showed)
a set of linear equations (assuming there is a solution, of course).

If, on the other hand, it is a different type of problem, it would
certainly help to specify that if you want advice... :)

Quote:

> hmmm.
> i'm trying to avoid matrix methods. actually, i don't even think it can work
> for my particular application.
> i know it works for my simple example case, but this is hardly the
> representative case for my problem. (for a number of reasons, i can't
> exactly lay out the problem for you guys to see.)
>  i think i'll consult the fortran numerical books.

> thanks.

> > > it turns out that i'm an aweful programmer. this is what i need to do
> > > involving math:

> > > Sample:
> > > 5x + y =10
> > > x + 3y  = 7
> > > Find x and y.

> > > you have 2 unknowns and 2 equations. solving for x and y is possible.
> but
> > > i'm too stupid and  can't code it in vb so that it will solve. is there
> an
> > > OCX somewhere that handles something like this?
> > > this is just the beginning.  there could be more unknowns and more
> > > complicated expressions.  i went to bookstores and tried to look for
> books
> > > that would help to do this but unsuccessfull. all of them talk about
> > > web-building and data stuff.

> > > or somebody give me a sample code and maybe i can learn from there and
> build
> > > myself up.

> > > dumb idea:
> > > i was thinking something like FOR and Loop. example, Loop i until LHS
> equals
> > > RHS. this would be purely iterative approach but i think it won't work
> when
> > > you have tons of equations. also, it'll probably give more than solution
> > > since you are looking at only equation at a time.  i am so lost...

> > Well, that's certainly one possible way--as you surmise, not very
> > efficient and can be fraught with difficulties--things like starting
> > points for estimates, etc., are not necessarily easy to determine, for
> > example.  That technique is known by the name of "minimization".  What
> > you're really doing is trying to minimize a simultaneous set of
> > conditions, F(x,y)=0.

> > What you're actually looking for is known as basic linear algebra.  In
> > theory, one can use matrix algebra and solve a set of equations A x = y
> > by inverting the coefficient matrix A, and multiplying by it to find the
> > result.  However, this is not a very good way in general for actually
> > coding the problem owing to numerical issues.  As an example of one
> > better way, try

> > http://mathworld.wolfram.com/GaussianElimination.html

> > I'm sure somebody has probably implemented BLAS and or LAPACK in VB, but
> > I use it in Fortran as a DLL to VB.  A link to BLAS is
> > http://www.netlib.org/blas/ while LAPACK is at
> > http://www.netlib.org/lapack/

Thu, 13 Oct 2005 09:05:49 GMT
help in VB coding: solving math equations, or find OCX that's equation solver
Well, if it wasn't a set of linear equations, you should have said so...

If it <does> require iteration, then the best I can tell my suggestion
about minimization is still valid.  Look on netlib under the problem
taxonomy charts and see where that leads you if you don't/won't tell us
enough to help...

There are some in this group who are pretty d-d good, but I don't think
any of us can divine the solution to the unasked question... :)

Quote:

> folks, the problem is not straight forward like 50 equations and 50
> unknowns. in this case, yes, just use the matrix methods and solve it.

> unfortunately, for some of my equations you have to iterate to a solution -
> that's the only way. and this is just the beginning of the problem. the math
> part i can do. i know exactly what to do in my head. the problem is that i
> can't get the computer to do what i want. the last time i did actual
> programming was in high school. just can't get the darn thing to do what i
> want.

> i'll take your advice and look up fortran. fortran was my initial choice
> anyway.

> remember, the problem has already been solved by hand. solution is long and
> tideous. just trying to make my life a little easier by programming the
> solution.

> thanks for yall help.

> > it turns out that i'm an aweful programmer. this is what i need to do
> > involving math:

> > Sample:
> > 5x + y =10
> > x + 3y  = 7
> > Find x and y.

> > you have 2 unknowns and 2 equations. solving for x and y is possible. but
> > i'm too stupid and  can't code it in vb so that it will solve. is there an
> > OCX somewhere that handles something like this?
> > this is just the beginning.  there could be more unknowns and more
> > complicated expressions.  i went to bookstores and tried to look for books
> > that would help to do this but unsuccessfull. all of them talk about
> > web-building and data stuff.

> > or somebody give me a sample code and maybe i can learn from there and
> build
> > myself up.

> > dumb idea:
> > i was thinking something like FOR and Loop. example, Loop i until LHS
> equals
> > RHS. this would be purely iterative approach but i think it won't work
> when
> > you have tons of equations. also, it'll probably give more than solution
> > since you are looking at only equation at a time.  i am so lost...

> > thanks.

Thu, 13 Oct 2005 09:11:39 GMT
help in VB coding: solving math equations, or find OCX that's equation solver
Jimmy,
With two equations and two unknowns, all that is needed is to equate the
solution using one of the variables. Being a linear equation, there can only
be one answer for the intersection of x and y;

If y1=y2, and x1=x2

y1=m1x1+b1
y2=m2x2+b2

=> m1x1+b1=m1x1+b1 ; next solve for x

_____________________
x=((m1x1+b1)-b1)/m1
_____________________

then solve for y using either of the original equations

_______________________
y1=m1x+b1  -or-   y2=m2x+b2
________________________

HTH
Wayne

Quote:
> it turns out that i'm an aweful programmer. this is what i need to do
> involving math:

> Sample:
> 5x + y =10
> x + 3y  = 7
> Find x and y.

> you have 2 unknowns and 2 equations. solving for x and y is possible. but
> i'm too stupid and  can't code it in vb so that it will solve. is there an
> OCX somewhere that handles something like this?
> this is just the beginning.  there could be more unknowns and more
> complicated expressions.  i went to bookstores and tried to look for books
> that would help to do this but unsuccessfull. all of them talk about
> web-building and data stuff.

> or somebody give me a sample code and maybe i can learn from there and
build
> myself up.

> dumb idea:
> i was thinking something like FOR and Loop. example, Loop i until LHS
equals
> RHS. this would be purely iterative approach but i think it won't work
when
> you have tons of equations. also, it'll probably give more than solution
> since you are looking at only equation at a time.  i am so lost...

> thanks.

Thu, 13 Oct 2005 13:05:06 GMT
help in VB coding: solving math equations, or find OCX that's equation solver
I suggest you search on Gauss-Jordan Elimination.
Common problem.  The code is already out there.

Quote:
> it turns out that i'm an aweful programmer. this is what i need to do
> involving math:

> Sample:
> 5x + y =10
> x + 3y  = 7
> Find x and y.

> you have 2 unknowns and 2 equations. solving for x and y is possible. but
> i'm too stupid and  can't code it in vb so that it will solve. is there an
> OCX somewhere that handles something like this?
> this is just the beginning.  there could be more unknowns and more
> complicated expressions.  i went to bookstores and tried to look for books
> that would help to do this but unsuccessfull. all of them talk about
> web-building and data stuff.

> or somebody give me a sample code and maybe i can learn from there and
build
> myself up.

> dumb idea:
> i was thinking something like FOR and Loop. example, Loop i until LHS
equals
> RHS. this would be purely iterative approach but i think it won't work
when
> you have tons of equations. also, it'll probably give more than solution
> since you are looking at only equation at a time.  i am so lost...

> thanks.

Tue, 18 Oct 2005 08:59:39 GMT

 Page 1 of 2 [ 15 post ]

Relevant Pages