Re: NSolve keeps on running forever
- To: mathgroup at smc.vnet.net
- Subject: [mg82729] Re: [mg82681] NSolve keeps on running forever
- From: DrMajorBob <drmajorbob at bigfoot.com>
- Date: Tue, 30 Oct 2007 03:23:01 -0500 (EST)
- References: <18342578.1193602902297.JavaMail.root@m35> <op.t0xemrpkqu6oor@monster.gateway.2wire.net> <2111825.1193666327269.JavaMail.root@m35>
- Reply-to: drmajorbob at bigfoot.com
Something like #.#&[Flatten[matrix1-matrix2]] Bobby On Sun, 28 Oct 2007 20:43:36 -0500, Nabeel Butt <nabeel.butt at gmail.com> wrote: > Hi Bob, > I have some problem and it would really help save my time.Say I > have > a matrix of variables that is 6 by 6.I also have an identity matrix that > is > 6 by 6.I want to create an expression that takes the coressponding > entries > in the matrices subtracts them and then takes their square.I will have 36 > new variables and create an algebraic expression by adding them all. > THanks . > Nabeel > > > > On 10/28/07, DrMajorBob <drmajorbob at bigfoot.com> wrote: >> >> Here's an initial look at the size of your problem: >> >> Cases[{\!\( >> \*UnderoverscriptBox[\(\[Sum]\), \(h = 2\), \(Length[y]\)]\(hca[A, c, h, >> y, \[Beta]0, \[Beta]1, \[Beta]2, \[Beta]3, \[Sigma], \[Gamma]]\)\),(\!\( >> \*UnderoverscriptBox[\(\[Sum]\), \(s = 2\), \(Length[y]\)]\(hca[A, c, s, >> y, \[Beta]0, \[Beta]1, \[Beta]2, \[Beta]3, \[Sigma], \[Gamma]] . >> Transpose[hca[A, c, s, y, \[Beta]0, \[Beta]1, \[Beta]2, \[Beta]3, >> \[Sigma], \[Gamma]]]\)\))},_Symbol,Infinity]; >> %//Length >> %%//Union//Length >> 95139 >> 43 >> >> That's 95,139 mentions of 6 variables and 37 unknown parameters. In >> addition, you've equated matrices... which isn't legal syntax in NSolve, >> AFAIK. (Correct me if I'm wrong.) I'm surprised NSolve even tries. >> >> On top of that, the following: >> >> Sum[hca[A, c, h, y, \[Beta]0, \[Beta]1, \[Beta]2, \[Beta]3, \[Sigma], >> \[Gamma]], {h, 2, Length[y]}] >> >> when evaluated, involves terms such as >> >> 2[{1, 2, 3, 2, 1, 4, 5, 3, 2, >> 1}, 2, \[Beta]0, \[Beta]1, \[Beta]2, \[Beta]3, \[Sigma], \[Gamma]] >> >> 3[{1, 2, 3, 2, 1, 4, 5, 3, 2, >> 1}, 3, \[Beta]0, \[Beta]1, \[Beta]2, \[Beta]3, \[Sigma], \[Gamma]] >> >> and so forth. Probably that's not what you intended, right? >> >> Fix that, change the matrix equations into scalar equations (Thread >> might >> help), and try again. >> >> Bobby >> >> On Sun, 28 Oct 2007 04:03:50 -0500, Nabeel Butt <nabeel.butt at gmail.com> >> wrote: >> >> > Hi Guys, >> > I have a system of equations that I want to solve.It has a >> > solution but NSolve seems to keep on running forever.I am pasting the >> > code >> > over here: >> >> > >> h[y_,t_,\[Beta]0_,\[Beta]1_,\[Beta]2_,\[Beta]3_,\[Sigma]_,\[Gamma]_]:= ={{v[y,t,\[Beta]0,\[Beta]1,\[Beta]2,\[Beta]3,\[Sigma],\[Gamma]]},{(y[[= t-1]])*v[y,t,\[Beta]0,\[Beta]1,\[Beta]2,\[Beta]3,\[Sigma],\[Gamma]]},{((= y[[t-1]])^2)*v[y,t,\[Beta]0,\[Beta]1,\[Beta]2,\[Beta]3,\[Sigma],\[Gamma]= ]},{(((v[y,t,\[Beta]0,\[Beta]1,\[Beta]2,\[Beta]3,\[Sigma],\[Gamma]])^2)-= \[Sigma]^2*((y[[t-1]])^3))},{(((v[y,t,\[Beta]0,\[Beta]1,\[Beta]2,\[Beta]= 3,\[Sigma],\[Gamma]])^2)-\[Sigma]^2*((y[[t-1]])^3))*y[[t-1]]},{(((v[y,t,= \[Beta]0,\[Beta]1,\[Beta]2,\[Beta]3,\[Sigma],\[Gamma]])^2)-\[Sigma]^2*((= y[[t-1]])^3))*((y[[t-1]])^3)}}; >> > >> v[y_,t_,\[Beta]0_,\[Beta]1_,\[Beta]2_,\[Beta]3_,\[Sigma]_,\[Gamma]_]:= =y[[t]]-y[[t-1]]-\[Beta]0-\[Beta]1*y[[t-1]]-\[Beta]2*((y[[t-1]])^2); >> > >> hca[A_,c_,t_,y_,\[Beta]0_,\[Beta]1_,\[Beta]2_,\[Beta]3_,\[Sigma]_,\[G= amma]_]:=( >> > A.h >> > >> [y,t,\[Beta]0,\[Beta]1,\[Beta]2,\[Beta]3,\[Sigma],\[Gamma]])*w[A,c,t,= y,\[Beta]0,\[Beta]1,\[Beta]2,\[Beta]3,\[Sigma],\[Gamma]]; >> > >> w[A_,c_,t_,y_,\[Beta]0_,\[Beta]1_,\[Beta]2_,\[Beta]3_,\[Sigma]_,\[Gam= ma]_]:= >> > Min[1,c/Norm[A.h >> > [y,t,\[Beta]0,\[Beta]1,\[Beta]2,\[Beta]3,\[Sigma],\[Gamma]]]]; >> > *c=5.85; >> > >> A={{a11,a12,a13,a14,a15,a16},{a21,a22,a23,a24,a25,a26},{a31,a32,a33= ,a34,a35,a36},{a41,a42,a43,a44,a45,a46},{a51,a52,a53,a54,a55,a56},{a61,a= 62,a63,a64,a65,a66}}; >> > y={1,2,3,2,1,4,5,3,2,1}; >> > NSolve[{\!\( >> > \*UnderoverscriptBox[\(\[Sum]\), \(h = 2\), \(Length[y]\)]hca[A, = c, h, >> y, >> > \[Beta]0, \[Beta]1, \[Beta]2, \[Beta]3, \[Sigma], >> > \[Gamma]]\)=={{0},{0},{0},{0},{0},{0}}, >> > 1/Length[y]*(\!\( >> > \*UnderoverscriptBox[\(\[Sum]\), \(s = 2\), \(Length[y]\)]hca[A, = c, s, >> y, >> > \[Beta]0, \[Beta]1, \[Beta]2, \[Beta]3, \[Sigma], \[Gamma]] . >> > Transpose[hca[A, c, s, y, \[Beta]0, \[Beta]1, \[Beta]2, \[Beta]3, >> > \[Sigma], >> > >> \[Gamma]]]\))=={{1,0,0,0,0,0},{0,1,0,0,0,0},{0,0,1,0,0,0},{0,0,0,= 1,0,0},{0,0,0,0,1,0},{0,0,0,0,0,1}}},{\[Beta]0,\[Beta]1,\[Beta]2,\[Beta]= 3,\[Sigma],\[Gamma]}] >> > >> > regards, >> > >> > Nabeel* >> >> >> >> -- >> DrMajorBob at bigfoot.com >> > > > -- = DrMajorBob at bigfoot.com