Qbasicnews.com

Full Version: Algebra in QB
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5
I've been thinking...Is there a way to solve algebraic equations in QB?
Take this:
((81 / 5 * 4)^2) / -3x = 98
Is there a way to easily solve that? I know, you could do it in several steps, and that's fine, but if you want to solve really, really, complex equations, you would need a considerably large amount of code!
Is there some kind of Algebra Mode in QB?
no.
problem:

3x=5x-35

Code:
FOR x=-1000 TO 1000
IF 3*x=(5*x)-35 THEN PRINT "x can be: ";x
NEXT
I'm not sure that's what you're looking for (you may wish to enter e series of characters such as "a*x^2+b*x+c" and get something like x1= p+/-sqr(q))

I just finished a series of routines that solve the polynomail equations of the first, second, third and fourth degree. You specify the coefficients of x^4, x^3 etc..., and the prog returns the number of solutions and, of course, their values. The calculations are made with double length real numbers for better precision.

If you go to http://www.progboards.fr.st, (this webforum is in french, so I will guide you through the links), search for "Wall/Mur". That's the place where we post the codes that are too long for the forum. You will find the prog, under the link "Equations 4ème degré". Beware of html funnies, such as triple spaces that become single spaces in html. I don't think there are any in this code, anyway.

The prog can solve 13200 equations per second with QB 4.0, 4200/sec with version 4.5.

I will use it this week-end to trace raytracing torus and the moebius ring, along with the TC-Lib to get Hi-Res views...

Hope I helped...
Once I saw a method that could solve any polynomial equation to 0:

f(x) is the polynomial function

1. Choose 2 values where SGN(f(x1)) = -1 and SGN(f(x2)) = 1
2. Let x3 = (x1 + x2) / 2
3. If SGN(f(x3)) = -1 then x1 = x3 else x2 = x3
4. If SGN(f(x3)) = 0 then print x3 else goto 1

It is called the "bisecting method". I'm not sure how fast it is but it will solve anything to 0. Actually to find all solutions a modified version needs to be used:

1. Find all points where the gradient (ie. derivative) of f(x) = 0 and place them in an array
2. Insert your left and right bound into the start and end of the array
3. Let arrayidx = 0 (first element of array)
4. If SGN(f(array(arrayidx)) = 0 then print array(arrayidx), goto 6
5. If SGN(f(array(arrayidx)) <> SGN(f(array(arrayidx+1)) then use the method above to find a solution
6. If arrayidx > endofarray-1 then end else increment arrayidx, goto 4
well, i think, for universal factoring, you simplify it to a set of single terms, get the leading and trailing coeffients, prime factor it, come up with every numerical combination of one of those factors atop the other, and then use synthetic division or something to factor it out.

but before that you'd need to make a symbolic interpreter

needless to say, this takes a lot of work, and the convenient thing to do is just not to.
Whoa...polynomial?
Heh, I wanted *simple* algebra...not, what, gr. 12/university math!

Thanks all for other help, though.
...polynomial, a product of multiple terms. you learn it in algebra 1. or algebra 2 at the very latest.

pretty much you'd need:
a) equation simplifier, takes out redundacies
b) a way to reduce x to a set of terms
c) a way to intellectually manipulate x to do your bidding.

it's definately been done. in 1996 some guy at a university, according to my psych book, made a program that not only calculated proofs, but did one that had been no has been able to do for over 60 years.

actually, i you can make a mathematic evaluator, which is easier but still difficult, and a derivation routine, which is also difficult, but involves less symbolic interpretation, you could go about making a program that solves for zero ala newton's method. if my ( http://derivatives.netfirms.com ) derivation routine was more accurate, i'd probably make something like this. but i'm lazy and depressed because after i was all proud of myself for making it i found out what these jack bastards could do:

http://mss.math.vanderbilt.edu/~pscrooke/toolkit.html

oh yeah, it factors too Sad
Heh, thanks, but I beg you...don't try to teach me algebra :-?
I'm only 12 :normal:
The method you describe works in very rare and simple cases only.

It's, basically, whats is called dichotomy. The limits are :

1) The function must be continous and derivable on its complete domain of application
2) You must know the derivative and how many null derivative points there are, and if they are double points or not. That means you need also the second derivative...

In other termes, the method is super fast when you have a graphic idea of the function behaviour, so that you can restrain the explored domain to a given interval. It does not work on the complete -infinite,+infinite interval with a function you do not know by advance...

The method does not work at all with fractal functions : I had to use a similar method to generate raytracing views of fractal landscapes... I found a way to get the result, based on probing, but it is horribly long, and dichotomy is not applicable to shortcut the loops. You may check my fractal landscapes page with the matching QBGround.bas source code to make your mind upon this.

Trust me, if you want to solve polynomia equations, the best approach is to code the algorithm after solving the general case a*x^4+b*x^3+c*x^2+d*x+e=0 by hand. The solution was found by Ferrari several centuries ago, and there was no computer then...

Once you got the logics, programming this takes only a couple of hours...
Pages: 1 2 3 4 5