What is the general procedure in solving systems of equations using R (as opposed to manual Gauss-Jordan/Gaussian elimination)?
Must I first determine if the system is determined/under/overdetermined?
If a system is determined, I just use
solve(t(a)%*%a)%*%t(a)%*%b
to get $x$
in $Ax = b$
If it overdetermined or underdetermined, I am not quite sure what to do. I think the above sometimes gives an answer depending on the rank, but the solution is not always unique. How can I get all the solutions? I think if there's no solution, will R just give an error?
Context: I am planning to recommend to my Stochastic Calculus professor that we use R in our upcoming exam (as opposed to tedious calculators/by-hand computation) so I have a feeling only simple functions will do (e.g. solve) for over/underdetermined systems rather than lengthy programs/functions.
Edit: I tried using solve(a,b)
, but I think that still doesn't give me all the solutions.
Here is an underdetermined example (R cannot give an answer since a is not square):
a=matrix(c(1,1,1,3,2,1),byrow=T,nrow=2)
a
b=matrix(c(1,2),byrow=T,nrow=2)
b
solve(a,b)