Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Algebra in QB
#21
It has to be simlper than that

cant you just run a code that looks for ^ do something then * and / and () do something then + - and so on?
Reply
#22
But although that might be simple in concept, programming it, taking account of all the arithmetic rules, might not seem so simple. Smile (But if you think otherwise, the world eagerly awaits your proof.) Smile (Get busy.)



Quote:It has to be simlper than that

cant you just run a code that looks for ^ do something then * and / and () do something then + - and so on?
ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Reply
#23
No, I'm not working on a graphic calculator, one of the subject I'm working on is raytracing. The purpose is to get 3D views of volumes that are defined by a polynomial equation such as x^2+y^2+z^2=R^2 for a sphere. The most beautiful shapes have, of course, more complex equations... As for now, I can draw any quadratic shape with my TC-Lib (ellipsoid, hyperboloid, hyperbolic paraboloid, etc...). You get, after a few 3D variable conversions, a second degree polynomial equation, so it's quite easy to do.
I managed to build a 4th degree solver that will allow drawing quadric shapes such as the torus, or the Moebius ring.

My problem today is that I crashed my hard drive, and I lost a lot (but not my progs, hopefully I have recent backups). The most painful is that I do not have a machine for a couple of days.

Sorry if I was "beside my shoes", as we say in french, yesterday : you can imagine how it feels to lose a HD with, amongst other stuff, 3 years of email...
hink Global, Make Symp' All ! ®
[Image: Banner.gif]
Reply
#24
Quote:no, rel, you're right, i forgot about the context we're solving this is. though you could conceivebly make some infinately complex equations. i think i'm going to make an algebraic interpreter sometime. then i'll kick the asses of all those vanderbilt smartasses...


LOL

Go FSU go!!!!!

Darn!!! 2 days transport strike and I ain't got no car!!!!

No net for 2 days....

Neo: you're barking at the wrong tree. Deriving X is not the problem but the equation being a true Quadratic Equation (AX^2+BX+C=0)

Jark: I already have the torus and sphere equations(Thanks for the link Antoni!!!) but I'd like to see the Mobius strip and its tesselation algo.
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#25
When I have retrieved my progs (after that horrible HD crash yesterday), I will integrate fully parameterizable cubic and quadric raytracing modules in the TC-Lib, in the mood of the existing quadratic module. You will have not only the torus and the moebius strip, but also all the cubic and quadric shapes !

Juts let me a couple of days to develop the 26 coefficients of a general quadric, knowing x, y and are each in the a+b*W form...

when I get a new machine, of course Sad :-?

The moebius cartesian equation is quite easy to retrieve, knowing that:

x = (R+m*Cos (Teta))*Cos(Teta)
y = (R+m*Cos (Teta))*Sin(Teta)
z = m*Sin(Teta)

with m ranging from -r to +r, and Teta from 0 to 2*Pi. Parameters are R (the radius of the global shape), and r, the half width of the strip. I let you solve that, takes only a few lines (tip : Let T = R+m*Cos(Teta))

In fact, the Moebius equation is simpler than the torus equation...
hink Global, Make Symp' All ! ®
[Image: Banner.gif]
Reply
#26
Thanks!!! I could build a model from that. I just don't have access to the equations....

Now for the tesselation....

BTW, could you tell biskbart that the torus tesselation he had from Moteur3d is not Counter-Clockwise so it won't work with negative (right-handed) visibility test but a left-handed one.

The sphere worked fine though.

PS. Here's the fix:

Poly(I).p1=Blah
Poly(I).P3=Blah
Poly(I).p2=blah

Instead of p1,p2,p3

:*)
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#27
I suggested the bisection method because with user inputted equations it is often difficult to get a direct, polynomial equation from that. The bisection method requires no deriving or factorizing, you just substitute values in.

I think the TI-83 uses such an algorithm to find solutions - that's why you have to specify a left/right bound.

Anyway, my suggestion for an equation parser is to find the order of everything, then work through it literally until you need something of a higher "priority":

Code:
(2 ^ (5 + (3 + 0.5))) ^ 2 / (x + 2) = 0

Order: 3 + 0.5, 5 + ?, 2 ^ ?, ? ^ 2, x + 2, ? / ?

