Function inside a function?
Alasdair McAndrew <[email protected]> Thu, 12 Nov 2015 14:10:09 +1100
| Newsgroups | gmane.comp.mathematics.axiom.user |
|---|---|
| Message-ID | <CAPGiC75vG7515QU9iv8oPLdhpUkC43fueC7vgc2kwam0BqAuFQ@mail.gmail.com> |
--===============8873436313667374245== Content-Type: multipart/alternative; boundary=001a113dc1eed6d0a205244f4733 --001a113dc1eed6d0a205244f4733 Content-Type: text/plain; charset=UTF-8 I have been experimenting with writing a few little programs to perform numerical integration, in which I have been running into difficulties. I can do all the operations I need from the command line, but I run into problems when I try to bundle those commands into a program. As a simple example, suppose I wanted a program to implement the two-point Gaussian rule, which approximates the integral of f(x) between -1 and 1 by f(-1/sqrt(3))+f(1/sqrt(3)). On an interval other than [-1,1], we need a scaling transformation. So I might have a file called "gauss2.input" which contains one function: gauss2(f,a,b)== xs:LIST Float := [-1/sqrt(3),1/sqrt(3)] g := (x:Float):Float +-> f((b-a)/2*x+(b+a)/2) int2 := (b-a)/2*(g(xs.1) + g(xs.2)) return(int2) However, the system clams up on the use of the scaling function g(x), and this gives no results. I have two questions here: first, how do I get round this? and second, if I'm writing programs, should I be writing them in Aldor (that's the language of ".input" files, isn't it?), or SPAD? For that matter, how do all the languages Aldor, SPAD, Lisp, Boot link up - which is used for which purpose, and why? Thanks, Alasdair -- [image: http://www.facebook.com/alasdair.mcandrew] <http://www.facebook.com/alasdair.mcandrew> [image: https://plus.google.com/+AlasdairMcAndrew/posts] <https://plus.google.com/+AlasdairMcAndrew/posts> [image: https://www.linkedin.com/pub/alasdair-mcandrew/a/178/108] <https://www.linkedin.com/pub/alasdair-mcandrew/a/178/108> [image: https://twitter.com/amca01] <https://twitter.com/amca01> [image: http://numbersandshapes.net] <http://numbersandshapes.net> --001a113dc1eed6d0a205244f4733 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div><div><div><div><div><div>I have been experimenting wi= th writing a few little programs to perform numerical integration, in which= I have been running into difficulties.=C2=A0 I can do all the operations I= need from the command line, but I run into problems when I try to bundle t= hose commands into a program.<br><br></div>As a simple example, suppose I w= anted a program to implement the two-point Gaussian rule, which approximate= s the integral of f(x) between -1 and 1 by f(-1/sqrt(3))+f(1/sqrt(3)).<br><= br></div>On an interval other than [-1,1], we need a scaling transformation= .=C2=A0 So I might have a file called "gauss2.input" which contai= ns one function:<br><br></div>gauss2(f,a,b)=3D=3D<br>=C2=A0 xs:LIST Float := =3D [-1/sqrt(3),1/sqrt(3)]<br>=C2=A0 g :=3D (x:Float):Float +-> f((b-a)/= 2*x+(b+a)/2)<br>=C2=A0 int2 :=3D (b-a)/2*(g(xs.1) + g(xs.2))<br>=C2=A0 retu= rn(int2)<br><br></div><div>However, the system clams up on the use of the s= caling function g(x), and this gives no results.<br><br></div><div>I have t= wo questions here: first, how do I get round this?=C2=A0 and second, if I&#= 39;m writing programs, should I be writing them in Aldor (that's the la= nguage of ".input" files, isn't it?), or SPAD?<br><br></div><= div>For that matter, how do all the languages Aldor, SPAD, Lisp, Boot link = up - which is used for which purpose, and why?<br><br></div><div>Thanks,<br= ></div><div>Alasdair<br></div><div><br>-- <br><div class=3D"gmail_signature= "><div dir=3D"ltr"><a href=3D"http://www.facebook.com/alasdair.mcandrew" ta= rget=3D"_blank"><img alt=3D"http://www.facebook.com/alasdair.mcandrew" src= =3D"https://dl.dropboxusercontent.com/u/2796170/facebook.png"></a> <a href= =3D"https://plus.google.com/+AlasdairMcAndrew/posts" target=3D"_blank"><img= alt=3D"https://plus.google.com/+AlasdairMcAndrew/posts" src=3D"https://dl.= dropboxusercontent.com/u/2796170/f-gplus_256-48.png"></a> <a href=3D"https:= //www.linkedin.com/pub/alasdair-mcandrew/a/178/108" target=3D"_blank"><img = alt=3D"https://www.linkedin.com/pub/alasdair-mcandrew/a/178/108" src=3D"htt= ps://dl.dropboxusercontent.com/u/2796170/linkedin.png"></a> <a href=3D"http= s://twitter.com/amca01" target=3D"_blank"><img alt=3D"https://twitter.com/a= mca01" src=3D"https://dl.dropboxusercontent.com/u/2796170/twitter.png"></a>= <a href=3D"http://numbersandshapes.net" target=3D"_blank"><img alt=3D"http= ://numbersandshapes.net" src=3D"https://dl.dropboxusercontent.com/u/2796170= /wordpress.png"></a><br></div></div> </div></div></div></div> --001a113dc1eed6d0a205244f4733-- --===============8873436313667374245== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Axiom-mail mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/axiom-mail --===============8873436313667374245==--