# Solving Equations

Well, I don’t boast a whole lot about my programming (mainly because I know programmers who are a billion times better than me, ie. Guy Perfect) but today, I think I’ve got something worthwhile. (Skip to the last paragraph if you don’t care about the backstory.)

On and off over the last 28 days (according to my project file’s Created On date) I’ve been working on a program to solve equations. It may seem simple to you, but it’s about as difficult as making a very small programming language. The program must parse the lexicons (numbers, variables, binary operators, unary operators, grouping symbols), fix shorthand (7x is 7 * x), order all the grouping symbols, and run through the rest of the order of operations, repeating the process until all but one lexicon are eliminated.

With such inconsistencies as the Mid function using locations ranging from 1 to the length of the given string (piece of text) compared to the many arrays which start with 0, it’s extremely easy to make a mistake, and any mistake could result horribly. For example, just a few minutes ago, as I was showing the program to the school principal, I realized that I had made a mistake rendering the program entirely useless (except for, specifically, x = e). So I spent a few minutes looking at the code and realized that a snippet I had copied and pasted had a single number incorrect–I used 120 (the ASCII value of “x”) instead of 101 (the ASCII value of “e”), and that resulted exactly as one would expect.

Of course, that mistake was not the only of its kind. The process of my programming is riddled with constant mistakes of overlooking and thinking incorrectly. In short, it took 28 days to make a program of about 600 lines of code which is capable of solving any equation that could be solved by any programmer with just a few lines of code. For example, I have “3(x + 4) - x ^ 2” as my program’s default equation. With just the code

```For x = -10 to 10 y = 3* (x + 4) - x ^ 2 txtResults.Text = txtResults.Text & y & vbCrLf Next x```
the equation would be solved and the answer reported for 21 different values of x. But of course, not everyone has a compiler at their disposal; even though it’d probably take a few seconds to get one, they’d have to learn something about the syntax to make it work. I decided on a whim to develop this program, which I thought would also help to hone my skills, and share it with others who may want to play around with it or actually make use of it.

Cool!

Yeah, it sounds like it’s a pretty large project to program. Tons of low-level string interpreting and all that…

But seriously: No Pi? WHAT?! <_< It works if you use “pie” instead, but the program reads that as just “e”. Placing x’s together past “xx” doesn’t work. Nested parentheses also don’t work. And, the graph doesn’t clear itself automatically for some things. You have to re-graph it or move it.

Other than those small things I noticed, nice job. I like that the trig functions are working, even if only the main three.

Programming: When you spend more time fixing your mistakes than you do adding new content.

Ah, I didn’t catch that xx one yet…I probably just need to stick “-1” in there. Also, the graph actually isn’t supposed to clear itself. That’s why there’s a clear button. You’re supposed to be able to put some graphs on top of one another, for comparison purposes.

But yeah, “pie” would be read as “e” because the program is set up to completely ignore unknown characters. I can certainly implement pi on the first try… Also, I just realized that case matters–X will be ignored, whereas x will not. Thanks for your input! (I’m working on the nested parentheses problem right now. Looks like it’s actually not doing them in the right order, but that’s weird because for the parentheses I only slightly edited code I used for a high-score table I made once.)

EDIT: “xxxxxx + 1 + 1” actually works. Turns out I don’t need a “-1,” but rather a “+1.” (And I don’t mean in the equation, although that was a funny coincidence.) I can explain that–my loop said “For x = 1 to LexiconCount - 1,” and LexiconCount increased each time it saw an implied , but it only checks with the original value from when the loop began; therefore, while LexiconCount may have been 11 (xxxxxx = 11), the loop quit at 5 (xxxxxx = 6) because that was LexiconCount - 1 when said loop began. So I’ve got that fixed, but I’ll upload it when I think I’ve fixed the parentheses.

EDIT 2: I think I’ve fixed the parentheses. Had a variable name slightly wrong. It’s re-uploaded now. Same link.

Seems to be all fixed now.

I was just confused about the graph clearing, because if you graph more than one function and then move or center the graph, previous ones are cleared out. If it’s not an easy fix, don’t bother, as it’s easy enough for the user to get around it. >_>

MZ asked me to make a Metroid out of functions. So I used this program to do so.

The function along the top is the one in the box in the screenshot, and the function along the bottom is y = (100-tan(x^2*2))^.5-10 . I found out just after taking the screenshot that y = (100-tan(x^2))^.5-10 looks better in that view, and vertically stretching the top function by like 1.25-ish along with that looks better. But meh, I had fun in those few geeky minutes of messing around, and it kind of looks alright.

Just for the sake of letting you know, I added resizing abilities today.

Wow MMC, this is kinda impressive!