I need to convert this MATLAB function into C. MATLAB Code function [ Q, R ] = m
ID: 3803216 • Letter: I
Question
I need to convert this MATLAB function into C.
MATLAB Code
function [ Q, R ] = myqr(A); % QR factorization by the Gram-Schmidt Algorithm
Q= zeros(size of(A));
R=zeros(size(A));
n= length(A);
for i = 1:1:n
Q(:,i)=A(:,i);
for j = 1:1:i-1
R(j,i) = Q(:,j)' * A(:,i);
Q(:,i) = Q(:,i) - R(j,i) * Q(:,j);
end
R(i,i) = norm(Q(:,i));
Q(:,i) = Q(:,i) / R(i,i);
end
C Code that I have
void qr_decomp( int n, double **A, double **Q, double **R)
int i, j, k:
for (i=0, i<n, i++) {
For the transpose in Matlab, what do i use in C? If you could translate the Matlab code to C that'd be awesome!
Explanation / Answer
for matrix transpose in c
printf("The given matrix is ");
for (i = 0; i < m; ++i)
{
for (j = 0; j < n; ++j)
{
printf(" %d", array[i][j]);
}
}
printf("Transpose of matrix is ");
for (j = 0; j < n; ++j)
{
for (i = 0; i < m; ++i)
{
printf(" %d", array[i][j]);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.