## Plucked string in R

T(x):=if abs(x)<1 then 1-abs(x) else 0;

T(0.4);T(6);

wxplot2d([T(t)], [t,-5,5])$

u(t,x):=(T(x-t)+T(x+t))/2;

wxplot2d([u(0,x),u(0.2,x),u(0.5,x), u(0.8,x),u(1,x),u(1.5,x)], [x,-5,5],
[legend, "u(0,x)","u(0.2,x)","u(0.5,x)","u(0.8,x)","u(1,x)","u(1.5,x)"])$

with_slider(t,makelist(i,i,0,1.5,.1),[u(t,x)],[x,-3,3],[y,0,1]);

Al principio la onda original baja y se expande, 
y al llegar a altura 1/2 se va separando en dos ondas viajeras 

## Plucked string in 0<x<1 with fixed extremes

f(x):=if x>0 and x<0.5 or x=0.5 or x=0 then x else if x>0.5 and x<1 or x=1 then 1-x else 0;

tf(x):= if x>0 and x<1 or x=0 or x=1 then f(x) else if x>-1 and x<0 or x=-1 then -f(-x) else 0;

ttf(x):= if x>-1 and x<1 or x=-1 or x=1 then tf(x) else if x>1 and x<3 then tf(x-2) else if x>-3 and x<-1 then tf(x+2) else 0 ;

f(1/2);f(0.5);ttf(2.5);ttf(5/2);

wxplot2d([ttf(x)], [x,-1,3],[legend,"odd periodic extension"])$

u(t,x):=(ttf(x-t)+ttf(x+t))/2;

wxplot2d([u(0,x),u(.2,x),u(.4,x),u(.5,x),u(1,x)], [x,0,1],
[legend,  "u(0,x)","u(0.2,x)","u(0.4,x)","u(0.4,x)","u(1,x)"])$

with_slider(t,makelist(i,i,0,2,.1),[u(t,x)],[x,0,1],[y,-0.6,0.6]);

La onda estacionaria baja y sube progresivamente de forma simétrica

## Plucked string with fixed extremes: 
non symmetric case (ejercicio 2)

g(x):=if x>0 and x<1/3 or x=1/3 or x=0 then 3*x else if x>1/3 and x<1 or x=1 then 3/2*(1-x) else 0;

tg(x):= if x>0 and x<1 or x=0 or x=1 then g(x) else if x>-1 and x<0 or x=-1 then -g(-x) else 0;

ttg(x):= if x>-1 and x<1 or x=-1 or x=1 then tg(x) 
else if x>1 and x<3 then tg(x-2) 
else if x>-3 and x<-1 then tg(x+2) else 0 ;

g(1/3);g(0.5);ttg(2.5);ttg(5/2);

wxplot2d([ttg(x)], [x,-1,3],[legend, "odd periodic extension"])$

u(t,x):=(ttg(x-t)+ttg(x+t))/2;

wxplot2d([u(0,x),u(.2,x),u(1/3,x),u(.4,x),u(.5,x),u(0.9,x),u(1,x)], [x,0,1],
[legend,  "u(0,x)","u(0.2,x)","u(1/3,x)","u(0.4,x)","u(0.5,x)","u(0.9,x)", "u(1,x)"])$

with_slider(t,makelist(i,i,0,2,.1),[u(t,x)],[x,0,1],[y,-1.1,1.1]);

La onda (estacionaria) baja y sube de manera asimétrica, 
desplazando el pico a dcha e izda sucesivamente.
Observar que por la izquierda la pendiente es 3, por la dcha -3/2,
y en el centro el promedio entre ambas  (3-3/2)/2 = 3/4 