Monday, December 24, 2012

Merry Christmath



MATLAB:

x = -4:.01:4;
a = 1.5;
p = @(x) (1+abs(x)./x)/2;
tree = {@(x) (10-a*abs(x)).*p(x+2).*p(2-x)
         @(x) 7*p(x-.6).*p(2-x) + 7*p(x+2).*p(-.6-x)
         @(x) (8-a*abs(x)).*p(x+3).*p(3-x).*(1-p(-x+1/a).*p(1/a+x))
         @(x) (6-a*abs(x)).*p(x+4).*p(4-x).*(1-p(1.7-x).*p(1.7+x))
         @(x) 3.5*p(x-1.7).*p(3-x) + 3.5*p(-x-1.7).*p(3+x)
         @(x) 0
         @(x) p(x+1.1).*p(-x+1.1).*(5*abs(x)-5.5).*(p(x-.9)+p(-x-.9))
         @(x) (p(x-1)-1).*p(x+1)};
hold on
for i = 1:length(tree)
   plot(x,tree{i}(x),'g.');
end
red_ornaments = [1 2 4 5 2 3 6 9 4 3 2 2 1];
cyan_ornaments = [1 .2 3 7.5 5 .5 6 1 .6 4 1];
plot(linspace(-3,3,length(red_ornaments)),red_ornaments, 'ro');
plot(linspace(-3,3,length(red_ornaments)),red_ornaments, 'r*');
plot(linspace(-3,3,length(cyan_ornaments)),cyan_ornaments, 'co');
plot(linspace(-3,3,length(cyan_ornaments)),cyan_ornaments, 'c*');
hold off
axis([-6, 6, -2, 10]);


There are certainly easier ways to plot this. I just wanted to have fun with absolute values.

No comments:

Post a Comment