Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Solution 304756

Submitted on 15 Aug 2013 by Erin

Correct

148Size
Leading solution size is 45.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test
Code Input and Output
1
Pass
 
N={'Mercury','Venus','Earth','Mars','Jupiter',...
   'Saturn','Uranus','Neptune','Pluto'};
P=[0.5000 1.9246 365.2425 668.5950 10471.0182 ...
   24204.8198 42582.9327 89087.3743 14183.7398];
for i=1:9
   p=P(i);
   m=leapsequence(p);
   n=numel(m);
   r=dot(1./m,(-1).^(0:n-1));
   disp([N{i} ' p=' num2str(p,'%0.6f') ...
    ' r=' num2str(r,'%0.6f') ' m=' mat2str(m)])
   assert(abs(floor(p)+r-p)<=0.00005);
   assert(all(m>0))
   assert(all(mod(m,1)==0))
   assert(all(mod([m 0],[1 m])==0))
end
Mercury p=0.500000 r=0.500000 m=2
Venus p=1.924600 r=0.924600 m=[1 13 650 65000]
Earth p=365.242500 r=0.242500 m=[4 132 13200]
Mars p=668.595000 r=0.595000 m=[1 2 10 200]
Jupiter p=10471.018200 r=0.018199 m=[54 3132]
Saturn p=24204.819800 r=0.819800 m=[1 5 50 5000]
Uranus p=42582.932700 r=0.932699 m=[1 14 238 13566]
Neptune p=89087.374300 r=0.374294 m=[2 6 24 1416]
Pluto p=14183.739800 r=0.739800 m=[1 3 12 96 4608]