View Single Post
  #11   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Dana DeLouis Dana DeLouis is offline
external usenet poster
 
Posts: 947
Default How do I calculate simultaneous equations?

The Newton Method can sometimes be useful, and done in only a very few
loops.
It would be easy to adapt to a more general equation.
I might put the circle equation into its other form:

'49*x^2 - 280*x + 36*y^2 + 120*y + 300 = 0

Sub TestIt()
'// Enter two guesses for x & y
Debug.Print LineCircle(1, 1)
Debug.Print LineCircle(2, -3)
End Sub

Returns the two solutions:

X: 0.8571428571428571428571428571 Y: -1.3333333333333333333333333333
X: 1.4285714285714285714285714286 Y: -3.3333333333333333333333333333



Function LineCircle(gx, gy) As Variant
Dim a, b, c, d, x, y, v1, v2
Dim J As Long

'// Jacobian of Line
a = CDec(21): b = CDec(6)
x = gx: y = gy

For J = 1 To 10
v1 = 10 - 21 * x - 6 * y
v2 = -49 * x * x + 280 * x - 36 * y * y - 120 * y - 300
c = 98 * x - 280
d = 24 * (5 + 3 * y)

x = x + (d * v1 - b * v2) / (a * d - b * c)
y = y + (c * v1 - a * v2) / (b * c - a * d)
Next J
LineCircle = "X: " & CStr(x) & " Y: " & CStr(y)
End Function

--
Dana DeLouis
Excel 2007



"Niek Otten" wrote in message
...
<Goal Seek seems to permit far less user control

I don't think so. Goal Seek takes its parameters from the Iteration
dialog: the max number of "iterations" and the maximum change,
which can be set to what Harlan called "machine precision".

Not that I want to restart the discussion about how desirable such a
solution is, just to indicate that accuracy should not be an
issue.

--
Kind regards,

Niek Otten
Microsoft MVP - Excel


"Jerry W. Lewis" wrote in message
...
| Solver's default settings greatly limit its accuracy, but I can usually
tweak
| it to get what I want. Goal Seek seems to permit far less user control.
| However, I suspect that most algorithms would perform poorly when asked
to
| numerically solve an n-dimensional problem that analytically reduces to
an
| n-k (k0) dimensional problem. Do the analytical reduction as Harlan
| suggested, then apply appropriate methods to the problem that remains.
|
| If the algebra is tedious, download Maxima
| http://maxima.sourceforge.net
| which is a free symbolic math program. In Maxima,
| solve ([21*x+ 6*y = 10, (7*x-20)^2+(6*y+10)^2=200], [x,y]);
| returns the two solutions to the reduced quadratic equation
| [x=10/7,y=-10/3],[x=6/7,y=-4/3]
| With more complicated equations, you might get a reduction that actually
| requires a numerical solution, but with a clear picture of the actual
| dimensionality of the problem, Solver will perform much better.
|
| Jerry
|
| "David A. Heiser" wrote:
|
| Using Solver to solve these equation sets is a disaster. You cannot
rely on
| the accuracy of the results, which generally are only accurate to 2-3
| decimal digits. Most of the time it is not accurate to any decimal
digit.
| The algorithm is faulty.
|
| David Heiser