%https://dxdy.ru/post1558470.html
clc
clearvars
format compact
x0 = log (2) / 2;
phi0 = x0 - pi / 4;
num = 16;
myfunc = @ (q, p) (cos (q - p) - exp (-q));
xx = 0 : 0.001 : 2;
pp = 2 * pi * xx;
yy = zeros (size (xx));
ksks = zeros (num, numel (yy));
for n = 1 : numel (yy)
phi = phi0 + mod (pp (n) - phi0, 2 * pi);
if 0 > phi
ksi = fzero (@ (x) myfunc (x, phi), [0, x0]);
ksks (1, n) = ksi;
yy (n) = yy (n) + exp (-ksi);
ksi = fzero (@ (x) myfunc (x, phi), [x0, pi / 2]);
ksks (2, n) = ksi;
yy (n) = yy (n) - exp (-ksi);
else
ksi = fzero (@ (x) myfunc (x, phi), [0, phi + x0]);
ksks (1, n) = ksi;
yy (n) = yy (n) + exp (-ksi);
ksi = fzero (@ (x) myfunc (x, phi), [phi + x0, phi + pi]);
ksks (2, n) = ksi;
yy (n) = yy (n) - exp (-ksi);
end
for k = 2 : num - 1
ksi = fzero (@ (x) myfunc (x, phi), [-pi, 0] + phi + pi * k);
ksks (k + 1, n) = ksi;
yy (n) = yy (n) + (-1) ^ k * exp (-ksi);
end
end
if 1
subplot(111)
plot (xx, yy, 'LineWidth', 2)
grid on
else
subplot(111)
plot (xx, ksks, 'LineWidth', 2)
ylim ([0, 20])
grid on
end