Quantcast

a question about equation solution

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

a question about equation solution

dai_yunhao
This post has NOT been accepted by the mailing list yet.
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 ?

Loading...