MATLAB: Solving a over determined system in MATLAB

MATLAB

I have 4 equations and 3 variables. I know that 3 equations are sufficient but my instructor said that the equations make a overdetermined system. My equations are:
e1=(x*(a-principle_stress(1,1)))+(p*y)+(r*z);
e2=(y*(b-principle_stress(1,1)))+(p*x)+(q*z);
e3=(r*x)+(q*y)+(z*(c-principle_stress(1,1)));
eqn4 = (x^2) + (y^2) + (z^2) == 1;
What I did earlier was
eqns=[e1,e2,eqn4];
S = solve(eqns,[x y z]);
The above method matched with the actual answer but is it the correct way of solving a overdetermined system?
Will using
eqns=[e1,e2,e3,eqn4]
solve my problem?

Best Answer

Is it the correct way? perhaps it might be, except that you have a typo in e3. Perhaps that is why you decided to try it with only 3 equations. Look carefully at e3. Does it contain y at all? (NO.) TYPO.
It looks like you are trying to solve an eigenvector problem, thus you have an eigenvalue of a 3x3 stress matrix, well, you call it a principle stress. It is still one of three eigenvalues of that 3x3 matrix.
How should you solve the problem? Best is just to use eig, which will give you both the desired stresses and the eigenvectors directly. Trying to use solve at all here is a bad idea, because it forces you to face a numerical problem.
If you already know the value of the principle stress, then you can use null to give the desired vector directly.
Of course, since this is homework, I assume you are not allowed to use either null or eig anyway.
Sigh.