Return amplitudes characterising FRS
function [data, y] = frs_output(prob, data, u)
hatr = data.hatr;
cind = data.cind;
dind = data.dind;
m = size(cind,2);
coeffs = data.coeffs;
nhatr = numel(hatr.val);
optdof = data.optdof;
ndofs = numel(optdof);
whatr = zeros(ndofs,nhatr);
isnonauto = data.isnonauto;
switch data.coordinates
case 'polar'
rho = u(1:2:2*m-1);
th = u(2:2:2*m);
for i=1:nhatr
idx = hatr.pos{i};
ci = cind(idx,:); di = dind(idx,:);
ang = (ci-di)*th;
rhopower = rho.^((ci+di)');
pdrho = prod(rhopower,1);
whatri = coeffs(:,idx).*(pdrho.*exp(1i*ang'));
whatr(:,i) = sum(whatri,2);
end
case 'cartesian'
zRe = u(1:2:2*m-1);
zIm = u(2:2:2*m);
zcomp = zRe+1i*zIm;
zconj = conj(zcomp);
for i=1:nhatr
idx = hatr.pos{i};
ci = cind(idx,:)'; di = dind(idx,:)';
zk = prod(zcomp.^ci.*zconj.^di,1);
whatri = coeffs(:,idx).*zk;
whatr(:,i) = sum(whatri,2);
end
otherwise
error('Optional coordinates: polar and cartesian');
end
if isnonauto
omega = u(2*m+1); epf = u(2*m+2);
x0 = (1i*data.kappa*omega*data.B-data.A)\data.Flead;
if data.isbaseForce; x0 = x0.*omega.^2; end
idplus = find(hatr.val==1);
whatr(:,idplus) = whatr(:,idplus)+epf*x0(optdof);
idminus = find(hatr.val==-1);
whatr(:,idminus) = whatr(:,idminus)+epf*conj(x0(optdof));
end
outdof = data.outdof;
noutdof = numel(outdof);
y = zeros(2*noutdof+1,1);
y(1) = sqrt(real(sum(sum(conj(whatr).*(data.Q*whatr)))));
if noutdof>0
outidx = data.outidx;
for k=1:numel(outdof)
whatrk = whatr(outidx(k),:);
y(k+1) = sqrt(real(sum(sum(conj(whatrk).*(whatrk)))));
end
omega = u(2*m+1);
hatrval = full(hatr.val');
hatrmin = min(data.mFreqs);
T = 2*pi/(omega*hatrmin);
t = linspace(0,T,128)';
yout = exp(1i*hatrval*omega.*t);
for k=1:numel(outdof)
yk = whatr(outidx(k),:).*yout;
yk = max(abs(real(sum(yk,2))));
y(noutdof+k+1) = yk;
end
end
y = data.scales(:).*y;
end