# Lab sheet 4

## Parametric plotting

Exercise 1.1

wxplot2d([parametric,cos(10*t)/(1+t^2),sin(10*t)/(1+t^2),[t,-5,5]],[same_xy]);

wxplot2d([parametric,sin(3*t),sin(2*t),[t,0,2*%pi]],[same_xy],[box,false],[axes,false]);

wxdraw(gr2d(
  nticks=100,
  proportional_axes='xy,
  xtics=false,ytics=false,
  axis_top=false,axis_bottom=false,axis_left=false,axis_right=false,
  color=red,
  parametric(sin(3*t),sin(2*t),t,0,2*%pi)
));

wxplot2d([parametric,t-sin(t),1-cos(t),[t,0,8*%pi]],[same_xy],[box,false],[axes,false]);

wxplot2d([parametric,2*t/(1+t^2),(1-t^2)/(1+t^2),[t,-10,10]],[same_xy]);

Exercise 2

x: 4*t^2-1; y: 8*t^3-8*t;

pic1: [color=red,nticks=100,parametric(x,y,t,-1.5,1.5)]$
wxdraw(apply(gr2d,pic1));

pic2: [color=blue,explicit((X-3)*sqrt(X+1),X,-1,8)]$
wxdraw(apply(gr2d,append(pic1,pic2)));

map(lambda([e],subst(e,[t,x,y])),solve(y=0,t));

kill(x,y)$

## Implicit plotting

Exercise 2.1

wxdraw2d(ip_grid=[200,200],implicit(y^2=x^3-x,x,-1.5,3,y,-3,3));

a0:2/3^(3/2),float;

wxdraw(gr2d(
        ip_grid=[100,100],
        color=red,
        implicit(y^2=x^3-x+a0,x,-1.5,2,y,-3,3),
        color=blue,
        implicit(y^2=x^3-x+a0+0.1,x,-1.5,2,y,-3,3),
        color=green,
        implicit(y^2=x^3-x+a0-0.1,x,-1.5,2,y,-3,3)
    ));

Exercise 2.2

z : x^2 + y^2 + a * (sin(2*%pi*x)+cos(2*%pi*y));

wxdraw(
 gr2d(ip_grid=[200,200],proportional_axes=xy,implicit(subst(a=1 ,z)=100,x,-15,15,y,-15,15)),
 gr2d(ip_grid=[200,200],proportional_axes=xy,implicit(subst(a=5 ,z)=100,x,-15,15,y,-15,15)),
 gr2d(ip_grid=[200,200],proportional_axes=xy,implicit(subst(a=20,z)=100,x,-15,15,y,-15,15)),
 columns=3
);

## Plotting lists of points

Exercise 4.1

vals: [10,40,20,30,50,10,20];

makelist([i,vals[i]],i,1,length(vals));

wxdraw(gr2d(xrange=[0,8],yrange=[0,60],points(makelist([i,vals[i]],i,1,length(vals)))));

wxdraw(gr2d(xrange=[0,8],yrange=[0,60],points_joined=true,point_type=filled_circle,
              points(makelist([i,vals[i]],i,1,length(vals)))));

Exercise 3.2

N:1000$

primes:[2]$ for i from 2 thru N do (primes : cons(next_prime(primes[1]),primes))$
primes : reverse(primes)$

wxdraw(gr2d(
        points(makelist([i,primes[i]],i,1,N)),
        color=red,
        explicit(x*(log(log(x)) + log(x) - 1),x,1,N)
));

kill(N)$

Exercise 3.3

20!;

1.0 * 20!;

f(x) := sqrt(2*%pi) * x^(x + 1/2) * exp(-x);

wxdraw(gr2d(
        points(makelist([i,log(i!)],i,1,20)),
        color=red,
        explicit(log(f(x)),x,1,20)
));

kill(f)$

Exercise 3.4

q(c,x) := c * x * (1 - x);

f(n,c) := block([],if n = 0 then return(0.5) else return(q(c,f(n-1,c)))); 

F(n,c) := block(
  l :[[0,0.5]],
  for i from 1 thru n do (l : cons([i,q(c,l[1][2])],l)),
  return(reverse(l))
);

wxdraw(gr2d(points(F(500,3.44))));