1
votes

I'm trying to get a function that calculates schmidt decomposition of bipartite states (tensor of two density matrices) to print a sum of the schmidt number (X) and the basis vectors (e_i, e_j) side by side for each iteration of the for loop. ex:(x'*'e_1'\otimes' e_1+ ... + x'*'e_i'\otimes' e_j). The commented out fprintf statements are things i've already tried.

Code:

function [u, v] = Schmidt(m,n,v)

    m = 3 %size of basis vector
    n = 4 %size of basis vector
    e_m = eye(m)
    e_n = eye(n)
    %can have a = input('enter an array>');
    v = [1
         2
         3
         4
         5
         6
         7
         8
         9
         10
         11
         12]

    for i = 1:m

        for j = 1:n
            e_i = e_m(:,i)
            e_j = e_n(:,j)
            K = kron(e_i, e_j)
            x = ctranspose(K)*v
            W(i,j) = x
            %fprintf('%d %f %f %f\n',j,e_i,e_j,x);
            %fprintf(1,'Header 1\tHeader 2\n');
            %fprintf(1,'%f\t%f\n','e_i e_j');
            %fprintf('the basis are %d\n',e_i, e_j)

        end
    end
end
2
so you want how many numbers side by side on each iteration and what are their variable names? - jerad
If you're trying to put all the numbers on the same row you can use disp([ a b c d ]) - jerad

2 Answers

0
votes

Typing "doc fprintf" will bring up the help file and it can show you the proper way to format. If you are just trying to align the outputs you may need to specify the precision using

 fprint('%3.4f',e_i)
0
votes

You can try this:

    .
    .
    .
    x = ctranspose(K)*v;

    NEW(1:numel(j(:,1)), 1) = j;
    NEW(1:numel(e_i(:,1)), 2) = e_i;
    NEW(1:numel(e_j(:,1)), 3) = e_j;
    NEW(1:numel(x(:,1)), 4) = x;

    sprintf('%f %f %f %f \n',NEW(:,1), NEW(:,2), NEW(3,:), NEW(4,:))