Contents

%mat_transform3.m
%
%Transforms a general rank 3 tensor (symmetric in its last two indices)
%according to a chosen transformation matrix.
%Generating matrices can be loaded by entering their number.
%General, already created group elements can be loaded by entering their
%file name (no file extension necessary). The tensor will be tranformed and
%a system of 6 equations will be created via the invariance condition
%(h_ijk = g_ijk, with h_ijk the transformed tensor). The transformed tensor as
%well as the resulting independent elements will be shown at the end,
%mapped to the corresponding matrix representation for symmetric rank 3
%tensors
%
%input:  nam ... name or # of tranforming matrix
%
%output: hs  ... transformed rank 2 tensor
%        hi  ... resulting tensor with independent elements
%
%Valentin Zauner
%
%05.2008

close all;
clear all;
clc;

rep = 1;
while rep

    g = sym(zeros(3,3,3));
    h = sym(zeros(3,3,3));

generate general rank 3 tensor

    mask = [1,6,5;6,2,4;5,4,3];
    for l=1:3
        for m=1:3;
            for n=1:3
                g(l,m,n) = sym(['g',num2str(l),num2str(mask(m,n))]);
            end;
        end;
    end;

load transforming matrix

    nam = input('Transforming matrix: ','s');
    if isempty(nam)
        M = eye(3);
    elseif ~isempty(str2num(nam));
        t = struct2cell(load(['M',nam,]));
        M = t{1};
    else
        t = struct2cell(load(nam));
        M = t{1};
    end;

transform

    for i=1:3
        for j=1:3
            for k=1:3
                temp1 = 0;
                for l=1:3
                    temp2 = 0;
                    for m=1:3
                        temp2 = temp2 + M(j,m)*sum(M(k,:).*reshape(g(l,m,:),1,3));
                    end;
                    temp1 = temp1 + M(i,l)*temp2;
                end;
                h(i,j,k) = simple(temp1);
            end;
        end;
    end;

    %matrix representation for rank 3 tensor, symmetric in its last 2
    %indices
    hs = sym(zeros(3,6));
    for k=1:3
        f = h(k,:,:);
        hs(k,:) = f([1,5,9,8,7,4]);
    end;

determine independent elements

    x = cell(1,18);
    y = cell(1,18);
    temp = hs.';
    temp = temp(:);%plug rows of tranformed tensor into 1 single row vector

    hi = sym(zeros(3,6));
    for l = 1:6
        x{l} = ['g1',num2str(l)];
        x{6+l} = ['g2',num2str(l)];
        x{12+l} = ['g3',num2str(l)];
    end;
    for k=1:18
        y{k} = [char(temp(k)),'=',x{k}];%generate defining equations for each element
    end;

    S = solve(y{:},x{:});%solve system of eqns

    %fill matrix representation for independent elements
    for k=1:6
        hi(1,k) = S.(x{k});
        hi(2,k) = S.(x{6+k});
        hi(3,k) = S.(x{12+k});
    end;

display results

    disp('Transformed tensor:');
    disp(hs);

    disp('Independent elements:');
    disp(hi);

    rep = input('repeat: ');
    if isempty(rep),rep=1;end;
end;