Solved

Matlab loop help

Posted on 2008-10-22
1
1,307 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
either24  challenge 19 105
Line meaning 9 91
Python - ImportError: No module named 'urllib2' 2 422
Problem to event 3 114
Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This video teaches viewers about errors in exception handling.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

726 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