Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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]);
}
  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote