Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
"Abhimanyu Arora" <abhimanyu.arora@student.kuleuven.be> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: RE: RE: query regarding mata |

Date |
Sun, 11 Apr 2010 20:10:59 +0200 |

Thanks for your reply Yes, indeed. Here is the code, when I tried to use the do-while command. But, the problem with this is that it gives,"error 3201, vector required" which is surprising. Kind regards Abhimanyu mata numeric vector fpt(real scalar x,real scalar y) { lastv=J(1,5,0) do{ v[1,1]=0.5775+ln(exp(x+0.9*lastv[2])+exp(y+0.9*lastv[1])) v[1,2]=0.5775+ln(exp(2*x+0.9*lastv[3])+exp(y+0.9*lastv[1])) v[1,3]=0.5775+ln(exp(3*x+0.9*lastv[4])+exp(y+0.9*lastv[1])) v[1,4]=0.5775+ln(exp(4*x+0.9*lastv[5])+exp(y+0.9*lastv[1])) v[1,5]=0.5775+ln(exp(5*x+0.9*lastv[5])+exp(y+0.9*lastv[1])) lastv=v }while (mreldif(v,lastv)<10^(-6)) return(v) } fpt(2,3) end -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox Sent: zondag 11 april 2010 19:59 To: statalist@hsphsun2.harvard.edu Subject: st: RE: query regarding mata This doesn't look complete. -mreldif(,)- will surely complain if -lastv- is not defined when it is called. Is there more code upstream of this? Conversely, my guess is that -lastv- has been defined previously, but is of different dimensions: hence the conformability message. You might try some initialisation of -lastv- to 1,1,1,1,1 before entering the loop. Nick n.j.cox@durham.ac.uk Abhimanyu Arora I am trying to use mata to find the fixed point of a contraction mapping. Basically I have 5 non-linear equations in 5 variables (all explicitly expressed in terms of the others). Since I wasn't successful with 'optimize', I tried to use the following idea-start with a vector of zeros and put the elements of vector of unknowns into the RHS of the equations till convergence is achieved (updated value 'almost equal' to previous one). Following is my code and output: clear mata . mata ------------------------------------------------- mata (type end to exit) ------------------------------------------------------------------------ ---- -------------------------- : : real vector fpt(real scalar x,real scalar y) \\x and y are the parameters of the equations > { > v=0,0,0,0,0 > > while (mreldif(v,lastv)<10^(-6)) { > > > lastv=v > > v[1,1]=0.5775+ln(exp(x+0.9*v[1,2])+exp(y+0.9*v[1,1])) > v[1,2]=0.5775+ln(exp(2*x+0.9*v[1,3])+exp(y+0.9*v[1,1])) > v[1,3]=0.5775+ln(exp(3*x+0.9*v[1,4])+exp(y+0.9*v[1,1])) > v[1,4]=0.5775+ln(exp(4*x+0.9*v[1,5])+exp(y+0.9*v[1,1])) > v[1,5]=0.5775+ln(exp(5*x+0.9*v[1,5])+exp(y+0.9*v[1,1])) > > > } > return(lastv) > } note: variable lastv may be used before set : : : fpt(2,3) mreldif(): 3200 conformability error fpt(): - function returned error <istmt>: - function returned error r(3200); : : : end ------------------------------------------------------------------------ ---- ------------------------------------------------------------------------ ---- ------------------------ The error code indicates that there is some operation that is not compatible with the matrices involved. It would be nice if you could point out the mistake. * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/ * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**Follow-Ups**:**st: RE: RE: RE: query regarding mata***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

**References**:**st: query regarding mata***From:*"Abhimanyu Arora" <abhimanyu.arora@student.kuleuven.be>

**st: RE: query regarding mata***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

- Prev by Date:
**st: RE: RE: RE: query regarding mata** - Next by Date:
**st: RE: RE: RE: RE: query regarding mata** - Previous by thread:
**st: RE: query regarding mata** - Next by thread:
**st: RE: RE: RE: query regarding mata** - Index(es):