Mahery Raharinjatovo escribi?:
> Hello,
> I need help
> I made the program below
> I would want to plot the curve define by points of coordinates (t,v)
>
> chute():=block([g,k,r,rho,rhoh,vm,V,v],
> g:9.8,
> k:9.33/100,
> rho:2400,
> rhoh:950,
> r:1.5/1000,
> V:(4/3)*3.14*r*r*r,
> vm:(g*rho*V/k)*(1-rhoh/rho),
> dt:1.5/10000,
> a:-k/(rho*V),
> b:g*(1-(rhoh/rho)),
> v:0,t:0,
> while v<0.999*vm do (print(v,"?",t),dv:(a*v+b)*dt,v:v+dv,t:t+dt)
> )$
Hello Mahery,
The output should be a list of pairs, don't use 'print' if you want to
use the output as input for other functions. Here is a new version of
'chute':
chute():=
block([g,k,r,rho,rhoh,vm,V,v,dt,a,b,
pairs:[]],
g:9.8,
k:9.33/100,
rho:2400,
rhoh:950,
r:1.5/1000,
V:(4/3)*3.14*r*r*r,
vm:(g*rho*V/k)*(1-rhoh/rho),
dt:1.5/10000,
a:-k/(rho*V),
b:g*(1-(rhoh/rho)),
v:0,t:0,
while v<0.999*vm do (
pairs: cons([t,v],pairs),
dv:(a*v+b)*dt,
v:v+dv,
t:t+dt),
pairs)$
Remember that the result of the last sentence is also the result of the
function.
After this redefinition, you can play with something similar to:
/* store the result in a variable for later use */
my_pairs: chute()$
/* load package draw and set value 4 to global
variable fpprintprec for pretty print */
load(draw)$
fpprintprec : 4$
/* build the labels. Maybe you want to read
documentation on functions apply, map and lambda*/
my_labels:
apply (label,
map (lambda([z], [string(z), z[1], z[2] + 0.0001]), my_pairs));
/* call draw2d */
draw2d(points(my_pairs),
my_labels)$
This is a minimalistic piece of code; you can fine-tune the output with
some extra drawing options. Type
? points
and
? label
for ideas.
--
Mario Rodriguez Riotorto
http://www.telefonica.net/web2/biomates