Path: csiph.com!news.mixmin.net!news.unit0.net!fu-berlin.de!uni-berlin.de!news.dfncis.de!not-for-mail From: =?UTF-8?Q?Hans-Bernhard_Br=c3=b6ker?= Newsgroups: comp.graphics.apps.gnuplot Subject: Re: Undefined value during function evaluation Date: Tue, 27 Jun 2017 21:44:56 +0200 Lines: 45 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.dfncis.de CvR/wPbxWPWM1ZiBLLMEyQIkf1CF5APqn5DEW25CNwhLPVwnu4W+XiBWzM Cancel-Lock: sha1:zJnkZB7boBuwCBUCtAYWb+3lo2U= User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 In-Reply-To: Content-Language: de-DE Xref: csiph.com comp.graphics.apps.gnuplot:3684 Am 27.06.2017 um 15:54 schrieb schmidtanna114@gmail.com: > a=100000 > b=0.15e-3 > c=633e-9 > d=30 > e=880 > f(x)=((a)**2)*((b)**2)*((c/(pi*b*sin(atan((x-d)/e))))**2)*((sin((pi*b*sin(atan((x-d)/e)))/c))**2) That's a somewhat suboptimal way of setting up your function. It would make a lot more sense to do it more piecemeal: # Let's refer to things by their usual name (some do without the pis...) sinc(x)=sin(pi*x)/(pi*x) # use atan2 instead of atan: f1(x,d,e)=sin(atan2(x-d,e)) # Note: this doesn't really need to use trig functions. # alternative: #f1(x,d,e) = (x-d) / sqrt((x-d)**2 + e**2) # Using these, and after spotting that f(x) consists of terms that are # all_ squared, so the square can be moved to the outer edge, one gets: f(x,a,b,c,d,e) = (a*b * sinc(b/c*f1(x,d,e)))**2 One thing this makes much easier to see is that there's a redundancy in your parameters: f(x,a*b,1,c/b,d,e)=f(x,a,b,c,d,e) for all k,x,a,... Another thing more obvious is how this function's value can become undefined: for x==d, f1(x,d,e) is zero, so the argument to sinc() becomes zero, and you hit the function's undefined spot: gnuplot> print f(d,a,b,c,d,e) ^ undefined value To avoid that, you can use sinc()'s continuous extension instead: sinc(x) = (x == 0) ? 1.0 : sin(pi*x)/(pi*x)