+ Reply to Thread
Results 1 to 6 of 6

Is there an algorithm for finding the set of equations in physics that you need to use?

Hybrid View

tahi.laci Is there an algorithm for... 08-04-2014, 12:45 PM
MrShorty Re: Is there an algorithm for... 08-04-2014, 01:53 PM
tahi.laci Re: Is there an algorithm for... 08-04-2014, 02:22 PM
MrShorty Re: Is there an algorithm for... 08-04-2014, 02:46 PM
scottiex Re: Is there an algorithm for... 08-04-2014, 05:26 PM
tahi.laci Re: Is there an algorithm for... 08-06-2014, 04:19 AM
  1. #1
    Registered User
    Join Date
    04-16-2013
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    52

    Is there an algorithm for finding the set of equations in physics that you need to use?

    I would like to make a program in VBA which can solve physics equations. It would be given a bunch of basic equations in memory and the given physical quantities in each task.

    For example these equations are given: R=V/I, V=W/Q. If you need to calculate R and V and I are given then you would just substitute into R=VI as that equation has all given quantities and the one you want to calculate. However if you are given W, Q, and I, one way to find R would be is to solve R=V/I and V=W/Q simultaneously. However as V is not given it's so obvious that these equations should be used.

    My question is what algorithm should be used to choose the right equations from all of those available.

    Should it just look for anything that can be calculated from the given quantities or is there a more elegant method?

    (I'm fine with substituting, solving simultaneously and finding the units.)

    Note: sometimes there's not any equation with a single unknown: P=VI, R=V/I with P and R given
    Last edited by tahi.laci; 08-04-2014 at 02:03 PM.

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,577

    Re: Is there an algorithm for finding the set of equations in physics that you need to use

    What are the characteristics of an "elegant" method? (somewhat of a rhetorical question -- I really don't know if there is an answer to it).

    When I have done similar programming, I will usually use some kind of block if structure: http://msdn.microsoft.com/en-us/library/752y8abs.aspx

    If R<0 then R=V*I
    If V<0 then V=R/I
    If I<0 then I=R/V
    
    In this case, toggle value is to solve for the variable with a negative number in it
    since I will generally assume that I will never talk about negative values.
    I don't know if that would be considered "elegant", but I usually find it to be the simplest to code and the simplest to modify when modifications are needed. IMO, Simple and easy are part of elegant, even if it seems to be tedious.

    Back when I used a programmable hand calculator, I understand that the calculator would use a numerical (Newton Raphson type) algorithm for these kinds of problems. After selecting what to use for the "solve for this variable" toggle (usually leave variable blank), the calculator would "find the root" of the equation f=R-VI=0 (If you are unfamiliar with root finding algorithms: http://en.wikipedia.org/wiki/Root-finding_algorithm ) Coding this is not as "simple", but it may be more flexible -- especially when dealing with equations where the algebra to solve for the unkown is complex or even impossible.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Registered User
    Join Date
    04-16-2013
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    52

    Talking Re: Is there an algorithm for finding the set of equations in physics that you need to use

    By "elegant" I mainly mean a method which is well defined and always works, as supposed to just saying "write equations until you have as many equations as unknowns". Also using as few lines as possible. When you tell that to a human you can expect them to use their experience, common sense or come up with something new.

    I think you misunderstood the question. I will use an external program to rearrange equations, substitute and solve them, so I don't need to worry about that. A clearer example is like this:

    equations given:

    P=VI
    R=V/I
    V=W/Q
    E=Pt
    I=Q/t
    s=vt

    The problem I can't find a solution for is to find the equation from the list which applies, these examples show what the algorithm should return with example inputs.

    Examples
    given: I=2 A, R=10 ohm, V=? solution: use equation: R=V/I
    given: W=30 J, Q=5 C, I=2 A, R=? solution: use equations: V=W/Q, R=V/I
    given: P=20 W, R=5 ohm, I= ?, V=? solution: use equations: P=VI, R=V/I

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,577

    Re: Is there an algorithm for finding the set of equations in physics that you need to use

    It still looks to me like the same basic approach -- using a bunch of IF/Then statements or block ifs. The complication I see now is that you are asking the code to make two judgements -- Based on the given inputs -- which group of equations to use. For example, if R, V, and I are the variables of interest then go into the "ohm's law" section of equations. If P, V, and I are the variables of interest, then go to the power law equations. And so on. Once the code has decided which "section" to go to, then it needs to identify the unkown and choose the correct form of the equation to solve for the unkown.

    Since it appears that all of the equations you are looking at seem to be different properties in a arg1=arg2*arg3 type function, maybe the "elegant" approach you are looking for is something like:
    Decide which equation is indicated (ohm's law, power law, newton's law, etc.) then feed those values into arg1,arg2,arg3. From there, you can program the "solve for the unkown" part of the problem for all variations.

    For example: if user indicates that P, V, and I are the variables of interest, the code can then feed P into arg1, V into arg2, and I into arg3. Then, based on the "which is the unkown variable" toggle, solve the problem.

  5. #5
    Forum Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,347

    Re: Is there an algorithm for finding the set of equations in physics that you need to use

    maybe if you list all the formula in column A, then all the variables in column F then run a series of substitutes like this

    =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,"/",""),"=",""),$F$3,""),$F$2,""),$F$1,"")
    nested as many times as you need
    which gives you the things you can solve for (including combinations eg I,V etc)

    (or using VBA you could do the same in a more robust way that deals with + symbols and other unknown symbols)

    Then the cell with len() = 1 is a thing you want to solve for,
    so you can construct the equation from that which has that letter on one side of the = sign.

    You could do it from a table of the possible formula or if that is not elegant enough (maybe you don't want to have to build it) some other method like moving the other items to the other side of the = sign and inverting them.

    Not sure if this is elegant or not !
    Last edited by scottiex; 08-04-2014 at 09:44 PM.

  6. #6
    Registered User
    Join Date
    04-16-2013
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    52

    Re: Is there an algorithm for finding the set of equations in physics that you need to use

    This could be a first step, but not a final solution. This would work for all my examples only because I didn't make them general enough by mistake. What if in the last example you're only asked to find I?

    As a first step this could simplify the problem to: from a list of strings IV, IV, R, WQ find as many as the amount of different letters in them.

    Eg
    given R found: R (1 string with 1 letter)
    given I found: IV, IV (2 strings 2 different letters)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Pinballing physics teacher signing in :)
    By Wizards_Hat in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 12-20-2012, 09:51 PM
  2. algorithm help
    By david90 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-30-2012, 10:33 AM
  3. WAP for given algorithm
    By newguy59 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-15-2011, 07:11 AM
  4. Sorting algorithm
    By Newbie_Nick in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-17-2010, 11:52 AM
  5. Algorithm Challenge
    By Lowkey in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 12:05 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1