From: Marios Karaoulis on
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
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
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
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
"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