Jump to content

QR decomposition: Difference between revisions

No edit summary
Line 1,074:
 
=={{header|Rascal}}==
[[File:qrresultQrresult.jpeg||200px|thumb|right]]
This function applies the Gram Schmidt algorithm. Q is printed in the console, R can be printed or visualized.
 
Line 1,118:
public rel[real, real, real] matrixTranspose(rel[real x, real y, real v] matrix){
return {<y, x, v> | <x, y, v> <- matrix};
}
 
//a function to normalize an element of a matrix by the normalization of a column
Line 1,124:
normalized = 1.0/nroot((0.0 | it + v*v | <x,y,v> <- column), 2);
return matrixMultiplybyN(element, normalized);
}
 
//a function that takes the dot product, see also Rosetta Code problem "Dot product"
public real matrixDotproduct(rel[real x, real y, real v] column1, rel[real x, real y, real v] column2){
return (0.0 | it + v1*v2 | <x1,y1,v1> <- column1, <x2,y2,v2> <- column2, y1==y2);
}
 
//a function to subtract two columns
public rel[real,real,real] matrixSubtract(rel[real x, real y, real v] column1, rel[real x, real y, real v] column2){
return {<x1,y1,v1-v2> | <x1,y1,v1> <- column1, <x2,y2,v2> <- column2, y1==y2};
}
 
//a function to multiply a column by a number
public rel[real,real,real] matrixMultiplybyN(rel[real x, real y, real v] column, real n){
return {<x,y,v*n> | <x,y,v> <- column};
}
 
//a function to perform matrix multiplication, see also Rosetta Code problem "Matrix multiplication".
Line 1,162:
points = [box(text("<v>"), align(0.3333*(x+1),0.3333*(y+1)),shrink(0.25)) | <x,y,v> <- matrix];
render(overlay([*points], aspectRatio(1.0)));
}
 
//a matrix, given by a relation of <x-coordinate, y-coordinate, value>.
Line 1,187:
}
See R in picture</pre>
 
 
=={{header|Tcl}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.