/
ValentinesDay.m
53 lines (43 loc) · 1.11 KB
/
ValentinesDay.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
%% Happy Valentines Day!
% Anonymous, February 2012
%%
% (Chebfun example fun/ValentinesDay.m)
% [Tags: #gift, #heart]
%%
% Happy Valentine's Day to all Chebfun users!
t = chebfun('t',[-pi pi]);
x = 16*sin(t).^3;
y = 13*cos(t)-5*cos(2*t)-2*cos(3*t)-1*cos(4*t);
fill(x,y,'.-r'); axis equal
hold on
plot(12.5*scribble('Happy Valentine''s Day!'),'k')
hold off
axis equal off
%%
% This 'heart curve' can be found on Wolfram's MathWorld site [1], where
% its area is computed. We do the same, and compare the result:
z = x+1i*y;
A = abs(sum(x.*diff(y)))
err = A - 180*pi
%%
% Here are some more heart curves that can be found in [1]:
%%
% Heart eqn 1
t = chebfun('t',[-pi pi]);
r = 1-sin(t);
[x1 y1] = pol2cart(t,r);
plot(x1,y1,'.-r')
axis equal off
A1 = abs(sum(x1.*diff(y1)))
err = A1-3*pi/2 % Note, this is A2 on [1]!
%%
% Heart eqn 5
t = chebfun('t',[-pi pi]);
r = 2 - 2*sin(t)+sin(t).*sqrt(abs(cos(t))+.1)./(sin(t)+1.4);
[x5 y5] = pol2cart(t,r);
plot(x5,y5,'.-r')
axis equal off
A5 = abs(sum(x5.*diff(y5))) % Note, different from [1] was we include .1 in sqrt
%% References
%
% 1. http://mathworld.wolfram.com/HeartCurve.html