hello i need base code (triu) for gauss elimination

1 次查看(过去 30 天)
I write body code and i have problem with code..i need good code for triu..i havent use triu code..
  3 个评论
masoud mansouri
masoud mansouri 2015-11-28
well..i wrote this but i don't like use code triu to solve matrix ...i solve gausse elimination only with loop.(my teacher said don't use triu(x) you can write only for e.g A(a11.a12)..it's my project so thanks for saw my problem ...if you skill Matlab please send me email(<mailto:masoudmansouri8@gmail.com masoudmansouri8@gmail.com>) thanks
masoud mansouri
masoud mansouri 2015-11-28
编辑:Geoff Hayes 2015-11-29
clear all
clc
c = input ('please enter matrix :'); %matris elim zarib
disp(c);
b=input('please enter matrix :'); %ansewr matrix
disp(b);
b = b'
A = [c b]
...????? if you run this code after last sentence you can write triu but i don't like used them

请先登录,再进行评论。

采纳的回答

Geoff Hayes
Geoff Hayes 2015-11-29
masoud - triu returns the upper triangular part of a matrix so it is should be straightforward on how to implement this function. If X is your input matrix, then the output matrix U has to be the same size as X, so
U = zeros(size(X));
Now if you are only concerned with those elements above and including the main diagonal, then you need to copy these elements from X into U. But which ones are they? Look at the diagram drawn in the description for triu. If we start with the first row, then we copy all column elements i.e. those elements from columns 1,2,3,...,*m* where m is the number of columns. When we move to the second row, we copy all those element from the second column onwards. So what is the pattern?
for r=1:size(X,1)
for c=???:size(X,2)
% do the copy from X to U
end
end
Since this is homework, I will leave it to you to determine the pattern and what c should begin iterating over.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by