Converting from String to Mathematical Expression.

Christopherx

Well-known member
Joined
Jul 4, 2010
Messages
58
Programming Experience
Beginner
I want to take the equation in a string variable, and solve it for 0. For arguments sake, let's say this..
Dim Eq as string
Eq = "Y = 4x^2 + 3x^3"

How would I then substitute, so the program actually carries this Equation out ? This ISN'T homework, but nonetheless, this is something i've been trying to achieve for a while, so please don't spoil it all! Just a nudge in the right direction please :D
 
By solve it do you mean plug in a number for x and the program will give you y or plug in y and the program give you x.

I can't really come up with a good plan for solving for x but if you want to solve for y i think a recursive function will do it.

pass in the right side of the equation and the function returns the left side. call it Solve()

Solve(4x^2 + 3x^3) returns
Solve(4x^2) + Solve(3x^3) returns
SquareRoot(Solve(4x)) + SquareRoot(Solve(3x)) returns
4*SquareRoot(Solve(x)) + 3*SquareRoot(Solve(3)) returns
 
I dont think I was clear. I do understand that recursive idea, and I think that would actually be quite good, but I think it doesn't work. What I am trying to do is write a program to eventually calculate the stationary point of a Parabola. It's just for my calculus project, to help me gain a better understanding of it all. I've worked out the differentiation part but when solving it, there are alot more rules, and things that the computer needs to go through before a value can be calculated. I'm thinking about the computer actually analysing the string, and if certain conditions are met then its happy days. It's just a case of getting the values into integers, and stuff. I'll message you with how it goes, but thankyou very much and I might have a go at that solution.
 
Back
Top