Graphing Calculator (anyone know how to do this?)

So I am making a graphing calculator and I need a way to put in any function with an x (and or z) variable and output the y. The problem is, there isn't really a good way to take a line of text and calculate it. Just to do something like calculate a simple equation like "y=2(x+1)" would be difficult because the program would have to read each individual character, look for signs, look for parenthesis, and make a list of which parts of the function need to be calculated first (stuff inside parenthesis). Does anyone know of any tricks to do this/has done this before?

@DomiNation I don't know if this is the best way, but you could check each character to see what it is....first you could find the = to separate each half. Then for order of operations you (using trim text i think) could find the innermost set of parentheses and so on, and then multiply (or whatever operations) their results in the correct order.
For example you had y=2(x+1). you find that x+1 is in parentheses so you multiply 2* the x+1 result.
If you had something like y=3[5(x2)7]/10 or something( I don't know if I did that rightðŸ˜³) it would get kinda hard....maybe it would work thoughðŸ˜¬ðŸ¤”
It might just be a dumb idea!

Oh well I guess I will give it a try. I will have to break the function up into sections and rearrange them so they are in order, then take all the numbers and operations and solve it.
Does anyone know how a real graphing calculator would do this?

@DomiNation You can make something that reads each individual character quite easily (e.g. My 3D code reader), but making it do stuff with it will be hard especially for a graphics calculator.

@DomiNation ...I'm not sure how a real graphing calculator would do this... But I agree that you will need to break up functions.
It might be wise to wait for Hyperpad to implement their own coding functions. That way, you can save different properties and operations to reuse inside of bigger grouping symbols. You could start with Hyperpad onebehaviors such as addition, subtraction, multiplication, division, modulus, sinus, and other mathrelated logic behaviors. Then, you can move on to creating functions for absolute value, fraction to decimal conversions, geometric formulas, etc. Then, you could do the grouping methods and applying the behavior functions to the algebraic functions. Finally, to go even further and graph these functions, you would have to make algorithms for plotting and connecting points. Actually, most of the functions are going to be clever ways of using code to carry out exactly what you would do on paper.
If you aren't keen on waiting for functions, you could get these methods on a piece of paper and copy them over each time you want to use them.
Hyperpad lags when crazy amounts of behaviors overload inside of one object. Try to spread out behavior use, while still maintaining organization...

@iTapDevelopment @AidanOxley @GameCRAZY
My current plan is to do something like this:
Step 1:
A Loop trims individual characters from the function and decides what the character is. For example, it will decide that it is an operator or a number. It will look at the previous character to see if they are the same type. For example, if the character is a number and the previous character is also a number, it will group these characters together. If characters, such as digits of a longer number, are in a group they will be combined and saved as one group in an array. The loop will build a list of all the groups. For example, if we take the function "2(sin(x+34))" the loop would split it into separate values in the array like: "2" "*" "(" "sin" "[" "x" "+" "34" "]" ")" Notice that I added a multiplication operator between the "2" and "(" and replaced the sin parenthesis with brackets to mark the beginning and the end.Step 2:
Now that we have an array we can start to reorder it so we can calculate it. Another loop will look for parenthesis in the array. When it finds one, it temporarily stores the location in the array. The loop continues until it finds the close parenthesis (if it finds another open it will keep searching and count until it finds the end to the original parenthesis). Next it repeats the same thing inside the selected parenthesis, looking for parenthesis. If there are no more parenthesis it will look for exponents, fractions, sin/cos/tan, multiplication, division, etc. It will compile a list of all the smallest possible functions. These functions will be used when calculating the larger functions and so on until it gets to the end. For example:Origional Function:
y = "2(sin(x+34))"Step 1:
"2" "*" "(" "sin" "[" "x" "+" "34" "]" ")"Step 2:
Function1: "x" "+" "34"
Function2: "sin" "Function1"
Function3: "2" "*" "Function2"This way, we can say that y = "Function3"
So when I need to calculate the whole function, I just calculate "Function3"
I know that it is very easy to create custom functions and call them in real code (or at least in PHP which I know a little) but I'm not sure how to do this in Hyperpad. Any suggestion on how to create and call custom functions? Any critiques or concerns? :)TL;DR:
y = "2(sin(x+34))"
...is the same as saying...
Function1: "x" "+" "34"
Function2: "sin" "Function1"
Function3: "2" "*" "Function2"...therefore...
y = "Function3"
...how do I create and call on custom functions in Hyperpad?

*I think I can create new functions this way:
Have an Object already set up with a blank Function in its behaviors.
Duplicate this object whenever I need to create a new function.
The object would get an ID (an attribute), which increases for every new Object.
The object would fill in the blank function (maybe by receiving broadcasts sent by the "brain" that spawned the objects or have the "brain" set attributes for the new Object)
Whenever the function needs to be called the object can be activated in some way (maybe a with broadcast with the object's ID)
Once activated, the object will get any values that it needs to use in its function and calculate it, then send the calculation back to the brain :)

@DomiNation what do you mean by a blank function? I would avoid duplicating objects if you can, cause if it's something like your sine wave generator, spawned objects will make the performance worse.

@iTapDevelopment The blank function inside each object would just be a couple of box containers and an if system to figure out which operator to use. When the object gets spawned, it will be given a function. The box containers would be filled in with a number or variable or maybe even another function. It would also store which operator to use (multiplication, division, add, subtract, etc). When the function gets called, the object will decide which operator to use (with some if behaviors for each operator) then use the values from the box containers in the operation. It is a bit hard to explain but it should be easy to do :)
Also, spawning new objects would be the only way to do this (unless I had a few blank functions set up in the main object but then I would have a limited number of functions that can be done). Anyway, it would only be spawning like 5â€“10 objects so it shouldn't drag down performance a lot.

@DomiNation Functions aren't possible. If you try to do this all in one object, Hyperpad will lag crazy.

Use an array:

@DomiNation ok when you say function, what exactly do you mean? Like a math equation?

@iTapDevelopment f(x) = mx+b is the most generic generic linear function.
A function is basically any type of relationship or expression involving more than variable, in which each member of the domain has one input in the range.

@GameCRAZY ok. @DomiNation So couldn't you just store each expression like f(x)=mx+b as an index in an array? The. You can get the different values and load them into your equation solver( like you described above, with the trimming and checking characters etc.).
Or you could use dictionaries if you need to find it by name or something.

@iTapDevelopment @GameCRAZY I could use that function but then I would be limited to only that function. I want to be able to just paste any function in. Also when I said "y=Function3," and so on, I was referring to the coding function (a set of code that is set up and can be executed from another part of code). Anyway, you guys are right that I dont need seperate objects (I have no idea what I was thinking when I said that).
I pretty much have it planned out so it should be done in a couple of days.

@DomiNation ok great! Hope it works well!

@DomiNation No, I was just explaining to @iTapDevelopment what a function is in Algebra. This was just one example...
Let me know how it works out!

@DomiNation So, will you be creating a parser? That's always a course of action.