From: Marios Karaoulis on 21 May 2010 10:50 Hi, I have this problem i want to solve the system Ax=b, multiple times likes this A matrix is always the same. b changes in every iteration. for i=1:large_number x(:,i)=A\b(:,i) end Wouldn't be faster is I calculate the inverse of A matrix once, and then use it like this for i=1:large_number if i==1 ;A=inv(A); end; x(:,i)=A*b(:,i) end 2) Is inv(A) the best way to fast calculate the inverse of A: Thanks
From: James Tursa on 21 May 2010 11:37 Marios Karaoulis <marios.karaoulis(a)gmail.com> wrote in message <66d57be3-4ecb-4f9f-8be7-face3bd886d4(a)34g2000prs.googlegroups.com>... > > i want to solve the system Ax=b, multiple times likes this > A matrix is always the same. > b changes in every iteration. > > for i=1:large_number > x(:,i)=A\b(:,i) > end > > Wouldn't be faster is I calculate the inverse of A matrix once, and > then use it like this > > for i=1:large_number > if i==1 ;A=inv(A); end; > x(:,i)=A*b(:,i) > end > > 2) Is inv(A) the best way to fast calculate the inverse of A: Yes, inv(A) is the best way to fast calculate the inverse of A, *BUT* this is *NOT* the way to solve your problem. If you have all of your b values ahead of time, then use backslash on the whole thing. If you are getting the b values iteratively and need the solution iteratively, then what you should do instead is factor A once (not invert it) and then use that factorization multiple times to solve for x. e.g., see this excellent submission on the FEX by Tim Davis: http://www.mathworks.com/matlabcentral/fileexchange/24119-dont-let-that-inv-go-past-your-eyes-to-solve-that-system-factorize James Tursa
From: Marios Karaoulis on 21 May 2010 14:30 Ok. Thanks. This is what I did, for i=1:large_number if i==1 ;[L,U]=lu(A); end; x(:,i)=U\(L\b(:,i); end and it is superfast!!!
From: Bruno Luong on 21 May 2010 14:48 Marios Karaoulis <marios.karaoulis(a)gmail.com> wrote in message <66d57be3-4ecb-4f9f-8be7-face3bd886d4(a)34g2000prs.googlegroups.com>... > Hi, > I have this problem > > i want to solve the system Ax=b, multiple times likes this > A matrix is always the same. > b changes in every iteration. > > > for i=1:large_number > > x(:,i)=A\b(:,i) > > > end Or simply x = A\b; Bruno
From: James Tursa on 21 May 2010 16:42 "Bruno Luong" <b.luong(a)fogale.findmycountry> wrote in message <ht6kh5$gfu$1(a)fred.mathworks.com>... > Marios Karaoulis <marios.karaoulis(a)gmail.com> wrote in message <66d57be3-4ecb-4f9f-8be7-face3bd886d4(a)34g2000prs.googlegroups.com>... > > > > i want to solve the system Ax=b, multiple times likes this > > A matrix is always the same. > > b changes in every iteration. > > > > for i=1:large_number > > x(:,i)=A\b(:,i) > > end > > Or simply > > x = A\b; Yes. Per my first post, it is unclear to me whether OP needs the solutions iteratively or not. James Tursa
|
Next
|
Last
Pages: 1 2 Prev: PWM block in Target Support Package TC2 Next: Two way flow through pipe |