Solved

Matlab loop help

Posted on 2008-10-22
1
1,304 Views
Last Modified: 2016-02-10
Hey

i dont really understand whats happening in this example code i have. i dont understand matlabs implicit algebra. If you look at the attatched code can you please tell me how to write the bottom part of it with just "for loops" instead of the built in matlab algebra so i can better understand whats happening.

how do i write the:

  x(i) = ( b(i) - A(i,i+1:n)*x(i+1:n) ) / A(i,i);

line of the loop:

for i = n-1:-1:1
  x(i) = ( b(i) - A(i,i+1:n)*x(i+1:n) ) / A(i,i);
end  


as a series of nested loops. when i it like this i think i'll be able to understand whats happening more easily and then hopefully i'll be able to play with the function!

thanks
function x = UpperTriangularSolve(A,b,n)
 
% function x = UpperTriangularSolve(A,b,n)
%
% Solve the system  A x = b  where A is assumed to be upper triangular,
% i.e. A(i,j) = 0 for j < i, and the diagonal is assumed to be nonzero,
% i.e. A(i,i) \= 0.
%
% ARGUMENTS:  A   upper triangular n x n matrix
%             b   right hand side column n-vector
%             n   integer matrix dimension
%
% RETURNS:    x   column n-vector solution
 
  x = zeros(n,1);
  x(n) = b(n)/A(n,n);
 
for i = n-1:-1:1
  x(i) = ( b(i) - A(i,i+1:n)*x(i+1:n) ) / A(i,i);
end

Open in new window

0
Comment
Question by:Ashwee
1 Comment
 

Accepted Solution

by:
Ashwee earned 0 total points
ID: 22776012
erm i kind of worked it out :P

for i = n-1:-1:1
  f = 0;
  x(i) = b(i);
  
  for m = i+1:n
    m;
    f = f + A(i,m)*x(m);
  end
 
  x(i) = x(i) - f;
  x(i) = x(i) / A(i,i);
end

Open in new window

0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
why to use string 10 60
Which programming language is best for beginning Object-oriented programming 11 142
How To Loop - Python 19 87
What language/protocol is the Angular Chat? 2 76
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question