From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/19392 Path: news.gmane.org!not-for-mail From: David Arnold Newsgroups: gmane.comp.tex.context Subject: Re: OT: looking for metapost/fun examples Date: Sat, 26 Mar 2005 20:39:26 -0800 Message-ID: <33010155-9E7A-11D9-83E3-001124338712@northcoast.com> References: <83247004dabfc9c2a8d8ce00ef0408a6@rna.nl> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 (Apple Message framework v619) Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1111899780 12025 80.91.229.2 (27 Mar 2005 05:03:00 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 27 Mar 2005 05:03:00 +0000 (UTC) Original-X-From: ntg-context-bounces@ntg.nl Sun Mar 27 07:02:59 2005 Original-Received: from ronja.vet.uu.nl ([131.211.172.88] helo=ronja.ntg.nl) by ciao.gmane.org with esmtp (Exim 4.43) id 1DFPvH-0003yH-AV for gctc-ntg-context-518@m.gmane.org; Sun, 27 Mar 2005 07:02:51 +0200 Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id DC4411284F; Sun, 27 Mar 2005 07:03:21 +0200 (CEST) Original-Received: from ronja.ntg.nl ([127.0.0.1]) by localhost (ronja.vet.uu.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 10508-03; Sun, 27 Mar 2005 07:03:20 +0200 (CEST) Original-Received: from ronja.vet.uu.nl (localhost.localdomain [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id 2BF0C1287D; Sun, 27 Mar 2005 06:39:47 +0200 (CEST) Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id 7FBFD1287D for ; Sun, 27 Mar 2005 06:39:45 +0200 (CEST) Original-Received: from ronja.ntg.nl ([127.0.0.1]) by localhost (ronja.vet.uu.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 10274-03 for ; Sun, 27 Mar 2005 06:39:44 +0200 (CEST) Original-Received: from borg.inreach.com (mail.northcoast.com [209.142.2.71]) by ronja.ntg.nl (Postfix) with SMTP id 1404C1287B for ; Sun, 27 Mar 2005 06:39:43 +0200 (CEST) Original-Received: (qmail 22122 invoked by uid 507); 27 Mar 2005 04:39:41 -0000 Original-Received: from unknown (HELO ?209.209.19.237?) (209.209.19.237) by mail.northcoast.com with SMTP; 27 Mar 2005 04:39:41 -0000 In-Reply-To: <83247004dabfc9c2a8d8ce00ef0408a6@rna.nl> Original-To: mailing list for ConTeXt users X-Mailer: Apple Mail (2.619) X-Virus-Scanned: by amavisd-new at ntg.nl X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.5 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: ntg-context-bounces@ntg.nl Errors-To: ntg-context-bounces@ntg.nl X-Virus-Scanned: by amavisd-new at ntg.nl Xref: news.gmane.org gmane.comp.tex.context:19392 X-Report-Spam: http://spam.gmane.org/gmane.comp.tex.context:19392 Gerben, Again, thanks for all you do. Here's a Fourier approximation of a square wave. Again, I compiled this in Texshop so I know it works. %verbatimtex % \input mtplain % \MTMI{8pt}{6pt}{5pt} % \MTSY{8pt}{6pt}{5pt} % \MTEX{8pt} % \MathRoman{tir}{8pt}{6pt}{5pt} % \MathBold{tib}{8pt}{6pt}{5pt} %etex %Input Context macros input mp-tool %define ytick vardef ytick(expr pos)= path p; p:=(-2,0)--(2,0); draw p shifted pos; enddef; %define xtick vardef xtick(expr pos)= path p; p:=(0,-2)--(0,2); draw p shifted pos; enddef; %define pi pi:=3.14159; %define cosine in radians vardef cos(expr x)= cosd(x*180/pi) enddef; %define sine in radians vardef sin(expr x)= sind(x*180/pi) enddef; %hyperbolic sine vardef sinh(expr x)= (exp(x)-exp(-x))/2 enddef; beginfig(1); %enter number of terms numeric N; N=6; %define L numeric L; L:=pi; %define a_0 ao:=1; %define a_n vardef a(expr n)= 2*sin(n*pi/2)/(n*pi) enddef; %define b_n vardef b(expr n)= 0 enddef; %initialize scale numeric ux, uy; pi*ux=2in; 1.5*uy=2in; %draw axes drawarrow (0,0)--(3.5ux,0); drawarrow (0,0)--(0,1.5uy); %label axes label.rt(btex $x$ etex, (3.5ux,0)); %tick marks xtick((pi*ux,0)); label.bot(btex $\pi$ etex, (pi*ux,0)); ytick((0,1*uy)); label.lft(btex $1$ etex, (0,1*uy)); %draw the function in black draw (0,1uy)--((pi/2)*ux,1uy); %draw Fourier approximation in cyan path p; numeric x, y; x:=0; y:=ao/2; for k=1 step 1 until N: y:=y+a(k)*cos(k*pi*x/L)+b(k)*sin(k*pi*x/L); endfor; p:=(x,y); for x=0 step .1 until pi: y:=ao/2; for k=1 step 1 until N: y:=y+a(k)*cos(k*pi*x/L)+b(k)*sin(k*pi*x/L); endfor; p:=p--(x,y); endfor; x:=pi; y:=ao/2; for k=1 step 1 until N: y:=y+a(k)*cos(k*pi*x/L)+b(k)*sin(k*pi*x/L); endfor; p:=p--(x,y); p:=p xyscaled(ux,uy); draw p withcolor cyan; endfig; beginfig(0); %enter number of terms numeric N; N=6; %define L numeric L; L:=pi; %define a_0 ao:=1; %define a_n vardef a(expr n)= 2*sin(n*pi/2)/(n*pi) enddef; %define b_n vardef b(expr n)= 0 enddef; %initialize scale numeric ux, uy; 6*pi*ux=2in; 1.5*uy=2in; %draw axes drawdblarrow (-3.5*pi*ux,0)--(3.5*pi*ux,0); drawarrow (0,0)--(0,1.5uy); %label axes label.rt(btex $x$ etex, (3.5*pi*ux,0)); %tick marks xtick((pi*ux,0)); xtick((2*pi*ux,0)); xtick((3*pi*ux,0)); label.bot(btex $3\pi$ etex, (3*pi*ux,0)); xtick((-pi*ux,0)); xtick((-2*pi*ux,0)); xtick((-3*pi*ux,0)); label.bot(btex $-3\pi$ etex, (-3*pi*ux,0)); ytick((0,1*uy)); label.lft(btex $1$ etex, (0,1*uy)); %draw the function in black path q; q:=(-pi/2,1)--(pi/2,1); q:=q xyscaled(ux,uy); draw q; draw q shifted (2*pi*ux,0); draw q shifted (-2*pi*ux,0); %draw Fourier approximation in cyan path p; numeric x, y; x:=-3*pi; y:=ao/2; for k=1 step 1 until N: y:=y+a(k)*cos(k*pi*x/L)+b(k)*sin(k*pi*x/L); endfor; p:=(x,y); for x=-3*pi step .1 until 3*pi: y:=ao/2; for k=1 step 1 until N: y:=y+a(k)*cos(k*pi*x/L)+b(k)*sin(k*pi*x/L); endfor; p:=p--(x,y); endfor; x:=3*pi; y:=ao/2; for k=1 step 1 until N: y:=y+a(k)*cos(k*pi*x/L)+b(k)*sin(k*pi*x/L); endfor; p:=p--(x,y); p:=p xyscaled(ux,uy); draw p withcolor cyan; endfig; end; On Mar 26, 2005, at 3:19 PM, Gerben Wierda wrote: > I am trying to learn metapost/fun, inline in ConTeXt source. Some > basic things are clear, but now the issue is metapost itself. > > For instance, I would like to plot a Fourier approximation of a block > function. > > For instance, I would like to plot a gaussian spread. > > I am looking for examples on how to do this. I need to do a bit of > programming here and these are my initial projects. > > Thanks in advance, > > G > > _______________________________________________ > ntg-context mailing list > ntg-context@ntg.nl > http://www.ntg.nl/mailman/listinfo/ntg-context >