Contents
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;
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(:);
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}];
end;
S = solve(y{:},x{:});
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;