"Null" in a for loop

1 visualización (últimos 30 días)
harry wang
harry wang el 1 de Nov. de 2011
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?

Respuestas (3)

Walter Roberson
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.

harry wang
harry wang el 1 de Nov. de 2011
Hi Walter, Thanks for your replay. The sample code here is actually a simplified version, the original code is more complicated. In the original code, the determinant of matrix A is dependent on HH and its roots are also dependent on HH. So in the original program, i some time get one vector for null(WW), sometime i got two vectors from null(WW). You mentioned that null only gives a single solution, are there any way to obtain this single solution in each "for" loop?
Harry

harry wang
harry wang el 1 de Nov. de 2011
To describe this problem more clearly, The following is cut and paste from the real runing program: When the root of the determinant is equal to 0.527785592374495 + 0.118279569892473i, null(WW)=
0.000000000000000 0.000000000043649
-0.776234180889516 - 0.630444681489806i -0.000000000002771 + 0.000000000000302i
0 - 0.000000000000000i -0.000000000028390 - 0.000000000082173i
-0.000000000002374 + 0.000000000001462i 0.226282459254081 - 0.974061727322209i
When the root of the determinant is slightly changed to 0.524178053258712 + 0.118279569892475i, null(WW)=
-0.000000000043399
-0.000000000001090 + 0.000000000000128i
0.000000000028560 + 0.000000000082160i
-0.220919301866939 + 0.975292090638812i
So are there any way to get a more consistant single solution ? because the roots changed gradually in each for loop, I require the solution of null (WW) also changed gradually. a abrupt change of the solution from null(WW) will result in a void calculation.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by