Friday, December 22, 2017

SENATOR SCROOGE: A Digital Carol

Stan Letovsky, Dec 2017
With apologies to Charles Dickens

Marley was dead, that much was certain. Ebe had been to the funeral --open casket; he had even been a pallbearer. It was tragic, but it was undisputable. Marley was 100% dead.
               So how could he be messaging Ebe from his Facebook account?
Someone must have password access. But who? His wife, still grief-stricken over her husband’s untimely passing, would hardly be likely to be playing such games. Someone must have hacked it, clearly. But what did they want with Ebe?
               Ebe and Marley had been elected to the Senate the same year. They had shared similar political views and had cosponsored several pieces of legislation. That was many terms ago, now, and Marley had succumbed suddenly to pancreatic cancer, leaving Ebe to carry on alone. In recent years Ebe had become a leading member of the Senate faction that viewed it as their primary mission to comfort the comfortable and afflict the afflicted. Consequently, he often came in for criticism from certain segments of the public. Maybe this hacker was one of those, a liberal troll.
               Still, his laptop’s antivirus had been provided by the CIA. It couldn’t hurt to take a peek. Gingerly, he clicked to open the message. It read, simply: “Expect 3 communications”. Strange, Ebe thought. Didn’t sound like a political manifesto. Didn’t sound like much of anything, really. 3 communications. When? About what? Just a bunch of nonsense, Ebe thought. Just SPAM. Nothing to worry about. He had more important things to attend to. A tax bill was in the final stages of passage; it absolutely had to be signed before Christmas, which was just 3 days away. Ebe had work to do.
               Several hours later, deep in his email, he heard a chime from his laptop. A notification window appeared, announcing an email from Facebook. Odd, Ebe thought; I thought I turned off email notifications. The Subject line announced: “Facebook has compiled a Christmas Retrospective video just for you!” At first he was irritated at being interrupted, but then he thought, perhaps he could use a bit of distraction. The time, he noted, was exactly midnight. He clicked on the attachment.
               The video filled his screen. It was a collage of Christmas clips from his timeline, and those of his friends, arranged chronologically. Oh look – that was his first Christmas in the Senate, when he and Marley were working on that Banking Deregulation bill! What a bunch of idealists we were back then, he thought! Still we had a lot of fun. There’s Senator Fezziwig, who used to lead the monthly bipartisan breakfasts!  And oh look, its Jane, my old office manager: I wonder what happened to her. Probably still a do-gooder, chasing impossible dreams. Still she was rather attractive. Perhaps I should have asked her out, back then. No, she was too much of a leftie; she would never have gone for someone like me. Anyway, I probably would have ended up getting sued for harassment.
               The video continued, flipping through Senate Christmas parties of his first term, then his second. The rightward drift in Ebe’s politics was evident in the changing faces in the selfies: his colleagues faces, and his own, became older, meaner, drunker.
               Finally it ended, leaving Ebe blinking back tears. Nonsense, he said aloud. Who needs these stupid autogenerated memorabilia? He would definitely shut down his Facebook account: right after the New Year.
               The next day he was on the Senate floor all morning, speaking out in support of the Tax Bill, and registering procedural votes to pave the way for final passage. This bill, a signature piece of legislation for his party, would put an end, once and for all, to the sickening whining liberals and their idiotic programs. It would transfer $1.5 trillion dollars from the treasury to the people who truly deserved it: the captains of industry, landowners, and people from the right families.
               After some early evening drinks with his colleagues at the Senate club, he retired to his office to catch up on email. His phone rang; it was his nephew Fred, who lived in Georgetown with his family. “Hiya Unk!” came Fred’s voice on the phone. “What is it?” Ebe replied, curtly. Fred was a relative, so Ebe felt duty-bound to take his calls, but was also a liberal, unable to confine his society to his own race and class. The last time Ebe had attended one of Fred’s Christmas parties he felt like he was in a third world country. “We were hoping you might join us for Christmas dinner.” “We”, Ebe shuddered. Even worse – that wife of his, a laywer for the ACLU. As if she would want him in her house. Still, she always managed to fake a pleasant smile, pretending she could stand him. Humbug. “Too busy; tax bill; deadline” mumbled Ebe, and hung up.
                He pressed the intercom button on his phone and yelled “Bob!” His secretary stuck his head on the door: “Yes boss?” “See that there are no more calls tonight—I don’t want to be disturbed.” “Yes boss.” Bob Cratchit shifted his weight. “Ah boss, would it be OK if I knocked off for the night? I got to do a bit of Christmas shopping for Tim.” Oh there he goes – always playing the Tim card. So he’s got a kid with muscular dystrophy. Big deal. We all have problems. You should be glad you have healthcare – for the moment. “Have you finished the revisions to the language on deductions for purchases of second yachts?” Ebe asked. “Almost, boss, but I can easily knock those off before…”. “Finish them first, then do your shopping. We have the nation’s business to conduct.”
               Some hours later Ebe heard the sounds of Cratchit shutting down the outer office for the night. Ebe yawned. “Should probably be heading home myself”, he thought. He was about to close his laptop when it emitted a soft chime. Reflexively, Ebe glanced at his phone: 12 midnight, again. What now? It was his newsfeed, announcing the arrival of the daily digest. He clicked, disinterestedly: if anything important were happening he would already know about it. Hmm… Saber rattling by North Korea. Nothing new there. Oh look – a shot of me doing that speech this morning – not bad actually; usually they get you with your eyes squinting…What’s that? Bunch of do-gooders running some sort of soup kitchen in Southeast DC. Wait – could that be? Why it is -- its Fred, the fool! Oh and there’s that wife of his. If I were married I wouldn’t bring my wife to… Now, that one looks familiar – where do I know her from? Why, I do believe that’s Jane, my old office manager. I was just thinking about her the other day. She looks the same as ever – a touch older, perhaps. What would she be doing with Fred and his lot? Of course, she always was a sucker for the undeserving.
               Well, enough of this nonsense, thought Ebe. Time to get home to bed. Busy day tomorrow. With any luck they could get the votes lined up for a final vote in two days, right before Christmas.
               The next day sped by in conference committee meetings. It was strange, making changes to the language of a bill no one had actually read. Everyone was clamouring to get in one last loophole to reward their donors. Of course some things had to be cut to make room – everything had to balance, except for the one-and-half trillion, of course. Tax breaks for the bottom 80% -- cut those in half, they won’t notice. Health care in the out years. Funding for muscular dystrophy research – those fool scientists think they know everything. Stroke of the pen – gone! Serve them right. Ebe had a sudden mental image of Bob Cratchit’s son Tim – a sweet enough lad, to be sure; very sad the way his muscles were wasting away. Still – not my fault; survival of the fittest and all that.  
               By late evening, the job was done: the conference bill was complete, ready for a vote the next day. Ebe felt satisfied. He went to the Senate gym to burn off some excess energy; at that hour only a few people were here. He jumped onto a stationary bike, put on his headphones and played Wagner’s Ring on his phone.  Lost in the music, he pedaled over 5 miles and 200 calories. Suddenly his phone buzzed with a text message. Unidentified Caller. Curious. And 12:00, again! Could this be one of those “communications” Marley’s message had promised? The message had a link: “click here”, it said. Nothing else – no indication of where the link  led. Ebe started to click, but noticed his hand was shaking. Nonsense.  A link can’t hurt me. He clicked.
               A YouTube video started: a special Christmas edition of Breitbart News – but they had the date wrong, it was 10 years in the future! That would be when all the paltry handouts to the poor they had inserted into the tax bill as bait would have expired, leaving only the large benefits for the truly deserving. The video showed crowds of people sleeping under bridges, shivering in the cold. Medical clinics with their doors boarded up. The voiceover assured the viewer that these people were simply reaping the just rewards of their lack of individual initiative, and besides, most of them were probably foreigners, or not white, maybe both! The scene shifted to a soup kitchen, not unlike the one on the news feed the night before, only now with ten, maybe a hundred times as many people lined up. The woman with the ladle looked a bit like – yes, it is, its Jane – but older, grimmer, more haggard.  Poor thing, I wonder what’s happened to her. As the camera panned down the line, Ebe recognized one of the faces – why that’s Bob, Bob Cratchit! I wonder what he’s doing in a place like that. Surely we pay him enough to buy food! He looks so sad -- I wonder if something happened to little Tim?
             The scene shifted again, this time to a funeral procession – someone important, obviously: a horse-drawn hearse, surrounded by men in brown uniforms with armbands, goose-stepping in ranks, except for the ones at the edges, who were swinging billy clubs to keep the rabble away. The scrolling banner at the bottom of the screen announced “Protesters and Neo-Nazis Clash at the Funeral of President Ebenezer Scrooge”. What the hell is this, Ebe thought? Some kind of sick joke? He paused the video, switched back to his text messages and replied to the message from Unidentified, typing frantically with both thumbs: “Who is this”? No answer. “What do u want?” A hand emoticon appeared in reply, index finger pointing to the right. What on earth is that supposed to mean? Keep watching, maybe? Ebe returned to the YouTube app and pressed play.
               The funeral procession was now at the grave site; a casket was being lowered. The neo-Nazis were holding an unruly crowd at bay some distance from the grave. The camera panned over some of the faces: many looked angry, with raised fists and shouted imprecations. Some carried signs – “Not soon enough”, said one, and “Rot in Hell” said another. A few looked like they were actually sad – a woman, all in black, lifted her veil for a moment, and he recognized Jane. Why would she be coming to his funeral – and why in mourning? Could it be that, in some strange way, she cared for him?
               Suddenly his phone ran out of power, and the video came to an abrupt end. Ebe’s mind was a tumult of confused thoughts and feelings. Perhaps the bill was too regressive. Maybe he should reconsider his support. The Senate was balanced on the edge of a knife; if he were to withhold his vote it would be enough to stop the bill. What a Christmas present that would be for the nation. Perhaps that horrible Breitbart future could still be averted! Perhaps he should go to Fred’s party after all. He could ask Jane to be his date!
               Then again: what was that about President Scrooge?

