"Arrad Dianarkop" <adianarko@gmail.com> wrote in message <i6ts0a$54v$1@fred.mathworks.com>...
> Hi, I'm newbie here, so please bear with me.
>
> I wonder if anyone can tell me what's wrong with this inverse matrix program
> Here's the program:
>
> function [Ainv]=INVMAT(A)
> [n,n]=size(A);
> I=zeros(n,n);
> for i=1:n;
> I(i,i)=1;
> end
> m(1:n,1:n)=A;
> m(1:n,n+1:2*n)=I;
> for i=1:n;
> m(i,1:2*n)=m(i,1:2*n)/m(i,i);
> for k=1:n;
> if i~=k
> m(k,1:2*n)=m(k,1:2*n)m(k,1)*m(i,1:2*n);
> end;
> end;
> end
> invrs=m(1:n,n+1:2*n);
>
> A= [2 1 0 0; 1 2 1 0; 0 1 2 1; 0 0 1 2]
>
> When I run:
>
> >>Ainv = INVMAT(A)
>
> it gives:
>
> Error in ==> INVMAT at 2
> [n,n]=size(A);
>
> ??? Output argument "Ainv" (and maybe others) not assigned during call to
> "D:\Program
> Files\%location of the program in file%"
% The function is supposed to return a variable called Ainv:
function [Ainv]=INVMAT(A)
% but you didn't assign a value to Ainv anywhere in the function.
% Try changing:
invrs=m(1:n,n+1:2*n);
% to
Ainv=m(1:n,n+1:2*n);
% OR change:
function [Ainv]=INVMAT(A)
% to
function [invrs]=INVMAT(A)
>
> I did not create this program. I'm learning from it tho, also, can someone tell me what '~' in i~k means?
% if i~=k means "if i is not equal to k then" ...
>
> Thank you.
>
> Rad
