salter Posted March 7, 2009 Posted March 7, 2009 I just started learning how to do VB and I've been searching everywhere for hours and can't find anything on how to do something. I want a user to be able to input an equation in terms of x that the program can then run values through. can anyone help?
Klaynos Posted March 8, 2009 Posted March 8, 2009 It's quite a difficult thing to do, and gets exponentially more difficult with the complexity of equations you want it to understand. Being able to recognise x+5 or x-5 is relativily easy but x+5(x-5) is significantly harder. The easiest way I can think of is after they have typed it in is taking each character and running a series of if statements to identify what to do with/after that character.
John Cuthber Posted March 8, 2009 Posted March 8, 2009 I could tell you how to do this with a commodore pet (and it was difficult then) but I don't think it will help.
Xittenn Posted March 8, 2009 Posted March 8, 2009 Are you trying to create an interface through which an equation can be input and answered or are you trying to write an equation in VB which upon compiling and executed will render a result? Also why Visual Basic?
doG Posted March 9, 2009 Posted March 9, 2009 Kant/Kash and Fortran come to mind when I imagine the logistics of implementing such a math procedure. Even C offers much more functionality than VB.
John Cuthber Posted March 9, 2009 Posted March 9, 2009 Somewhere hidden away in the source code for VB there already is a routine that "understands" things like 4*x^7 that's how you can put that formula into a line of code and get the program to calculate it. Writing your own software to do that woold be redundant and frankly rather hard. The trick with the pet was to force the machine to stop, write the equation into a line of the code that was already running; then restart itself. (That was cheating- but it worked). In effect the program rewrote itself yo include the new code. God knows if that's possible in VB but if there is some similar trick to use the stuff that's already written, it's almost certain to be easier than trying to write your own interpreter.
doG Posted March 9, 2009 Posted March 9, 2009 Somewhere hidden away in the source code for VB there already is a routine that "understands" things like 4*x^7 that's how you can put that formula into a line of code and get the program to calculate it. Actually that would be handled by the runtime interpreter, not VB itself....
Xittenn Posted March 10, 2009 Posted March 10, 2009 (edited) int binomial(int term0, int term1, int right_side) {}; int trinomial(int term0, int term1, int term2, int right_side) {}; float polynomial(char* equation_left, char* equation_right) {}; multiple variables/substitution equations................matrices(I'm sure I've gone to far)..........I do that sometimes...........integrals............ Where exactly does salty want to go? Maybe the world will never know! Merged post follows: Consecutive posts mergedVB is good for one thing and one thing only batch renaming of files.......you should try it sometime! Edited March 10, 2009 by buttacup
salter Posted March 12, 2009 Author Posted March 12, 2009 Thanks for all the help. I was hoping that there was a simple command for the input of a formula but apparently not in VB... the only reason im using VB is cause it was the first thing i found to download. Perhaps C++ would be a better choice? I set up my own way of doing it using a drop down menu with different possibilities and then wrote code which ran operations based on the choice... you can also choose to alter the value of X again... aka you could choose ln(x) the first time then press modify x and choose sin(x) and you would get ln(sin(x)). works but i'm trying to add up terms of a sequence so its too slow and the simple program i wrote on my TI-84 is actually faster. Merged post follows: Consecutive posts mergedbtw this is for calculating what wierd series converge to in calc 2. So i need much more than polynomials etc.
Xittenn Posted March 12, 2009 Posted March 12, 2009 (edited) C++ would be a way better choice! Although it's still no solution to just 'inputing an equation!' Inputing an equation would be better done through MAPLE or Mathematica; well I think I've never actually had to use any of them.......... But making your own would be so much cooler. You can still make forms in C++ or you could make your own GUI. It could have all sorts of icons on it like roots and powers and well whatever you want(obviously........ ) I think C++ is a better option for you because it's function declarations, variable passing and structure like stuff are so already availlable. Not that VB isn't capable it just needs some extra coaxing to get it done! You could basically have a calculator that you could input the equation and then in code it could read it as a character array and break everything down into monomials(this needs to be severely expanded on.) You could create Monomials as Objects and give them a rigorous series of tests to better define how they can be treated inside of an equation. You could Parent them inside of Equation and relate the tests to define how the equation(s) should be treated. C++ is pretty easy to learn..................... I don't know it sounds like fun...................... p.s. you know that capacitors don't do work right? I felt so bad................ Divide by 4*pi*f.................15J is in the 'Threshold of Fibrillation.':D Edited March 12, 2009 by buttacup
doG Posted March 12, 2009 Posted March 12, 2009 You might take a look at TTCalc if you're looking for the functionality offered in a programmable calculator. It has an array of built in functions and the functionality to define your own variables and functions. It's also an open source project written in C++ so you could even modify it if you wanted.
Xittenn Posted March 12, 2009 Posted March 12, 2009 btw this is for calculating what wierd series converge to in calc 2. So i need much more than polynomials etc. Did you add that while I was writting a response? That doesn't really change anything I said though so............hmmm TTCalc............ you sounded like a kid: "So if you see something in the paper about a kid blowing himself up it's probably me. lol."
salter Posted March 12, 2009 Author Posted March 12, 2009 Well i am 16. idk if you consider that a kid or not. and btw i don't even remember the things i posted about capacitors and tesla coils earlier. i figured out all the answers outside of forums and have my coil up and running.i wish my school offered programming and AP physics... then most of my questions would probably be something i already knew. i think what i'm going to do regarding the programming thing is teach myself multiple languages. they are all nice to know and i enjoy it so why not. lol i can get it to work in vb just not fast enough. sorry im not quoting and everything is slurred together. im doing this on my cell
Xittenn Posted March 12, 2009 Posted March 12, 2009 You're inputing specific series and testing convergence in VB? Can we see some code? Care to elaborate? How many nF did you make the cap, same transformer?
salter Posted March 13, 2009 Author Posted March 13, 2009 i made the cap 4 nf and messed with the inductor until it matched. i used a 10k volt 30mA neon transformer aww i have to post code? but im a lazy teenager. lol ill just describe it its pretty simple. I used the thing i talked about above with three fields: constant and two "n's" as drop down menus, one in a numerator and one in a denomitator. By each n there is a "modify n" button that lets you get things like sin(ln(n)) or sin(n+1). then there is a next term button and it adds up to 8 terms that you enter in the same method. it then does operations based on what you entered using math.whatever commands. I made it a little faster by making it skip over all the if statements for terms past the first one using If constA = 0 Else... then listing the other ifs. It's slow but less code than actually having it interperet each character lol and then it runs through this '(tons of Dims) For Me.L = 1 To num '(A1 = const1 * TermN1, A2 = TermND2, etc. using ifs) sum = (A1 / A2) + (A3 / A4) + (A5 / A6) + (A7 / A8) + (A9 / A10) + (A11/A12) + (A13/A14) + (A15/A16)+ sum X = X + 1 TextBox2.Text = sum next end sub Merged post follows: Consecutive posts mergedit just runs it up to a specified number of terms and gives you the sum. it shouldn't be hard to find convergence using that... i could make it find convergence but it would be a pain. have it save the sums and find where it no longer changes past the third decimal place or something like that. Before i figured out how to make it input an equation i just put in the formula in the code where the if statements would be and did it that way. I tested one up to 500,000 then 1,000,000 and when they were the same i figured it was safe to say it converged to that. lol the one on my calculator displays the newest "sum" value over and over so that you can watch it work and tell where it stops changing then stop it, but i cant figure out how to make VB display it every time it loops. even though i wrote textbox2.text = sum within the loop it doesn't display it until afterwards.
Xittenn Posted March 14, 2009 Posted March 14, 2009 Not that VB isn't capable it just needs some extra coaxing to get it done! You guys are such language snobs, picking on VB. Oh no, it doesn't do multi-line comments! Heaven forfend! I doubt most people even know what partial interfaces or iterators are, much less have ever used them in code, but those are just about the ONLY differences between VB and C#. Both languages compile to the same Intermediary Language, then JIT-compile again at execution time, so all your high-fallutin' C# code looks *exactly* like that low-brow VB code after you smack the Build command. Posers. I still prefer C++! i made the cap 4 nf and messed with the inductor until it matched. i used a 10k volt 30mA neon transformer aww i have to post code? but im a lazy teenager. lol ill just describe it its pretty simple.. Awesome! Just try finding a way of computing through without actually going X+1........................ Reading the characters was less about a cyclical event and more about just typing in an equation and assaying it to better perform the task above! Who are "you guys" and who even brought up C# except for you? BTW, Kant/Kash and TTCalc are not languages but ready made solutions for doing math. I thought Kant was an 18th century German philosopher? Who said TTCalc was a language?
Xittenn Posted March 14, 2009 Posted March 14, 2009 Environment * Pascal like programming language, * user extensible library, * help system (TeX based online help), * more than 1000 pages of documentation, * examples for the programming language, * PVM access in the programming language of KASH, * PVM support for many parts of KANT, * database for number theoretical data, * colour support. colour support!
John Cuthber Posted March 15, 2009 Posted March 15, 2009 Does any of this actually answer the OP's question?
timo Posted March 15, 2009 Posted March 15, 2009 (edited) It's a variation of Godwin's law, also known as the Zuse Uncertainty principle: Whenever someone asks a well-defined question about doing something in a particular programming language' date=' the thread will ultimately turn into a discussion why he should use language X not Y or Z. After that the intellectual level of the discussion will then, after some initial well-meant but completely irrelevant arguments about compiled vs. interpreted and modern programming paradigms, degrade to primitive "I have 136521 years of programming experience, therefore you are an idiot"-arguments.[/quote'] To fake on-topicness of this comment: - Keywords to look up would be "equation parser" or "function parser" - You can probably find some ready-made ones on the net that are free to download and use. - If just writing the equation into the source code of the program is a serious option, then save yourself a lot of trouble and go for that rather worrying about an equation parser. - Do not try checking convergence of an infinite series with a computer! Use the computer as a tool showing you the first few elements in the series (to better understand its behaviour), at best. Edited March 15, 2009 by timo
salter Posted March 15, 2009 Author Posted March 15, 2009 not at all; however feel free to continue this is interesting. lol Merged post follows: Consecutive posts mergedIt's a variation of Godwin's law, also known as the Zuse Uncertainty principle: THATS INCREDIBLE lol
doG Posted March 15, 2009 Posted March 15, 2009 Does any of this actually answer the OP's question? No, it's drifted on to something else now....
Pangloss Posted March 16, 2009 Posted March 16, 2009 Language evangelism comments that should never have been in this thread in the first place moved to separate thread.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now