tl;dr: Looking for a java library to solve equations. Suggestions welcome.

I'm looking to write an app for the sake of writing an app.
I figured that, as a firmware guy with minimal EE hardware training, a good practice app would be one that acts as a helper for EE projects. One of the things I wanted to add was an equation solver for things like Resistor/Capacitor rate of discharge, etc.
But it's not enough to solve for the same variable over and over. I'd like to choose a known function, then be able to plug in the known values and get back the unknown value, whichever variable it may be. Something like http://hyperphysics.phy-astr.gsu.edu/hbase/electric/capdis.html

At first I looked into Functional Programming, but I'm not sure it's the right way to go.
Digging around Wikipedia, I found Constraint Programming (using linear/float variables) which seems close to what I'm looking for but not quite either. It'd be nice to put in an equation once without having to hash through every derivation.

Any suggestions?

define "equations".

I second the question; are you looking for an algebraic solver, like a system of equations kind of scenario?

What do you see as an equation?
1 + 3 + 4 - 1 / 2 = ?
or
"1 + 3 + 4 - 1 / 2 = " ?

Those are expressions, "equals" sign notwithstanding. Or is the "?" in the first example meant to be a variable name?

I guess stultuske is trying to ask you if you are trying to make calculations in java? or show those in a textfield or label?

Edited 1 Year Ago by altjen

Uh... no. Just no.
For those, I'd use a shunting yard algorithm.
This is a bit more complex.
ide13.gif

What I'm looking for is a library that can read in an equation, parse the relations between the variables and can reverse the relationships so if I give it any set of all-but-one known values, it can calculate the unknown variable.

Now that I've laid out what I'm really asking, it dawns on me that I may as well just hard code all the equation variations in.

Unless someone knows of something better.

my question was: how do you actually get the equation? as a String? or do you get them part by part with the operators known?

The best way (imo) would be to code it yourself. sure, there might be a library out there to solve equations, but are they solving also the ones you need solved? and do they solve them correctly?

What I'm looking for is a library that can read in an equation...

Well, if your input is like the example (V = Q/C = ...), you can split at = and proceed with shunting-yard as you said, at least for this portion.

parse the relations between the variables and can reverse the relationships so if I give it any set of all-but-one known values, it can calculate the unknown variable.

Hm. Something like MATLAB?

This question has already been answered. Start a new discussion instead.