Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

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

From |
Matthew Baker <matthew.baker@hunter.cuny.edu> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: a question about equation solution |

Date |
Tue, 30 Aug 2011 21:30:21 -0400 |

The mystery is resolved by observing that you are in fact getting the requested answers...given that you have restricted the search interval to the (0,1) range. If I understand it correctly, the first argument of mm_root is to contain a scalar to be replaced with the answer, the second the function you are finding a root for, and here is the key - the third and fourth arguments are the lower and upper search limits. So, if you change, the line of code: r=mm_root(x=.,&y(),0,1,1e-9,1000,v[i,2],v[i,3],v[i,4]) To r=mm_root(x=.,&y(),-10,10,1e-9,1000,v[i,2],v[i,3],v[i,4]) (The only change is in the third and fourth arguments) You should get the sought-after answer. Hope that helps! Matt Baker -- Dr. Matthew J. Baker Department of Economics Hunter College and the Graduate Center, CUNY On Tue, Aug 30, 2011 at 12:10 PM, dai_yunhao <dai_yunhao@smail.hust.edu.cn> wrote: > Hi, everybody, > > I don't know whether the mata program could solve the equation, and I run a > program like this: > > clear all > set obs 10 > g a=1 > g b=2 > g c=_n > g x=. > order x a b c > mata > v=J(1,1,.) > st_view(v,., "x a b c") > function y(x,a,b,c) { > return (-c+a+b+x) > } > for (i=1;i<=rows(v);i++) { > r=mm_root(x=.,&y(),0,1,1e-9,1000,v[i,2],v[i,3],v[i,4]) > v[i,1]=x > } > end > l,noo > gen d=c-a-b > > and the result is: > > +---------------------+ > | x a b c d | > |---------------------| > 1. | 0 1 2 1 -2 | > 2. | 0 1 2 2 -1 | > 3. | 0 1 2 3 0 | > 4. | 1 1 2 4 1 | > 5. | 1 1 2 5 2 | > |---------------------| > 6. | 1 1 2 6 3 | > 7. | 1 1 2 7 4 | > 8. | 1 1 2 8 5 | > 9. | 1 1 2 9 6 | > 10. | 1 1 2 10 7 | > +---------------------+ > > Shouldn't the x be the solution of the equation x+a+b=c ,and the value of x > equal to the value of d ? > > > > -- > View this message in context: http://statalist.1588530.n2.nabble.com/a-question-about-equation-solution-tp6742764p6742764.html > Sent from the Statalist mailing list archive at Nabble.com. > * > * 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/

**References**:**st: a question about equation solution***From:*dai_yunhao <dai_yunhao@smail.hust.edu.cn>

- Prev by Date:
**st: supply known-variance matrix for xtmixed?** - Next by Date:
**st: generating a variable with pre-specified correlations with other two (given) variables** - Previous by thread:
**st: a question about equation solution** - Next by thread:
**st: Margins after xtprobit, re.** - Index(es):