Bookmark and Share

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]

st: a question about equation solution


From   dai_yunhao <[email protected]>
To   [email protected]
Subject   st: a question about equation solution
Date   Tue, 30 Aug 2011 09:10:42 -0700 (PDT)

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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index