• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

An example - solving for unknown in equation

Sparky_

Lurker
Feb 27, 2011
6
0
Greetings all -

my first post -

I am looking for an example to go by for the following:

I would like 3 text boxes on the screen and would like to be able to enter values in 2 of the 3 and the app solve for the variable that is left out -

Meaning - the app searches for which box has no information and will solve accordingly - I want to start real simple - Newton's equation / Ohm's law - solve for F, M or A (or V, I or R) depending on which is missing.

Can you point me to an example or help get me started - I feel like this app probably already exists - I don't want the app, I want to know how to do the app.

Thanks
Sparky_
 
I was hoping / assuming what I wanted was not that sophistacted - I'm really wanting this for simple engineering equations.

What makes this sophisticated? - identifying the empty box?

How can I find the calcs you recommend? - these are examples and not just apps to install?

Thanks
Sparky_
 
Upvote 0
The sophistication comes in knowing what equation you're trying to solve and building the catalog of relevant equations.

Handycalc does have a few things built in and if you know the equation it'll solve it pretty easily for you without having to rearrange the equation, but you still need to know what the equation is. Another option that might be up your alley is to get the Wolfram|Alpha Android app. You can just put your variables in and it will determine and calculate the relevant equations and answers.
 
Upvote 0
That sounds close to what I'm wanting -

My 3 equations would be V = IR; R = V/I and I = V/r

I would like 3 boxes and the one that's empty is the one that is solved for. I'm wanting to write this myself (just getting started in this)

Can you point me to the web site that would have the code for the Handycalc or Wolfram or the closest to my descriiption?

Thanks
Sparky_
 
Upvote 0
OK, I think I'm understanding you better. You're looking for example code to write your own app to solve for whichever missing variable in Ohm's Law?

Both Handycalc and Wolfram|Alpha are applications and you won't be able to get their source code. Even if you were able there would be thousands or millions of lines more code than you need in your case. What you're trying to do is fairly straightforward and should be a pretty simple application to create for Android. Just to see if I could I built a very basic version in AppInventor in about 10 minutes. Three input text boxes (with labels) and a "calculate button". It checks each box for a blank and then sets the empty one with the correct calculation of Ohm's Law.
 
Upvote 0
As I mentioned, I used Google AppInventor to do it and there is no way to export Java sourcecode from AI. Even if I could it almost sounds like you're asking someone to do your homework for you, and I'd hate to do that.

I am attaching a screenshot of the relevant Blocks view from AI that might give you an idea of a direction to head. As I mentioned, what I did in 10 minutes was VERY basic. The logic has no input or error checking at all, but it DOES work if you put numbers in the right text boxes. It probably wouldn't take me more than 30 more minutes to implement at least halfway decent input checking.

ohmslaw.bmp
 
Upvote 0
Thanks

I have found tutorials and examples for various projects and am hoping to find examples and similar for this example of a simple equation solver (Ohm's law / Newton so forth).

I know there is no way to prove this - this is not "homework" this is purely a hobby project (I am an EE and intend to use this as a starting point to add more to as I go).

-Sparky_
 
Upvote 0
Thanks

I have found tutorials and examples for various projects and am hoping to find examples and similar for this example of a simple equation solver (Ohm's law / Newton so forth).

I know there is no way to prove this - this is not "homework" this is purely a hobby project (I am an EE and intend to use this as a starting point to add more to as I go).

-Sparky_

Sorry Spark,

I misunderstood you. I thought you had wanted more than just 3 related equations!

That should be easy. First, you label the first box V, second box I, third box R.

You have one button that says "Calculate", and one that says "Clear".

Then simply check which box is empty and check that 2 are filled, otherwise give an error message. It shouldn't be too difficult. The java coding behind it would be more difficult for the graphics then the actual equation.

For the equation it'd go something like,
x=0

if R = ""
x = x+1

if I = ""
x=x+1

if V = ""
x=x+1

if (x<=1) {

if R=""
R = int(V)/int(I)

if V=""
V=int(I)*int(R)

if I=""
I=int(V)/int(R)

}
Something that simple would suffice, but the graphics I honestly have no clue!

Check out Google's "App Inventor" :)

Edit:: That coding isn't copy/pastable. Just a basic guideline.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones