```
# =====================================================================================================
# OSWG-SE gnuplot script; Marcel Batik, 2019
# =====================================================================================================
#
# Input parameters
# -----------------------------------------------------------------------------------------------------
unit = "mm" # length unit
r = 12.7 # throat radius
tau = 0.0 # throat entry angle [deg]
alpha = 90.0 # coverage angle [deg]
L = 150.0 # lenght(depth) of the waveguide
q = 0.995 # SE parameter
s = 1.0 # SE parameter
n = 5.0 # SE parameter
# -----------------------------------------------------------------------------------------------------
# The maths
set angles degrees
k1 = r*r
k2 = 2.0*r*tan(0.5*tau)
k3 = tan(0.5*alpha)**2.0
# OS profile
os(x) = sqrt(k1 + k2*x + k3*x*x)
# OS first derivative
os1(x) = (k3*x + 0.5*k2) / sqrt(k3*x*x + k2*x + k1)
# OS second derivative
os2(x) = (k1*k3 - 0.25*k2*k2) / (k3*x*x + k2*x + k1)**1.5
# OS curvature
oscurv(x) = os2(x) / (1.0 + os1(x)**2)**1.5
# SE profile
se(x) = L*s/q * (1.0 - (1.0 - (q*x/L)**n)**(1/n))
# SE first derivative
se1(x) = L**(1-n) * q**(n-1) * s * x**(n-1) * (1.0 - (q*x/L)**n)**(1/n-1)
# SE second derivative
se2(x) = (L**(n+1) * (n-1) * q**(n-1) * s * x**(n-2) * (1 - (q*x/L)**n)**(1/n)) / ((q*x)**n - L**n)**2
# SE curvature
securv(x) = se2(x) / (1.0 + se1(x)**2)**1.5
# OS+SE
wg(x) = os(x) + se(x)
wgcurv(x) = (os2(x) + se2(x)) / (1.0 + (os1(x)+se1(x))**2)**1.5
# -----------------------------------------------------------------------------------------------------
# plotting
set term pngcairo size 800,1000 font "Courier New,11"
set output "oswg_se.png"
set grid
set size ratio -1
set key top left
set samples 600
set xlabel sprintf("x [%s]", unit)
set ylabel sprintf("y [%s]", unit)
set xrange [0:L]
set y2range [0:0.1]
set ytics nomirror
set y2tics
set y2label "Curvature"
set title sprintf(\
"OSWG-SE: r=%g {/Symbol t}=%g {/Symbol a}=%g s=%g q=%g n=%g L=%g", r, tau, alpha, s, q, n, L\
)
plot os(x) axes x1y1 lc rgb "#a0a0a0" t "OS",\
se(x) axes x1y1 lc rgb "black" t "SE",\
securv(x) axes x1y2 lw 3 lc rgb "black" t "SE curv.",\
wg(x) axes x1y1 lw 1 lc rgb "#7070c0" t "OS+SE",\
wgcurv(x) axes x1y2 lc rgb "#7070c0" lw 3 t "OS+SE curv."
```