* MetaFun: MetaPost example works with `mpost` but not embedded in ConTeXt: `! Redundant equation.`
@ 2011-12-11 20:15 Paul Menzel
2011-12-11 23:59 ` Marco
0 siblings, 1 reply; 2+ messages in thread
From: Paul Menzel @ 2011-12-11 20:15 UTC (permalink / raw)
To: ntg-context
[-- Attachment #1.1.1: Type: text/plain, Size: 1764 bytes --]
Dear ConTeXt folks,
looking for graphics example and therefore searching the list I found
the answer from David Arnold in the ntg-context list thread »OT: looking
for metapost/fun examples« [1].
It is for plain MetaPost and works fine with `mpost` after making sure
to remove the line breaks inserted by the mail program.
I then copied it into `\{start,stop}useMPgraphic`, removed the `end ;`
and `{begin,end}fig` and replaced `{e,b}tex` by `textext()` but still
get the following error.
! terminal: ! Redundant equation.
<to be read again>
;
<*> ...500; dt:=(tstop-tstart)/N; (b-a)*ux=1.75in;
(d-c)*uy=1.75in; q=(a,c)-...
! Redundant equation.
<to be read again>
;
<*> ...start)/N; (b-a)*ux=1.75in; (d-c)*uy=1.75in;
q=(a,c)--(b,c)--(b,d)--(a...
.
system > tex > error on line 39 in file arnold-2005.tex: terminal: ! Redundant equation.
<to be read again>
;
<*> ...500; dt:=(tstop-tstart)/N; (b-a)*ux=1.75in;
(d-c)*uy=1.75in; q=(a,c)-...
! Redundant equation.
<to be read again>
;
<*> ...start)/N; (b-a)*ux=1.75in; (d-c)*uy=1.75in;
q=(a,c)--(b,c)--(b,d)--(a...
Does someone have an idea why this fails and how to fix it?
Thanks,
Paul
[1] http://www.ntg.nl/pipermail/ntg-context/2005/009928.html
[-- Attachment #1.1.2: arnold-2005.mp --]
[-- Type: text/x-matlab, Size: 5618 bytes --]
%This file creates two figures associated with the
%system x'=f(x,y), y'=g(x,y)
%1. Plots the graphs of x(t) and y(t)
%2. Plots the graph of (x(t),y(t)) in the phase plane.
%verbatimtex
%\input mtplain
%etex
%Generate standard eps
prologues:=2;
beginfig(0);
%Place RHS of x'=f(t,x,y) here
def fxy(expr t, x, y)=
(0.4-0.01*y)*x
enddef;
%Place RHS of y'=g(t,x,y) here
def gxy(expr t, x, y)=
(-0.3+0.005*x)*y
enddef;
%Declare some variables
path q, trajx, trajy;
pair L, R, B, T, xt, yt;
numeric sx[], sy[];
%Initialize clipping window
a:=0; b:=40; %left and right of viewing rectangle
c:=0; d:=150; %bottom and top of viewing rectangle
%Initialize timespan
tstart:=a;
tstop:=b;
%Initialize number of points to be plotted
N:=500;
%Calculate time increment dt for Euler's method
dt:=(tstop-tstart)/N;
%Scaling factors for horizontal and vertical axes. Note that this produces
%an image that is 2 inches by 2 inches.
(b-a)*ux=1.75in;
(d-c)*uy=1.75in;
%Clipping boundary
q=(a,c)--(b,c)--(b,d)--(a,d)--cycle;
%Use Runge-Kutta4 to create path (t,x(t))
%Choose initial condition
t:=tstart;
x:=40;
y:=20;
trajx:=(t,x);
forever:
sx1:=fxy(t,x,y);
sy1:=gxy(t,x,y);
sx2:=fxy((t+dt/2),(x+dt*sx1/2),(y+dt*sy1/2));
sy2:=gxy((t+dt/2),(x+dt*sx1/2),(y+dt*sy1/2));
sx3:=fxy((t+dt/2),(x+dt*sx2/2),(y+dt*sy2/2));
sy3:=gxy((t+dt/2),(x+dt*sx2/2),(y+dt*sy2/2));
sx4:=fxy((t+dt),(x+dt*sx3),(y+dt*sy3));
sy4:=gxy((t+dt),(x+dt*sx3),(y+dt*sy3));
x:=x+dt*(sx1+2*sx2+2*sx3+sx4)/6;
y:=y+dt*(sy1+2*sy2+2*sy3+sy4)/6;
t:=t+dt;
trajx:=trajx..(t,x);
exitif ((t>tstop) or (t>b) or (x<c) or (x>d));
endfor;
%Use Runge-Kutta4 to create path (t,y(t))
%Choose initial condition
t:=tstart;
x:=40;
y:=20;
trajy:=(t,y);
forever:
sx1:=fxy(t,x,y);
sy1:=gxy(t,x,y);
sx2:=fxy((t+dt/2),(x+dt*sx1/2),(y+dt*sy1/2));
sy2:=gxy((t+dt/2),(x+dt*sx1/2),(y+dt*sy1/2));
sx3:=fxy((t+dt/2),(x+dt*sx2/2),(y+dt*sy2/2));
sy3:=gxy((t+dt/2),(x+dt*sx2/2),(y+dt*sy2/2));
sx4:=fxy((t+dt),(x+dt*sx3),(y+dt*sy3));
sy4:=gxy((t+dt),(x+dt*sx3),(y+dt*sy3));
x:=x+dt*(sx1+2*sx2+2*sx3+sx4)/6;
y:=y+dt*(sy1+2*sy2+2*sy3+sy4)/6;
t:=t+dt;
trajy:=trajy..(t,y);
exitif ((t>tstop) or (t>b) or (y<c) or (y>d));
endfor;
%Draw the paths x(t) and y(t) and clip them to bounding box
draw trajx xscaled ux yscaled uy withcolor red;
draw trajy xscaled ux yscaled uy withcolor red dashed evenly;
clip currentpicture to (q xscaled ux yscaled uy);
%Label graph x(t) and initial condition
len:= 0.65*(length trajx);
xt:=point len of trajx;
label.urt(btex $\scriptstyle x(t)$ etex, (xt xscaled ux yscaled uy));
%Label graph y(t) and initial condition
len:= 0.5*(length trajy);
yt:=point len of trajy;
label.lrt(btex $\scriptstyle y(t)$ etex, (yt xscaled ux yscaled uy));
%Initialize left and right endpoints on time-axis
L=(a*ux,0);R=(b*ux,0);
%Draw and label t-axis
drawarrow L--R;
label.rt(btex $\scriptstyle t$ etex,(b*ux,0));
%Initialize bottom and top endpoints on time-axis
B=(0,c*uy);T=(0,d*uy);
%Draw and label vertical axis
drawarrow B--T;
label.lft(btex $\scriptstyle 0$ etex, B);
label.lft(btex $\scriptstyle 150$ etex, T);
endfig;
beginfig(2);
%Make some variables local
save ux, uy;
%Place RHS of x'=f(t,x,y) here
def fxy(expr t, x, y)=
(0.4-0.01*y)*x
enddef;
%Place RHS of y'=g(t,x,y) here
def gxy(expr t, x, y)=
(-0.3+0.005*x)*y
enddef;
%Declare some variables
path q, trajxy;
pair L, R, B, T;
%Initialize clipping window
a:=0; b:=150; %left and right of viewing rectangle
c:=0; d:=100; %bottom and top of viewing rectangle
%Initialize timespan
tstart:=a;
tstop:=b;
%Initialize number of points to be plotted
N:=500;
%Calculate time increment dt for Euler's method
dt:=(tstop-tstart)/N;
%Scaling factors for horizontal and vertical axes. Note that this produces
%an image that is 2 inches by 2 inches.
(b-a)*ux=1.75in;
(d-c)*uy=1.75in;
%Clipping boundary
q=(a,c)--(b,c)--(b,d)--(a,d)--cycle;
%Use Runge-Kutta4 to create path (x(t),y(t))
%Choose initial condition
t:=tstart;
x:=40;
y:=20;
trajxy:=(x,y);
forever:
sx1:=fxy(t,x,y);
sy1:=gxy(t,x,y);
sx2:=fxy((t+dt/2),(x+dt*sx1/2),(y+dt*sy1/2));
sy2:=gxy((t+dt/2),(x+dt*sx1/2),(y+dt*sy1/2));
sx3:=fxy((t+dt/2),(x+dt*sx2/2),(y+dt*sy2/2));
sy3:=gxy((t+dt/2),(x+dt*sx2/2),(y+dt*sy2/2));
sx4:=fxy((t+dt),(x+dt*sx3),(y+dt*sy3));
sy4:=gxy((t+dt),(x+dt*sx3),(y+dt*sy3));
x:=x+dt*(sx1+2*sx2+2*sx3+sx4)/6;
y:=y+dt*(sy1+2*sy2+2*sy3+sy4)/6;
t:=t+dt;
trajxy:=trajxy..(x,y);
exitif ((t>tstop) or (t>b) or (x<a) or (x>b) or (y<c) or (y>d));
endfor;
%Draw the paths x(t) and y(t) and clip them to bounding box
draw trajxy xscaled ux yscaled uy withcolor red;
clip currentpicture to (q xscaled ux yscaled uy);
%Initialize left and right endpoints on x-axis
L=(a*ux,0);R=(b*ux,0);
%Draw and label x-axis
drawarrow L--R;
label.rt(btex $\scriptstyle x$ etex,(b*ux,0));
label.bot(btex $\scriptstyle 0$ etex,L);
label.bot(btex $\scriptstyle 150$ etex,R);
%Initialize bottom and top endpoints on y-axis
B=(0,c*uy);T=(0,d*uy);
%Draw and label vertical axis
drawarrow B--T;
label.rt(btex $\scriptstyle y$ etex,(0,d*uy));
label.lft(btex $\scriptstyle 0$ etex, B);
label.lft(btex $\scriptstyle 100$ etex, T);
endfig;
end;
[-- Attachment #1.1.3: arnold-2005.tex --]
[-- Type: text/x-tex, Size: 5713 bytes --]
\starttext
\startuseMPgraphic{ex1}
%This file creates two figures associated with the
%system x'=f(x,y), y'=g(x,y)
%1. Plots the graphs of x(t) and y(t)
%2. Plots the graph of (x(t),y(t)) in the phase plane.
%verbatimtex
%\input mtplain
%etex
%Generate standard eps
%prologues:=2;
%beginfig(0);
%Place RHS of x'=f(t,x,y) here
def fxy(expr t, x, y)=
(0.4-0.01*y)*x
enddef;
%Place RHS of y'=g(t,x,y) here
def gxy(expr t, x, y)=
(-0.3+0.005*x)*y
enddef;
%Declare some variables
path q, trajx, trajy;
pair L, R, B, T, xt, yt;
numeric sx[], sy[];
%Initialize clipping window
a:=0; b:=40; %left and right of viewing rectangle
c:=0; d:=150; %bottom and top of viewing rectangle
%Initialize timespan
tstart:=a;
tstop:=b;
%Initialize number of points to be plotted
N:=500;
%Calculate time increment dt for Euler's method
dt:=(tstop-tstart)/N;
%Scaling factors for horizontal and vertical axes. Note that this produces
%an image that is 2 inches by 2 inches.
(b-a)*ux=1.75in;
(d-c)*uy=1.75in;
%Clipping boundary
q=(a,c)--(b,c)--(b,d)--(a,d)--cycle;
%Use Runge-Kutta4 to create path (t,x(t))
%Choose initial condition
t:=tstart;
x:=40;
y:=20;
trajx:=(t,x);
forever:
sx1:=fxy(t,x,y);
sy1:=gxy(t,x,y);
sx2:=fxy((t+dt/2),(x+dt*sx1/2),(y+dt*sy1/2));
sy2:=gxy((t+dt/2),(x+dt*sx1/2),(y+dt*sy1/2));
sx3:=fxy((t+dt/2),(x+dt*sx2/2),(y+dt*sy2/2));
sy3:=gxy((t+dt/2),(x+dt*sx2/2),(y+dt*sy2/2));
sx4:=fxy((t+dt),(x+dt*sx3),(y+dt*sy3));
sy4:=gxy((t+dt),(x+dt*sx3),(y+dt*sy3));
x:=x+dt*(sx1+2*sx2+2*sx3+sx4)/6;
y:=y+dt*(sy1+2*sy2+2*sy3+sy4)/6;
t:=t+dt;
trajx:=trajx..(t,x);
exitif ((t>tstop) or (t>b) or (x<c) or (x>d));
endfor;
%Use Runge-Kutta4 to create path (t,y(t))
%Choose initial condition
t:=tstart;
x:=40;
y:=20;
trajy:=(t,y);
forever:
sx1:=fxy(t,x,y);
sy1:=gxy(t,x,y);
sx2:=fxy((t+dt/2),(x+dt*sx1/2),(y+dt*sy1/2));
sy2:=gxy((t+dt/2),(x+dt*sx1/2),(y+dt*sy1/2));
sx3:=fxy((t+dt/2),(x+dt*sx2/2),(y+dt*sy2/2));
sy3:=gxy((t+dt/2),(x+dt*sx2/2),(y+dt*sy2/2));
sx4:=fxy((t+dt),(x+dt*sx3),(y+dt*sy3));
sy4:=gxy((t+dt),(x+dt*sx3),(y+dt*sy3));
x:=x+dt*(sx1+2*sx2+2*sx3+sx4)/6;
y:=y+dt*(sy1+2*sy2+2*sy3+sy4)/6;
t:=t+dt;
trajy:=trajy..(t,y);
exitif ((t>tstop) or (t>b) or (y<c) or (y>d));
endfor;
%Draw the paths x(t) and y(t) and clip them to bounding box
draw trajx xscaled ux yscaled uy withcolor red;
draw trajy xscaled ux yscaled uy withcolor red dashed evenly;
clip currentpicture to (q xscaled ux yscaled uy);
%Label graph x(t) and initial condition
len:= 0.65*(length trajx);
xt:=point len of trajx;
label.urt(textext("$\type{x(t)}$"), (xt xscaled ux yscaled uy));
%Label graph y(t) and initial condition
len:= 0.5*(length trajy);
yt:=point len of trajy;
label.lrt(textext("$\type{y(t)}$"), (yt xscaled ux yscaled uy));
%Initialize left and right endpoints on time-axis
L=(a*ux,0);R=(b*ux,0);
%Draw and label t-axis
drawarrow L--R;
label.rt(textext("$\type{t}$"),(b*ux,0));
%Initialize bottom and top endpoints on time-axis
B=(0,c*uy);T=(0,d*uy);
%Draw and label vertical axis
drawarrow B--T;
label.lft(textext("$\type{0}$"), B);
label.lft(textext("$\type{150}$"), T);
%endfig;
\stopuseMPgraphic
\startuseMPgraphic{ex2}
%beginfig(2);
%Make some variables local
save ux, uy;
%Place RHS of x'=f(t,x,y) here
def fxy(expr t, x, y)=
(0.4-0.01*y)*x
enddef;
%Place RHS of y'=g(t,x,y) here
def gxy(expr t, x, y)=
(-0.3+0.005*x)*y
enddef;
%Declare some variables
path q, trajxy;
pair L, R, B, T;
%Initialize clipping window
a:=0; b:=150; %left and right of viewing rectangle
c:=0; d:=100; %bottom and top of viewing rectangle
%Initialize timespan
tstart:=a;
tstop:=b;
%Initialize number of points to be plotted
N:=500;
%Calculate time increment dt for Euler's method
dt:=(tstop-tstart)/N;
%Scaling factors for horizontal and vertical axes. Note that this produces
%an image that is 2 inches by 2 inches.
(b-a)*ux=1.75in;
(d-c)*uy=1.75in;
%Clipping boundary
q=(a,c)--(b,c)--(b,d)--(a,d)--cycle;
%Use Runge-Kutta4 to create path (x(t),y(t))
%Choose initial condition
t:=tstart;
x:=40;
y:=20;
trajxy:=(x,y);
forever:
sx1:=fxy(t,x,y);
sy1:=gxy(t,x,y);
sx2:=fxy((t+dt/2),(x+dt*sx1/2),(y+dt*sy1/2));
sy2:=gxy((t+dt/2),(x+dt*sx1/2),(y+dt*sy1/2));
sx3:=fxy((t+dt/2),(x+dt*sx2/2),(y+dt*sy2/2));
sy3:=gxy((t+dt/2),(x+dt*sx2/2),(y+dt*sy2/2));
sx4:=fxy((t+dt),(x+dt*sx3),(y+dt*sy3));
sy4:=gxy((t+dt),(x+dt*sx3),(y+dt*sy3));
x:=x+dt*(sx1+2*sx2+2*sx3+sx4)/6;
y:=y+dt*(sy1+2*sy2+2*sy3+sy4)/6;
t:=t+dt;
trajxy:=trajxy..(x,y);
exitif ((t>tstop) or (t>b) or (x<a) or (x>b) or (y<c) or (y>d));
endfor;
%Draw the paths x(t) and y(t) and clip them to bounding box
draw trajxy xscaled ux yscaled uy withcolor red;
clip currentpicture to (q xscaled ux yscaled uy);
%Initialize left and right endpoints on x-axis
L=(a*ux,0);R=(b*ux,0);
%Draw and label x-axis
drawarrow L--R;
label.rt(textext("$\type{x}$"),(b*ux,0));
label.bot(textext("$\type{0}$"),L);
label.bot(textext("$\type{150}$"),R);
%Initialize bottom and top endpoints on y-axis
B=(0,c*uy);T=(0,d*uy);
%Draw and label vertical axis
drawarrow B--T;
label.rt(textext("$\type{y}$"),(0,d*uy));
label.lft(textext("$\type{0}$"), B);
label.lft(textext("$\type{100}$"), T);
%endfig;
\stopuseMPgraphic
\useMPgraphic{ex1}
\useMPgraphic{ex2}
\stoptext
[-- Attachment #1.2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
[-- Attachment #2: Type: text/plain, Size: 485 bytes --]
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
archive : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-12-11 23:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-11 20:15 MetaFun: MetaPost example works with `mpost` but not embedded in ConTeXt: `! Redundant equation.` Paul Menzel
2011-12-11 23:59 ` Marco
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).