Download AspectMatlab - Sable Research Group

Transcript
D.4. Adding units to computations
newPNorm(i) = norm((v - u), 1); % see how much that unit
reduces the unit vector v
newMNorm(i) = norm((v + u), 1); % same but with inverted unit
end
[minPNorm, minPi] = min(newPNorm);
[minMNorm, minMi] = min(newMNorm);
if (minPNorm < minMNorm) % put the found unit into print vector
print(minPi) = (print(minPi) + 1); % positive unit (unitˆ1)
u = -getfield(this.units, names{minPi});
else
print(minMi) = (print(minMi) - 1); % negativ unit (unitˆ-1)
u = (getfield(this.units, names{minMi}));
end
v = (v + u);
end
% put whatever is in the print vector into a string
for i = (1 : length(print))
if (print(i) ˜= 0)
s = strcat(s, strcat(’*’, names{i}));
if (print(i) ˜= 1)
s = strcat(s, strcat(’ˆ’, num2str(print(i))));
end
end
end
s = s(2:length(s)); % we know there must be one unit - replace
leading ’*’
end
end
patterns
disp : call(disp);
plus : call(plus(*,*));
minus : call(minus(*,*));
mtimes : call(mtimes(*,*));
mrdivide : call(mrdivide(*,*));
power : call(power(*,*));
105