RE: 2 dimension Newton Raphson
- To: mathgroup at smc.vnet.net
- Subject: [mg71245] RE: [mg71218] 2 dimension Newton Raphson
- From: "David Park" <djmp at earthlink.net>
- Date: Sat, 11 Nov 2006 03:39:17 -0500 (EST)
This is a pretty simple problem. In the first place the equations can be directly solved. eqns = {(x - 4)^2 + (y - 4)^2 == 5, x^2 + y^2 == 16}; Solve[eqns] {{x -> (1/16)*(43 - Sqrt[199]), y -> (1/16)*(43 + Sqrt[199])}, {x -> (1/16)*(43 + Sqrt[199]), y -> (1/16)*(43 - Sqrt[199])}} You could also turn it into a 1-dimensional root search. I use Ted Ersek's RootSearch package from MathSource because it is quite convenient here. We parametrize the circle in terms of t and then travel around it looking for roots of the first equation. Needs["Ersek`RootSearch`"] f[t_] = Simplify[(x - 4)^2 + (y - 4)^2 - 5 /. {x -> 4*Cos[t], y -> 4*Sin[t]}] 43 - 32 Cos[t] - 32 Sin[t] Plot[f[t], {t, 0, 2Pi}]; tsols = RootSearch[f[t] == 0, {t, 0, 2Pi}] xysols = {x -> 4Cos[t], y -> 4Sin[t]} /. tsols {{t -> 0.468398}, {t -> 1.1024}} {{x -> 3.56917, y -> 1.80583}, {x -> 1.80583, y -> 3.56917}} eqns /. xysols {{True, True}, {True, True}} David Park djmp at earthlink.net http://home.earthlink.net/~djmp/ From: ms z [mailto:ms-z- at hotmail.com] To: mathgroup at smc.vnet.net I have tried to solve the roots of the simultaneous nonlinear equations (x-4)^2 + (y-4)^2 = 5 x^2 + y^2 = 16 by writing this function: nr2method[xl1_, xl2_, es1_] := Block[{x1, x2, ea, es, x1new, u, v}, u = (x1 - 4)^2 + (x2 - 4)^2 - 5; v = x1^2 + x2^2 - 16; ea = 100; es = es1; For[i = 1, ea > es, i++, (x1new[x1_, x2_] = x1 - (u*D[ v, x2] - v*D[u, x2])/(D[u, x1]*D[v, x2] - D[u, x2]*D[v, x1]); If[i == 1, x1 = xl1, x1 = b]; x2 = xl2; b = x1new[x1, x2]; ea = Abs[(b - x1)/b 100]; Clear[x1, x2, x1new];)]; ea = 100; es = es1; For[i = 1, ea > es, i++, (x2new[x1_, x2_] = x2 - (v*D[u, x1] - u*D[v, x1])/(D[u, x1]*D[v, x2] - D[u, x2]*D[v, x1]); If[i == 1, x2 = xl2, x2 = c]; x1 = xl1; c = x2new[x1, x2]; ea = Abs[(c - x2)/c 100]; Clear[x1, x2, x2new];)]; Print["The value of x1 is ", b]; Print["The value of x2 is ", c];] Is this function a good one? Is there a way to make this function simpler? _________________________________________________________________ Get MSN Messenger emoticons and display pictures here! http://ilovemessenger.msn.com/?mkt=en-sg