THE END


Wednesday, December 20, 2017

Tax Bill Impact

Most analyses of the Republican tax bill make statements of the form "if you make X $/yr your tax bill will go down/up by Y%", i.e., they focus on the impact on an individual. I have been curious how the total tax reductions will be distributed.  I found this analysis which provides some answers. Using table 1, I was able to construct the following “cui bono” or “follow the money” pie-chart of the 2018 tax benefits. It shows 65% of the money going to the top 20% of the income distribution, and 2/3 of that going to the top 5%.



Switching to bar graphs to show multiple years, and to allow for negative benefits to certain (lower income) groups in the later years, yielded the following, which shows shows how a benefit that is initially skewed to the wealthy becomes even more so over time.

If we divide each slice by the size of the group, we get a per person score – the units are proportional to dollars/person, but I don’t have the info needed to get the multiplier. This shows most clearly the impact, and intent, of the policy: to borrow $1.5T from America’s children and give it to Republican donors. 


Saturday, August 27, 2016

Euler's Formula: A matLab tutorial

This tutorial was developed in MatLab for my daughter Penelope as a companion to chapter 4 of Robert Crease's The Great Equations, on Euler's Equation. Euler was a legendary calculator who spent his entire life doing calculations. Imagine if he had had MatLab!

Contents


Basic MatLab


Stuff entered into MatLab is shown in the grey boxes; MatLab's responses are shown below.

a value

1
ans =

     1

an expression

1+1
ans =

     2

assigning to a variable

x=1+1
x =

     2

recalling a variable

x
x =

     2

; after means don't show the results

x=1+1;

a complicated expression showing *, exponentiation, grouping

x=1+2*2+3^2+(5-3)/1.7
x =

   15.1765

calling a named function

factorial(4)
ans =

    24

a row vector

x=[4,1,7,1]
x =

     4     1     7     1

transpose operator ' turns a row into a column

x=[4,1,7,1]'
x =

     4
     1
     7
     1

: operator generates regularly spaced vectors

0:5
-3:.1:2
ans =

     0     1     2     3     4     5


ans =

  Columns 1 through 7

   -3.0000   -2.9000   -2.8000   -2.7000   -2.6000   -2.5000   -2.4000

  ...
  Columns 50 through 51

    1.9000    2.0000

Factorial can be applied to a vector

factorial(0:5) % returns a vector of factorials
ans =

     1     1     2     6    24   120

Euler's series for e


See also wikipedia

Note MatLab notation ./ to mean elementwise division of a vector. If you just use / it means something else.

n=10; % generate 10 terms in series
1./factorial(0:n) % returns terms in series
ans =

  Columns 1 through 7

    1.0000    1.0000    0.5000    0.1667    0.0417    0.0083    0.0014

  Columns 8 through 11

    0.0002    0.0000    0.0000    0.0000

sum up terms

sum(1./factorial(0:n))
ans =

    2.7183

sum is same as e

e=exp(1)
e =

    2.7183
 

which also happens to be 

Limit

