Hot answers tagged

2

You must put a dot in all the numbers which are supposed to be floats, so as to be correct while doing division. In gnuplot 2/3 = 0 but 2.0/3.0 = 0.66666..7 In your example, you are suffering from division by zero, but gnuplot does not give good error message. Here is corrected version which runs without any error B0P = 4.0; B0 = 30.0 V0 = 36.0; E0 = -535.0; ...


2

I think a piecewise function is a perfect case for using a closure. This frees you from the need of having a cumbersome n as an argument. import numpy as np import matplotlib.pyplot as plt def define_fn(n): def fn(x): if n <= x <= n + 1: return float(x) - n elif n + 1 <= x <= n + 2: return 2.0 - x + ...


Only top voted, non community-wiki answers of a minimum length are eligible