Question

I'm working on a graphing applications that basically graphs equations with on an HTML5 canvas. I had no problem graphing equations that were along the lines of y=3x^(2) etc. That was as easy as plugging in a given x value, substituting exponents for native functions and voila!

Ideally however, I'd like to graph equations for circles and other equations that don't necessarily start with y=.... This would require actually doing algebra, which, unfortunately is not so easy. My question is: what is the most logical way to solve a problem such as 3x+3y=15? Let's assume that I'm given an x and I'm solving for y. How would you go about creating a function that solves it?

Obviously, I could choose to be extremely inefficient and loop through y values until I find one that satisfies the equation, but let's try to avoid that.

I'm not asking for you to write the script for me, I'm just asking for the best/most efficient thought-process to get started.

Currently, this project is being written in Javascript.

Thanks!

Was it helpful?

Solution

One (approximate numerical) way is to take your equation re-write it as P(x) = 0 [in your case P(x) = 3(x^2) + 3(y^2) - 15] and then use a numerical technique such as Newton-Raphson to find the roots of P(x)

If you want to solve symbolically, then a Computer Algebra System (CAS) is required (non-trivial).

OTHER TIPS

usually you would express the equation with one variable on one side of the equals sign and the other variable on the other.

If you want to rewrite equations form random user input, you will need some kind of parsing engine.

look here for a discussion

y=3x^(2) is not linear its quadatric, 3x+3y=15 is in fact linear.

It depends on how complex you want to go, it's not that challenging to write something to rearrange a linear equation like 3x+3y=15 into its standard linear form (y=5-x), but it gets harder fast and while there are probably server side libraries for it, i'm not sure about JS.

The proper name for what you are looking for: http://en.wikipedia.org/wiki/Computer_algebra_system

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top