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