Sponsored Content
Top Forums Programming Javascript: gamma approximation Post 302876504 by figaro on Monday 25th of November 2013 06:10:57 AM
Old 11-25-2013
Javascript: gamma approximation

Here is some javascript code that implements the Lanczos approximation to the gamma function (http://en.wikipedia.org/wiki/Lanczos_approximation):

Code:
<script type="text/javascript">
// Gamma approximation; coefficients used by the GNU Scientific Library
function gamma(z) {
  var p = [0.99999999999980993, 676.5203681218851, -1259.1392167224028, 771.32342877765313, -176.61502916214059, 12.507343278686905, -0.13857109526572012, 9.9843695780195716e-6, 1.5056327351493116e-7];
  if z < 0.5 {
     return Math.PI / (Math.sin(Math.PI*z) * gamma(1-z));
  } else {
    z -= 1;
    x = p[0];
    for (var i = 0; i < p.length; i++) x += p[i]/(z+i);
    t = z + p.length - 1.5;
    return Math.sqrt(2*Math.PI) * Math.pow(t, z+0.5) * Math.exp(-t) * x;
  }
}

for (var x = 0.1; x < 3; x += 0.1) document.write("x: " + x + " gamma(x): " + gamma(x) + "<br/>");
</script>

This returns an empty page, which usually means there is a syntactical error in the code. In the absence of a proper debugger, can anyone point out where this error might be?

Thank you in advance.
 

7 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

javascript onClick help

I have two radio buttons with corresponding text boxes for input, when one is chosen I am disabling the text box for the other, is there a way to "gray out" the disabled text box using background-color or something? Any help is greatly appreciated, right now my onClick looks like this: ... (1 Reply)
Discussion started by: k@ssidy
1 Replies

2. Shell Programming and Scripting

javascript injection

Please advise a script to get rid of the following code which is infected in a large number of files ( in particular php and html files ) <div id="testws35fdgh"></div> <script language="JavaScript"> var0 = "\x69\x3c\x33\x27\x34\x38\x30\x75\x3b\x34"; var1 =... (20 Replies)
Discussion started by: fed.linuxgossip
20 Replies

3. UNIX and Linux Applications

stopclock coding in javascript.

i have got a problem in this coding.i have got start/pause in the same button.wen i open that page the stopclock runs automatically.wen i click pause it get paused in the frontend textbox bt running in the backend.wen i again click that start itz starting from the time without considering that... (2 Replies)
Discussion started by: VIJI
2 Replies

4. Web Development

Sortable Tables in Javascript

Hi, I am writing a web application using Perl-CgI mostly. I wanted to integrate a table in which I was capable of sorting columns and I don't think this is possible with static HTML code. Can someone help me integrating some javascript code into what I have to acheive the above? Regards,... (6 Replies)
Discussion started by: garric
6 Replies

5. Web Development

Javascript Problems in Opera 10

Ref earlier post: https://www.unix.com/web-programming-web-2-0-mashups/118283-opera-10-0-released-looks-nice.html I have noticed that Google Docs, Speadsheets does not work properly in Opera 10. Anyone else seen the same thing? (1 Reply)
Discussion started by: Neo
1 Replies

6. Programming

Help in javascript

Hi , I wanted to know if its possible to execute a javascript function like this E:- function js1(){ alert ("this is js1"); } function js2(){ alert ("this is js2"); } function js3(){ .... execthisscript(js1); execthisscript(js2); } ... (1 Reply)
Discussion started by: daptal
1 Replies

7. Programming

Need help with Javascript

Hi guys, Ok first, let me explain what I want to do. I'm making a theme for the iphone, and I found a nice wallpaper slideshow script. Here is how it knows which wallpapers to use: <script type="text/javascript"> // SLIDE ROTATION FREQUENCY (in minutes) var slideRotation = 0.4;... (3 Replies)
Discussion started by: kicker75
3 Replies
Perl::Critic::Utils::McCabe(3)				User Contributed Perl Documentation			    Perl::Critic::Utils::McCabe(3)

NAME
Perl::Critic::Utils::McCabe - Functions that calculate the McCabe score of source code. DESCRIPTION
Provides approximations of McCabe scores. The McCabe score of a set of code describes the number of possible paths through it. The functions here approximate the McCabe score by summing the number of conditional statements and operators within a set of code. See <http://en.wikipedia.org/wiki/Cyclomatic_complexity> for some discussion about the McCabe number and other complexity metrics. INTERFACE SUPPORT
This is considered to be a public module. Any changes to its interface will go through a deprecation cycle. IMPORTABLE SUBS
"calculate_mccabe_of_sub( $sub )" Calculates an approximation of the McCabe number of the code in a PPI::Statement::Sub. "calculate_mccabe_of_main( $doc )" Calculates an approximation of the McCabe number of all the code in a PPI::Statement::Document that is not contained in a subroutine. AUTHOR
Jeffrey Ryan Thalhammer <jeff@imaginative-software.com> COPYRIGHT
Copyright (c) 2005-2011 Imaginative Software Systems. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of this license can be found in the LICENSE file included with this module. perl v5.16.3 2014-06-09 Perl::Critic::Utils::McCabe(3)
All times are GMT -4. The time now is 09:58 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy