28 for i = 1:ncalcs(j)
29 r2 = (x 2 –x 1)ˆ2 + (y 2–y 1)ˆ2 + (z 2 –z 1)ˆ2;
30 r2inv = 1/r2;
31 r6inv = r2inv*r2inv*r2inv;
32 r12inv = r6inv*r6inv;
43 legend(‘Method 1’,‘Method 2’,‘Location’,‘NorthWest’)
44 xlabel(‘Number of calculations’,‘FontSize’,14)
45 ylabel(‘Time for the calculation (s)’,‘FontSize’,14)
46 title(‘Solution to s12c3p2’,‘FontSize’,14)
47 saveas(h,‘s12c3p2 solution figure.eps’,‘psc2’)
101102103104105106107108
10−6
10−5
10−4
10−3
10−2
10−1
100
101
102
Numb e r of calc ulations
T im e f or t he c alc ula tio n ( s)
Solution t o s12c 3p2
M e t h o d 1
M e t h o d 2
(1.40) The Matlab script and output files for this problem are available in the folder s10c1p1 matlab.
1function [value sum,n terms]= s10c1p1
2%the output for this value is
3%value sum = 3.141592637882101