nn=1:10000;
limit=(1+1./nn).^nn; % converges very slowly
limitStart=limit(1:20)
limitEnd=limit(end)
limitStart =

  Columns 1 through 7

    2.0000    2.2500    2.3704    2.4414    2.4883    2.5216    ...


limitEnd =

    2.7181

plot series and limit for e

clf
x=0:n;
plot(x,series,'*--'); hold on; plot(x,cumsum(series),'*--'); plot(xlim,exp(1)*[1,1],'y'); plot(nn(1:10),limit(1:10),'c*-'); hold off;
legend('terms','sum','e','limit (scaled)','location','SE'); title('Euler''s series for e'); shg

generate powers of x using a vector exponent

x=5; % pick a value of x
x.^(0:5)
ans =

           1           5          25         125         625        3125

Euler's series for e^x

series=x.^(0:n)./factorial(0:n)
series =

  Columns 1 through 7

    1.0000    5.0000   12.5000   20.8333   26.0417   26.0417   21.7014

  Columns 8 through 11

   15.5010    9.6881    5.3823    2.6911

sum it up, get exp(x) (almost -- need more terms)

sum(series)
exp(x) % e^x
clf; plot(0:n,series); hold on; plot(0:n,cumsum(series)); plot(xlim,exp(x)*[1,1],'y--'); hold off; shg
ylim(ylim*1.2);
title(sprintf('Euler series for e^{%3.2f}',x));
ans =

  146.3806


ans =

  148.4132

exponential and log

x=-5:.1:5;     subplot(1,2,1); plot(x,exp(x)); title('y=e^x=exp(x)');
x=[.1,1:100];  subplot(1,2,2); plot(x,log(x)); title('y=log_e(x)=ln(x)');

other bases

