# Revision history [back]

### Plot evaluation different than function evalution

My sage input is

sage: eta, chi, omega, omega_n = var('eta chi omega omega_n')
sage: exp1=integrate(e**(-eta**2*chi**2/2)*e**(I*(omega_n - omega)*chi),(chi,-1,1))
sage: exp2 = e**(-(omega - omega_n)**2/(2*eta**2))


It turns out that exp1 is $\newcommand{\Bold}[1]{\mathbf{#1}}-\frac{\sqrt{2} \sqrt{\pi} \text{ erf}\left(-\frac{\sqrt{2} \eta^{2} + i \sqrt{2} \omega - i \sqrt{2} \omega_{n}}{2 \eta}\right) e^{\left(-\frac{\omega^{2}}{2 \eta^{2}} + \frac{\omega \omega_{n}}{\eta^{2}} - \frac{\omega_{n}^{2}}{2 \eta^{2}}\right)}}{2 \eta} + \frac{\sqrt{2} \sqrt{\pi} \text{ erf}\left(\frac{\sqrt{2} \eta^{2} - i \sqrt{2} \omega + i \sqrt{2} \omega_{n}}{2 \eta}\right) e^{\left(-\frac{\omega^{2}}{2 \eta^{2}} + \frac{\omega \omega_{n}}{\eta^{2}} - \frac{\omega_{n}^{2}}{2 \eta^{2}}\right)}}{2 \eta}$

I wanted to check if exp2 can be used as an approximation of exp1.

Now suppose I choose to evaluate the absolute error

sage: N(abs((exp1-exp2).subs(omega=2**4,omega_n=0,eta=0.4)))
0.0321314939737044


This is what it should be. However if I plot it (choosing five points for simplicity)

sage: p1 = plot(abs((exp1-exp2).subs(omega=2**4,omega_n=0)),(eta,0,1),plot_points=5)
sage: list(p1[0])
[(0.0025,0.0),(0.148624441929,0.0),(0.347230931288,0.0),(0.396882553627,0.0),(0.446534175967,0.031240245935),(0.545837420646,0.0291057729397),(0.741443657239,0.0242243187304),(1.0,0.0172533234321)]


For some reason below about 0.41 the plot function evaluates it to 0, but a call like

sage: N(abs((exp1-exp2).subs(omega=2**4,omega_n=0,eta=0.0025)))
0.0359877559973356


shows that this is incorrect behavior. Any idea why plot fails to evaluate this correctly for "small" values?

The larger omega is, the worse the cutoff is. That is, large omega means that the plot goes to 0 for even if eta is larger than 0.41 in general. For example choosing omega=2**5 gives a cutoff at about eta = 0.84, so that plot just puts zeros for eta < .84 in this case.

 2 retagged FrédéricC 1966 ●3 ●22 ●36

### Plot evaluation different than function evalution

My sage input is

sage: eta, chi, omega, omega_n = var('eta chi omega omega_n')
sage: exp1=integrate(e**(-eta**2*chi**2/2)*e**(I*(omega_n - omega)*chi),(chi,-1,1))
sage: exp2 = e**(-(omega - omega_n)**2/(2*eta**2))


It turns out that exp1 is $\newcommand{\Bold}[1]{\mathbf{#1}}-\frac{\sqrt{2} \sqrt{\pi} \text{ erf}\left(-\frac{\sqrt{2} \eta^{2} + i \sqrt{2} \omega - i \sqrt{2} \omega_{n}}{2 \eta}\right) e^{\left(-\frac{\omega^{2}}{2 \eta^{2}} + \frac{\omega \omega_{n}}{\eta^{2}} - \frac{\omega_{n}^{2}}{2 \eta^{2}}\right)}}{2 \eta} + \frac{\sqrt{2} \sqrt{\pi} \text{ erf}\left(\frac{\sqrt{2} \eta^{2} - i \sqrt{2} \omega + i \sqrt{2} \omega_{n}}{2 \eta}\right) e^{\left(-\frac{\omega^{2}}{2 \eta^{2}} + \frac{\omega \omega_{n}}{\eta^{2}} - \frac{\omega_{n}^{2}}{2 \eta^{2}}\right)}}{2 \eta}$

I wanted to check if exp2 can be used as an approximation of exp1.

Now suppose I choose to evaluate the absolute error

sage: N(abs((exp1-exp2).subs(omega=2**4,omega_n=0,eta=0.4)))
0.0321314939737044


This is what it should be. However if I plot it (choosing five points for simplicity)

sage: p1 = plot(abs((exp1-exp2).subs(omega=2**4,omega_n=0)),(eta,0,1),plot_points=5)
sage: list(p1[0])
[(0.0025,0.0),(0.148624441929,0.0),(0.347230931288,0.0),(0.396882553627,0.0),(0.446534175967,0.031240245935),(0.545837420646,0.0291057729397),(0.741443657239,0.0242243187304),(1.0,0.0172533234321)]


For some reason below about 0.41 the plot function evaluates it to 0, but a call like

sage: N(abs((exp1-exp2).subs(omega=2**4,omega_n=0,eta=0.0025)))
0.0359877559973356


shows that this is incorrect behavior. Any idea why plot fails to evaluate this correctly for "small" values?

The larger omega is, the worse the cutoff is. That is, large omega means that the plot goes to 0 for even if eta is larger than 0.41 in general. For example choosing omega=2**5 gives a cutoff at about eta = 0.84, so that plot just puts zeros for eta < .84 in this case.