Skip to main content
GameDev.net gamedev.net
🔒 Locked

Math question

Started by Dreq Jun 9, 2006 at 9:04 AM 11 replies 800+ views
Original Post
Dreq
Dreq
I am working on converting an excel spreadsheet into sourcecode, but I've ran into a problem. Heres a simplified version of the problem: where A = 4: B = A + (C * 2) C = B / 2 What is B and C? Excel says B is 40, and C is 20.. the only way I can get to that value is by iterating 10 times starting where C = 0. I am almost certain though that theres a mathematical way of doing this... any help would be greatly appreciated!
"Mommy, where do microprocessors come from?"
Trap
Trap
Since you are converting an Excel spreadsheet you don't need to care about the mathematical meaning of this, you have to find out what exactly Excel does in this case. Iterating till it doesn't change anymore seems likely to me.

OpenOffice Calc by default gives an error message.
Dreq
Dreq
Well one would logically assume that, if two variables are inter-related, a loop will continue endlessly.
"Mommy, where do microprocessors come from?"
CTar
CTar
Well, those values are incorrect. Try substituting.

A = 4
B = A + (C*2)
C = B / 2

B = 4 + (20*2) = 40
C = 40/2 = 20

B = 44 = 40 // Something is wrong
C = 20 = 20

I believe what you have typed is impossible

A=4
B=A+(C*2)
C=B/2

B=4+(B/2*2)
B=4+B // B=4+B something is wrong

smart_idiot
smart_idiot
I stuck it in mathomatic, and it solved it to be 4=0. That's probably not good.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other
Dreq
Dreq
So you guys don't think i'm crazy:

"Mommy, where do microprocessors come from?"
superdeveloper
superdeveloper
My results are:

A5 4
A6 44
A7 20

so I don't know how you got 40 in A6.

[edit]

it results in error for me to put A6/2 into the A7 cell
CTar
CTar
Quote:
Original post by Dreq
So you guys don't think i'm crazy:



Of course Excel outputs a wrong value if you gives it something impossible, try this:

A1 = A2+1
A2 = A1+1

This will also generate some weird result.
necreia
necreia
I am not able to enter the third cell in Excel 2003, it says it would be a circular function.
Dreq
Dreq
The weird thing is that i get the same error in a new workbook, but not in this one..
"Mommy, where do microprocessors come from?"
kSquared
kSquared
You are trying to solve what is called a simultaneous linear equation. Simplistic cell-based spreadsheets cannot do this, because they perform evaluation in a defined order by direct substitution. Because simultaneous equations refer to each other, such spreadsheets (correctly) tell you that there is a circular reference and (incorrectly) tell you that the equation is unsolveable. You'll want to visit this excellent page if you want to use Excel for solving SLEs. Excel also includes an equation solver that you can use as well.

However, in your particular case, Excel is correct in telling you the equation is unsolveable, as there is no real-valued solution to the system of equations you've provided:

1.) a = 4
2.) b = a + 2c
3.) c = b/2

Substitute (1) and (3) into (2) and you get the contradiction that "b = b + 4", clearly impossible. For instance, let b = 1; clearly 1 != 1 + 4.

hope that helps,
- k2 "Choose a job you love, and you'll never have to work a day in your life." — Confucius"Logic will get you from A to B. Imagination will get you everywhere." — Albert Einstein"Money is the most egalitarian force in society. It confers power on whoever holds it." — Roger Starr{General Programming Forum FAQ<
Dreq
Dreq
I have emailed the guy with the question, its his turn :D.. We asked for insurance formulas, they give us spreadsheets with errornous functions.. Another day in paradice for the lowly programmer eh ;) This scary thing is, the output of their excel formulas (cross reference and all) is correct O_o
"Mommy, where do microprocessors come from?"
Dreq
Dreq
Quote:
Original post by kSquared
You are trying to solve what is called a simultaneous linear equation. Simplistic cell-based spreadsheets cannot do this, because they perform evaluation in a defined order by direct substitution.


As I said, the scary part is, it doesn't tell me theres a circular equation on this book, if i start a new excel file, I can't put the same function in.. they may have done something to disable this warning. And the even creepier part is the fact that it 'correctly' calculates the insurance premiums... *Bang head on desk*

"Mommy, where do microprocessors come from?"

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.