"Null" in a for loop
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I need to use null to obtain a solution of a homogenious linear equation, and i have to put null in a for loop , the program is as followings
syms x
for HH=1:100
A=[x-1 x*HH;
3*x x^3*HH]
FF=sym2poly(vpa(det(A)))
S=roots(FF);
WW=subs(A,x,S(4))
JJ(:,HH)=null(WW);
end
The problem is that i found out that null(WW) some time give me one solution, some time give me two solutions, are there any way to force it to give me one solution in each for loop?
0 comentarios
Respuestas (3)
Walter Roberson
el 1 de Nov. de 2011
null() always returns the same number of solutions, namely one. The single solution is the list of vectors that span the null space of the given space. The number of vectors required to span the null space can vary, but each of them is part of the single solution, and it is meaningless to try to force the null space to only have a particular number of vectors.
Note: my computation is that the roots of FF are independent of HH -- that HH acts as a common multiple. The determinant of A is
x^4*HH - x^3*HH - 3*x^2*HH
which is
HH * x^2 * (x^2 - x - 3)
and the roots of that are going to be 0, 0, and 1/2 +/- sqrt(13)/2
What happens after that depends on which of the four roots you happen to get in the 4th position. The documentation for roots() indicates that it uses eig() on a companion matrix, but the order that eig() produces its values in has never been documented and is known to vary between versions; roots() does not impose any further sorting order on the roots.
If one of the 0's happens to end up in the 4th position of the roots() output then the subs() reduces A to [-1 0;0 0] which has the null space [0;1]
If the root 1/2 + sqrt(13)/2 happens to be the one chosen, then the null space will come out as [-(1+sqrt(13))*HH/(-1+sqrt(13); 1] and if the root 1/2 - sqrt(13)/2 happens to be the one chosen, then the null space will come out as [-(1+sqrt(13))*HH/(+1+sqrt(13); 1]
Overall, once you have worked through the math, the only point in going through the loop over HH would be to act as a random number selector over which of these three possibilities would be chosen.
0 comentarios
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!