Working through recursively:
a = 2 power something
  something = 5 + something
    something = 3 + 0.5
a = a power 2
a = a divided by something
  something = x + 2
Reply
#28
lanzaa, an expression evaluator takes strings and interprets them mathematically. it takes a little work. i was talking about in general what an expression evaluator does, but that's sadly how my program worked (it's painfully slow, as slow on my old 750 as it would be on your 6mhz calculator)

oh, and order of operations is important for all algebraic programs. i remember cgi-joe/generic/whoever telling me though that the calculators converted it to reverse polish notation which somehow make a logical algebraic equation without using parentheses.
i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
Reply
#29
I don't know how relevant this is to this forum, but down here in godzone we use the following formula to find the roots of a quadratic:

If the quadratic is in the form ax^2 + bx + c = 0 then...

x = (-b +- (SQR(b^2 - 4ac))) / 2a

Damn thats hard to write in qbasic form compared with the way it looks on paper... :???: Note the +- sign, you solve this equation twice, once with the + sign and the other time with the - for the two roots. If the result returns an error then the equation has no real roots, just complex ones that I don't know much about.

The b^2 - 4ac is called the discriminant. To find how many roots a quadratic has you substitute in the numbers, to come up with these cases:

1) answer > 0: The equation has two real roots i.e. it cuts the x axis twice
2) answer = 0: The equation has one root i.e. it sits on or hangs from the x axis
3) answer < 0: The equation has no real roots, because you can't take the square root of a negative number in the quadratic formula. This equation never passes through the x axis.

Like I said, I don't know how relevant this is :wink: but hope it confuses :???: er I mean helps :wink: :wink:
Reply
#30
Here's what I'v done for the quadratic (2nd degree) Polynomials:

SUB Equa2 (a#, b#, c#, x1#, x2#, Err2%, nSol2%)
' Second degree equatiion resolution - Discriminant method

Err2% = 0

IF a# = 0 AND b# = 0 AND c# = 0 THEN
Err2% = 1
nSol2% = 0
EXIT SUB
END IF

IF a# = 0 AND b# = 0 AND c# <> 0 THEN
nSol2% = 0
EXIT SUB
END IF

IF a# = 0 THEN
Equa1 b#, c#, x1#, Err2%, nSol2%
ELSE
Delta# = b# ^ 2 - 4 * a# * c#
IF Delta# >= 0 THEN
nSol2% = 2
x1# = (-b# - SQR(Delta#)) / 2 / a#
x2# = (-b# + SQR(Delta#)) / 2 / a#
ELSE
nSol2% = 0
EXIT SUB
END IF


END IF
END SUB

You can see that this routine Equa2 uses another routine Equa1 which is:

SUB Equa1 (a#, b#, x1#, Err1%, nSol1%)
' First degree equation resolution

Err1% = 0

IF a# = 0 AND b# = 0 THEN
Err1% = 1
nSol1% = 0
EXIT SUB
END IF

IF a# = 0 AND b# <> 0 THEN
nSol1% = 0
EXIT SUB
END IF

IF a# <> 0 THEN
x1# = -b# / a#
nSol1% = 1
EXIT SUB
END IF

END SUB

Of course, Equa1 is really a simple pice of code, and it is not absolutely necessary to create a routine for first degree ! But:

The rational is to build "EquaN" routines that solves polynomial equations of degree N, no matter what the coeficients are.

You may have seen above that, for example, the routines return an error code and the number of roots of the polynomia. If all the coefficients are null, then the equation is not defined and the ErrorFlag is set to 1. If an equation of degree N reveals to be an equation of degree (N-1), because the first coefficient is null, then Equa(N-1) is called from EquaN.

Right, first and second degrees are easy, but people who are interested in raytracing need more : I have personnaly validated Equa3 and Equa4, and that was tough! This will allow tracing shapes such torus and Moebius rings, while Equa2 allows "only" ellipsoids, paraboloids and hyperboloids.

Dedicated raytracers such as POV-Ray include a polynomial solver that goes up the seventh degree...

Well, let me a couple of days to build the new pages on these subjects. All that graphic stuff will be posted soon on The Mandelbrot Dazibao !
hink Global, Make Symp' All ! ®
[Image: Banner.gif]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)