output from function

  • Follow


I wrote the following matlab code :


function [w]   = SOR( A, b, x)
%UNTITLED Summary of this function goes here
%   Detailed explanation goes here
error=1; 

while error <= 10^-8;
   
      w(1,1)=x(1,1)+1.6399/A(1,1)*(b(1,1)-A(1,1)*x(1,1)-A(1,2)*x(1,2)-A(1,3)*x(1,3));
      
for i=2:8;
    w(1,i)=x(1,i)+1.6399/A(i,i)*(b(1,i)-A(i,i-1)*w(1,i-1)-A(i,i)*x(1,i)-A(i,i+1)*x(1,i+1));
end

   w(1,9)=x(1,9)+1.6399/A(9,9)*(b(1,9)-A(9,8)*w(1,8)-A(9,9)*x(1,9));
                
        z(1,i)=w(1,i)-x(1,i);
        
        for j=1:9;
            sum3=sum3+z(1,j)*z(1,j);
        end
        
        for j=1:9;
            sum4=sum4+w(1,j)*w(1,j);
        end
        
        norma1=sqrt(sum3);
        norma2=sqrt(sum4);
        error=norma1/norma2;
        
        for i=1:9;
        x(1,i)=w(1,i);
        end
end 
end


When I ran the code I received no output...what's wrong??

Thanks
0
Reply lauren.samama (1) 12/3/2009 3:10:30 AM

Well, your output argument w is never assigned because the while loop
is never entered.  You set error = 1 which is greater than 1e-8 so the
while loop never executes.

And I think you may have 1 too many ends.  Try ending your function
with return instead of end - but actually you don't need either.
0
Reply ImageAnalyst 12/3/2009 1:35:56 AM


1 Replies
295 Views

(page loaded in 0.035 seconds)

Similiar Articles:













7/24/2012 1:58:16 PM


Reply: