solve system of equations. Need help defining variables in app inventor 2

309 views
Skip to first unread message

David Rounds

unread,
Jan 16, 2015, 12:26:58 AM1/16/15
to mitappinv...@googlegroups.com

I was trying to build an app to solve a system of two equations.  I would have an equation like these. 
2500=4x+6y
y=2x

I am  having trouble figuring out how to set up variables using the app inventor 2.  I need to figure out how to create the variables x and y. 
Thanks for the help.  I saw some tutorials on how to define variables but it was all for app inventor 1 and it looks like the define variables differently in version two. 

Aubrey Colter

unread,
Jan 16, 2015, 12:32:36 AM1/16/15
to mitappinv...@googlegroups.com
Here is the documentation for creating variables in AI2: http://appinventor.mit.edu/explore/ai2/support/blocks/variables.html

What you want to do with the system of equations will determine whether you want to create a global or local variable.

Good luck and happy apping!
Aubrey

SteveJG

unread,
Jan 16, 2015, 9:56:19 AM1/16/15
to mitappinv...@googlegroups.com
Here are some possibilities.  These are global variables; they need to be initialized (the value can be anything...I chose 1), then you need to build the equation

and figure out how to solve simultaneous equations.  These 'equations' are part of what you may need.   Here is an AI Classic tutorial   https://www.youtube.com/watch?v=KUX2l07dSYk     The math reasoning is the same.        You do not have to use local variables but you might need to; local variables are only valid within a single procedure.

Be aware, that despite being called global, these variables are only effective on a single screen.  To use them on a second screen you will have to pass the information to that screen and re-instatiate the variables again on that screen.  The simple solution is, use ONLY one screen.

Did this help?

Regards,
Steve




Regards,
Steve

Abraham Getzler

unread,
Jan 16, 2015, 11:38:10 AM1/16/15
to mitappinv...@googlegroups.com
Let's clarify what you mean by "solve a system of two equations".

Do you mean to :
  • just spit out numbers for x and y, without explanation?
  • construct and display a proof of the values of x and y, by transforming and displaying the input equations in successively simpler forms leading to the equations "x = ..." and "y = ..." ?
ABG

Abraham Getzler

unread,
Jan 18, 2015, 12:05:07 AM1/18/15
to mitappinv...@googlegroups.com
You can use Cramer's Rule to set up A2 math blocks  
to calculate x and y from your 2 equations ...

ABG

SteveJG

unread,
Jan 21, 2015, 8:28:51 AM1/21/15
to
Please keep the discussion in the forum David.

I seem to be getting an error from my app.  I attached some screen shot.  I can't figure out what I am doing wrong.  Do you see any errors. I attached my blocks and the app screen.  I am trying to enter four numbers into the top boxes and out two numbers in the bottom. 


Glad to help if you would kindly re-post the images you sent by email in the forum as png or jpg images (you do that dragging the images to the Insert Image tool above in the toolbox (to the left of the words Link).   If I do not know the answer, most probably another forum user will know.   What you sent is difficult to work with and does not allow others to provide their opinion.

How are you inputting the gas/oil ratio?        You need to input it as   a decimal value     0.3333;   not 1/3     and not    1:3      ; that could be the issue.   Incidentally, this is not solving a quadratic equation.  You just have to ensure that all the info required for succeding calculations is present before proceeding to the next calculation in your sequence of blocks.      Have you tried using the AI2   DoIt  debugger to show what values ARE calculated before the issue occurs?  (   http://www.appinventor.org/Chapter15   ) ...look for DoIt

Another problem is Why are you trying to set oilproductionTextBox.NumbersOnly  to  get global x ?           that puzzle piece expects a Boolean value; true or false.    x in your case is a numerical value, not true false.

Regards,
Steve
Reply all
Reply to author
Forward
0 new messages