clf
x=-1:.1:2;     subplot(1,2,1); plot(x,[2.^x;exp(x);10.^x]); legend('2^x','e^x','10^x'); title('Exponentials with different bases');
x=[.1,1:100]; subplot(1,2,2); plot(x,[log2(x);log(x);log10(x)]'); legend('log_2(x)','log_e(x)','log_{10}(x)','location','SE');  title('Logs with different bases');
shg

sin and cos

degreesPerRadian=360/(2*pi); % multiplier to convert radians to degrees
radiansPerDegree=1/degreesPerRadian;
subplot(2,2,1);
x=-pi:.1:2*pi; % in radians
plot(x*degreesPerRadian,sin(x)); title('y=sin(x)'); xlabel('degrees'); settick('X',90*[-2:4]);
line(xlim,[0,0],'color','k');  line([0,0],[-1,1],'color','k');
% line(90*[1,1],[-1,1],'color','y'); line(180*[1,1],[-1,1],'color','y'); line(270*[1,1],[-1,1],'color','y');
settick('X',90*[-2:4]);
subplot(2,2,2);
plot(x*degreesPerRadian,cos(x)); title('y=cos(x)'); xlabel('degrees'); settick('X',90*[-2:4]);
line(xlim,[0,0],'color','k');  line([0,0],[-1,1],'color','k');

subplot(2,2,3); plot(x*degreesPerRadian,[sin(x);cos(x)]'); legend('sin(x)','cos(x)'); xlabel('degrees');  settick('X',90*[-2:4]); shg
line(xlim,[0,0],'color','k');  line([0,0],[-1,1],'color','k');
title('sin(x) = cos(x - 90^o)');

subplot(2,2,4); plot(x.^2.*sin(x.^2)); title('Random complicated expression: x^2sin(x^2)');
line(xlim,[0,0],'color','k');  line([0,0],[-1,1],'color','k');

sin vs cos

close all; w=-10:.1:10;
plot(sin(w),cos(w)); axis square; xlabel('sin(w)'); ylabel('cos(w)');  shg

tan

clf
x=-360:360;
plot(x,tan(x/degreesPerRadian)); ylim([-10,10]); shg

animate circle, sin, cos, tan

if(false) % don't use with MatLab's publish; won't work
    close all; w=-10:.1:10;% fullscreen;
    clear M;
    sinw=sin(w); cosw=cos(w);
    x=0:360; xr=x*radiansPerDegree; sinx=sin(xr); cosx=cos(xr); tanx=tan(xr); shg
    for i=0:360;
        r=i*radiansPerDegree; sinr=sin(r); cosr=cos(r); tanr=tan(r);
        subplot(2,2,1);  plot(sinw,cosw,'-',[0,cosr],[0,sinr],'-',cos(r),sinr,'*'); axis square; xlabel('sin(w)'); ylabel('cos(w)');
        subplot(2,2,2);  plot(x,sinx,'-',i,sin(r),'*'); title('sin(w)');
        subplot(2,2,3);  plot(x,cosx,'-',i,cos(r),'*'); title('cos(w)');
        subplot(2,2,4);  plot(x,tanx,'-',i,tanr,'*'); ylim([-5,5]); title('tan(w)');
        drawnow;
        M(i+1)=getframe(gcf);
    end
    % create an movie of the animation
    vw= VideoWriter('pers/Trig.avi');
    open(vw);
    writeVideo(vw,M);
    close(vw) % then use MakeAGif.com to convert to animated gif
end
irrationals & complex numbers

sqrt(-1)
ans =

   0.0000 + 1.0000i

MatLab defines symbol i to mean sqrt(-1)

clear i; % restore i to its mathematical meaning rather than a variable
i
ans =

   0.0000 + 1.0000i

i^2 = -1

i^2
ans =

    -1

you can make any complex # you want

3*i+2
ans =

   2.0000 + 3.0000i

One way to make alternating signs

(-1).^(0:n)
ans =

     1    -1     1    -1     1    -1     1    -1     1    -1     1

Generate an odd numbered series

1:2:10
ans =

     1     3     5     7     9

Euler series for sin

n=10;
ii=1:2:n; % odd term indices
x=.8; % a random # to find the sin of
sign=(-1).^(0:length(ii)-1)
num=x.^ii
denom=factorial(ii)
series=sign.*num./denom
sumSeries=sum(series)
sinx=sin(x)
clf; plot(ii,series,'*--',ii,cumsum(series),'*--',[min(ii),max(ii)],sinx*[1,1],'y');
legend('terms','sum','sin(x0','location','SE'); title(sprintf('Euler''s series for sin(%3.2f)',x)); shg
sign =

     1    -1     1    -1     1


num =

    0.8000    0.5120    0.3277    0.2097    0.1342


denom =

           1           6         120        5040      362880


series =

    0.8000   -0.0853    0.0027   -0.0000    0.0000


sumSeries =

    0.7174


sinx =

    0.7174

Euler series for cos

n=10;
ii=0:2:n;  % even term indices
x=.8; % a random # to find the sin of
sign=(-1).^(0:length(ii)-1)
num=x.^ii
denom=factorial(ii)
series=sign.*num./denom
sumSeries=sum(series)
cosx=cos(x)
sign =

     1    -1     1    -1     1    -1


num =

    1.0000    0.6400    0.4096    0.2621    0.1678    0.1074


denom =

           1           2          24         720       40320     3628800


series =

    1.0000   -0.3200    0.0171   -0.0004    0.0000   -0.0000


sumSeries =

    0.6967


cosx =

    0.6967

Euler series for e^ix

x=.736; % a random x
n=10
ii=0:n
num=(i*x).^ii
denom=factorial(ii)
series=num./denom
sumSeries=sum(series)
cosx=cos(x)
sinx=sin(x)
clf; plot(ii,real(series),'*--',ii,imag(series),'*--',ii,real(cumsum(series)),'^--',ii,imag(cumsum(series)),'^--');
legend('real component of terms','imaginary component  of terms','real component of sum','imaginary component  of sum','location','SE');
title(sprintf('Euler''s series for e^{%3.2fi}',x)); shg
n =

    10


ii =

     0     1     2     3     4     5     6     7     8     9    10


num =

  Columns 1 through 4

   1.0000 + 0.0000i   0.0000 + 0.7360i  -0.5417 + 0.0000i   0.0000 - 0.3987i

  Columns 5 through 8

   0.2934 + 0.0000i   0.0000 + 0.2160i  -0.1590 + 0.0000i   0.0000 - 0.1170i

  Columns 9 through 11

   0.0861 + 0.0000i   0.0000 + 0.0634i  -0.0466 + 0.0000i


denom =

  Columns 1 through 6

           1           1           2           6          24         120

  Columns 7 through 11

         720        5040       40320      362880     3628800


series =

  Columns 1 through 4

   1.0000 + 0.0000i   0.0000 + 0.7360i  -0.2708 + 0.0000i   0.0000 - 0.0664i

  Columns 5 through 8

   0.0122 + 0.0000i   0.0000 + 0.0018i  -0.0002 + 0.0000i   0.0000 - 0.0000i

  Columns 9 through 11

   0.0000 + 0.0000i   0.0000 + 0.0000i  -0.0000 + 0.0000i


sumSeries =

   0.7412 + 0.6713i


cosx =

    0.7412


sinx =

    0.6713

Euler series for e^i*pi

x=pi % a not-so-random x
n=20
ii=0:n
num=(i*x).^ii
denom=factorial(ii)
series=num./denom
sumSeries=sum(series)
cosx=cos(x)
sinx=sin(x)
fprintf('QED!!!!!');
x =

    3.1416


n =

    20


ii =

  Columns 1 through 13

     0     1     2     3     4     5     6     7     8     9    10    11    12

  Columns 14 through 21

    13    14    15    16    17    18    19    20


num =

   1.0e+09 *

  Columns 1 through 4

   0.0000 + 0.0000i   0.0000 + 0.0000i  -0.0000 + 0.0000i   0.0000 - 0.0000i

  Columns 5 through 8

   0.0000 + 0.0000i   0.0000 + 0.0000i  -0.0000 + 0.0000i   0.0000 - 0.0000i

  Columns 9 through 12

   0.0000 + 0.0000i   0.0000 + 0.0000i  -0.0001 + 0.0000i   0.0000 - 0.0003i

  Columns 13 through 16

   0.0009 + 0.0000i   0.0000 + 0.0029i  -0.0091 + 0.0000i   0.0000 - 0.0287i

  Columns 17 through 20

   0.0900 + 0.0000i   0.0000 + 0.2828i  -0.8886 + 0.0000i   0.0000 - 2.7916i

  Column 21

   8.7700 + 0.0000i


denom =

   1.0e+18 *

  Columns 1 through 7

    0.0000    0.0000    0.0000    0.0000    0.0000    0.0000    0.0000

  Columns 8 through 14

    0.0000    0.0000    0.0000    0.0000    0.0000    0.0000    0.0000

  Columns 15 through 21

    0.0000    0.0000    0.0000    0.0004    0.0064    0.1216    2.4329


series =

  Columns 1 through 4

   1.0000 + 0.0000i   0.0000 + 3.1416i  -4.9348 + 0.0000i   0.0000 - 5.1677i

  Columns 5 through 8

   4.0587 + 0.0000i   0.0000 + 2.5502i  -1.3353 + 0.0000i   0.0000 - 0.5993i

  Columns 9 through 12

   0.2353 + 0.0000i   0.0000 + 0.0821i  -0.0258 + 0.0000i   0.0000 - 0.0074i

  Columns 13 through 16

   0.0019 + 0.0000i   0.0000 + 0.0005i  -0.0001 + 0.0000i   0.0000 - 0.0000i

  Columns 17 through 20

   0.0000 + 0.0000i   0.0000 + 0.0000i  -0.0000 + 0.0000i   0.0000 - 0.0000i

  Column 21

   0.0000 + 0.0000i


sumSeries =

  -1.0000 - 0.0000i


cosx =

    -1


sinx =

   1.2246e-16

i.e., exp(i*pi)+1=0 QED!!!


Series for ln(x)=log_e(x)

See bottom formula of first table here
x=1.357;
y=(x-1)/(x+1)
ii=1:2:n % odd terms only
series=2*y.^ii./ii
sumSeries=sum(series)
log(x)
y =

    0.1515


ii =

     1     3     5     7     9


series =

    0.3029    0.0023    0.0000    0.0000    0.0000


sumSeries =

    0.3053


ans =

    0.3053

Leibnitz' series for pi

See wikipedia
n=10000 % this one converges verrrrry slowly
ii=1:2:n; display(ii(1:10)); % odd terms only. show only first few.
sign=(-1).^(0:length(ii)-1); display(sign(1:10));
series=4*sign./ii; display(series(1:10));
sumSeries=sum(series)
pi
k=20;
plot(ii(1:k),series(1:k),'-',ii(1:k),cumsum(series(1:k)),'-',[min(ii),k],pi*[1,1],'y');
legend('terms','sum','pi'); shg
n =

       10000


ans =

     1     3     5     7     9    11    13    15    17    19


ans =

     1    -1     1    -1     1    -1     1    -1     1    -1


ans =

  Columns 1 through 7

    4.0000   -1.3333    0.8000   -0.5714    0.4444   -0.3636    0.3077

  Columns 8 through 10

   -0.2667    0.2353   -0.2105


sumSeries =

    3.1414


ans =

    3.1416