Re: [問題] How to solve Ax=b that A is not inve …

作者: yabt (痴心絕對)   2006-04-16 12:27:37
※ 引述《brooky (未夠班)》之銘言:
: ※ 引述《Yyh (我愛批踢踢)》之銘言:
: : Thank you! I have solved it :p
: d_minus[d_minus > 1e-07] <- 1/d_minus[d_minus > 1e-07];
: d_minus[d_minus <= 1e-07] <- 0;
: x_minus <- v %*% diag(d_minus) %*% t(u);
: coef <- x_minus %*% y;
I have used "lm" to do the same job as yours, and the coefficients are
identical to those from SVD.
I suppose that your "d_minus" is the "d" component in the ouput of SVD,
and there might be some problem in your code.
If there is a element with value > 1e+07, it will be replaced with 1/value,
which is less than 1e-07, and it will be furthur replaced by 0 at the second
instruction.
Maybe you should create a temp array to store the result, such as:
temp <- numeric()
temp[d_minus > 1e-07] <- 1/d_minus[d_minus > 1e-07]
temp[d_minus <= 1e-07] <- 0

Links booklink

Contact Us: admin [ a t ] ucptt.com