# Integration Revision

Let's plot a curve as a a series of bars and a line.

x1=<span style="color: #ff0000;">[</span>1<span style="color: #ff0000;">:</span>10<span style="color: #ff0000;">]</span><span style="color: #800080;">'</span><span style="color: #ff00ff;">;</span>
y1=2<span style="color: #000000;">*</span>x1<span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">figure(</span>1<span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">bar(</span>x1<span style="color: #808080;">,</span>y1<span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">hold(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">on</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">plot(</span>x1<span style="color: #808080;">,</span>y1<span style="color: #808080;">,</span><span style="color: #800080;">'</span><span style="color: #ff9900;">LineWidth</span><span style="color: #800080;">'</span><span style="color: #808080;">,</span>3<span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">hold(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">off</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">grid(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">minor</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">xlabel(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">x</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">ylabel(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">y</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
ax=<span style="color: #0000ff;">gca</span><span style="color: #ff00ff;">;</span>
ax<span style="color: #ff0000;">.</span>YAxisLocation=<span style="color: #800080;">'</span><span style="color: #ff9900;">right</span><span style="color: #800080;">'</span><span style="color: #ff00ff;">;</span>

We seen before that integration is the sum of the area under the curve (the sum of the bars). We can plot the area under the curve with respect to

x1

. The first integrated

y2

value is going to be the sum of all the bars at

x1(1)

i.e.

x1(1)

and this is going to correspond to a new value of

x2=1.5

because we are shifted over by

0.5

, the mid point of the step size in

x1

. The next value is going to be the sum of the bars at

x1=2

i.e.

x1(1)+x(2)

and correspond to a new value of

x2=2.5

and so on and so forth.

y2=<span style="color: #ff0000;">[</span><span style="color: #0000ff;">sum(</span><span style="color: #00ccff;">y1(</span>1<span style="color: #00ccff;">)</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span><span style="color: #ff0000;">...</span>
<span style="color: #0000ff;">sum(</span><span style="color: #00ccff;">y1(</span>1<span style="color: #ff0000;">:</span>2<span style="color: #00ccff;">)</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span><span style="color: #ff0000;">...</span>
<span style="color: #0000ff;">sum(</span><span style="color: #00ccff;">y1(</span>1<span style="color: #ff0000;">:</span>3<span style="color: #00ccff;">)</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span><span style="color: #ff0000;">...</span>
<span style="color: #0000ff;">sum(</span><span style="color: #00ccff;">y1(</span>1<span style="color: #ff0000;">:</span>4<span style="color: #00ccff;">)</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span><span style="color: #ff0000;">...</span>
<span style="color: #0000ff;">sum(</span><span style="color: #00ccff;">y1(</span>1<span style="color: #ff0000;">:</span>5<span style="color: #00ccff;">)</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span><span style="color: #ff0000;">...</span>
<span style="color: #0000ff;">sum(</span><span style="color: #00ccff;">y1(</span>1<span style="color: #ff0000;">:</span>6<span style="color: #00ccff;">)</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span><span style="color: #ff0000;">...</span>
<span style="color: #0000ff;">sum(</span><span style="color: #00ccff;">y1(</span>1<span style="color: #ff0000;">:</span>7<span style="color: #00ccff;">)</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span><span style="color: #ff0000;">...</span>
<span style="color: #0000ff;">sum(</span><span style="color: #00ccff;">y1(</span>1<span style="color: #ff0000;">:</span>8<span style="color: #00ccff;">)</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span><span style="color: #ff0000;">...</span>
<span style="color: #0000ff;">sum(</span><span style="color: #00ccff;">y1(</span>1<span style="color: #ff0000;">:</span>9<span style="color: #00ccff;">)</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span><span style="color: #ff0000;">...</span>
<span style="color: #0000ff;">sum(</span><span style="color: #00ccff;">y1(</span>1<span style="color: #ff0000;">:</span>10<span style="color: #00ccff;">)</span><span style="color: #0000ff;">)</span><span style="color: #ff0000;">]</span><span style="color: #ff00ff;">;</span>
x2=<span style="color: #ff0000;">[</span><span style="color: #ff6600;">[</span>1<span style="color: #ff0000;">:</span>10<span style="color: #ff6600;">]</span>+0.5<span style="color: #ff0000;">]</span>'<span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">figure(</span>2<span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">scatter(</span>x1,y1,100,<span style="color: #800080;">'</span><span style="color: #ff9900;">fill</span><span style="color: #800080;">'</span>,<span style="color: #800080;">'</span><span style="color: #ff9900;">r</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">hold(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">on</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">scatter(</span>x2,y2,100,<span style="color: #800080;">'</span><span style="color: #ff9900;">fill</span><span style="color: #800080;">'</span>,<span style="color: #800080;">'</span><span style="color: #ff9900;">b</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">hold(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">off</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">grid(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">minor</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">xlabel(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">x</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">ylabel(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">y</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
ax=<span style="color: #0000ff;">gca</span><span style="color: #ff00ff;">;</span>
ax<span style="color: #ff0000;">.</span>YAxisLocation=<span style="color: #800080;">'</span><span style="color: #ff9900;">right</span>'<span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">legend(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">y1=2*x1</span><span style="color: #800080;">'</span>,<span style="color: #800080;">'</span><span style="color: #ff9900;">y2=int(y1,x1)</span><span style="color: #800080;">'</span>,<span style="color: #800080;">'</span><span style="color: #ff9900;">location</span><span style="color: #800080;">'</span>,<span style="color: #800080;">'</span><span style="color: #ff9900;">northwest</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>

We can plot

x1

,

y1

and

x2

,

y2

as a scatter plot. Noting that

y1=x.^2

and

y2=2*x

and the plots are correct.

y2=<span style="color: #ff0000;">[</span><span style="color: #0000ff;">sum(</span><span style="color: #00ccff;">y1(</span>1<span style="color: #00ccff;">)</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span><span style="color: #ff0000;">...</span>
<span style="color: #0000ff;">sum(</span><span style="color: #00ccff;">y1(</span>1<span style="color: #ff0000;">:</span>2<span style="color: #00ccff;">)</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span><span style="color: #ff0000;">...</span>
<span style="color: #0000ff;">sum(</span><span style="color: #00ccff;">y1(</span>1<span style="color: #ff0000;">:</span>3<span style="color: #00ccff;">)</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span><span style="color: #ff0000;">...</span>
<span style="color: #0000ff;">sum(</span><span style="color: #00ccff;">y1(</span>1<span style="color: #ff0000;">:</span>4<span style="color: #00ccff;">)</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span><span style="color: #ff0000;">...</span>
<span style="color: #0000ff;">sum(</span><span style="color: #00ccff;">y1(</span>1<span style="color: #ff0000;">:</span>5<span style="color: #00ccff;">)</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span><span style="color: #ff0000;">...</span>
<span style="color: #0000ff;">sum(</span><span style="color: #00ccff;">y1(</span>1<span style="color: #ff0000;">:</span>6<span style="color: #00ccff;">)</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span><span style="color: #ff0000;">...</span>
<span style="color: #0000ff;">sum(</span><span style="color: #00ccff;">y1(</span>1<span style="color: #ff0000;">:</span>7<span style="color: #00ccff;">)</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span><span style="color: #ff0000;">...</span>
<span style="color: #0000ff;">sum(</span><span style="color: #00ccff;">y1(</span>1<span style="color: #ff0000;">:</span>8<span style="color: #00ccff;">)</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span><span style="color: #ff0000;">...</span>
<span style="color: #0000ff;">sum(</span><span style="color: #00ccff;">y1(</span>1<span style="color: #ff0000;">:</span>9<span style="color: #00ccff;">)</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span><span style="color: #ff0000;">...</span>
<span style="color: #0000ff;">sum(</span><span style="color: #00ccff;">y1(</span>1<span style="color: #ff0000;">:</span>10<span style="color: #00ccff;">)</span><span style="color: #0000ff;">)</span><span style="color: #ff0000;">]</span><span style="color: #ff00ff;">;</span>

We can use

y2=<span style="color: #0000ff;">cumsum(</span>y1<span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>

# Differenciation

What we are now going to do is look at the plot

y3=1

i.e. a constant with respect to

x3
x3=<span style="color: #ff0000;">[</span>1<span style="color: #ff0000;">:</span>10<span style="color: #ff0000;">]</span><span style="color: #800080;">'</span><span style="color: #ff00ff;">;</span>
<span style="color: #ff0000;">[</span>m3<span style="color: #808080;">,</span>n3<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">size(</span>x3<span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
y3=<span style="color: #0000ff;">ones(</span>m3,n3<span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">figure(</span>3<span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">scatter(</span>x3<span style="color: #808080;">,</span>y3<span style="color: #808080;">,</span>100<span style="color: #808080;">,</span><span style="color: #800080;">'</span><span style="color: #ff9900;">fill</span><span style="color: #800080;">'</span>,<span style="color: #800080;">'</span><span style="color: #ff9900;">r</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">hold(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">on</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">scatter(</span>x4<span style="color: #808080;">,</span>y4<span style="color: #808080;">,</span>100<span style="color: #808080;">,</span><span style="color: #800080;">'</span><span style="color: #ff9900;">fill</span><span style="color: #800080;">'</span><span style="color: #808080;">,</span><span style="color: #800080;">'</span><span style="color: #ff9900;">b</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">hold(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">off</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">grid(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">minor</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">xlabel(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">x</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">ylabel(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">y</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
ax=<span style="color: #0000ff;">gca</span><span style="color: #ff00ff;">;</span>
ax<span style="color: #ff0000;">.</span>YAxisLocation=<span style="color: #800080;">'</span><span style="color: #ff9900;">right</span>'<span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">legend(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">y1=1</span><span style="color: #800080;">'</span><span style="color: #808080;">,</span><span style="color: #800080;">'</span><span style="color: #ff9900;">2=int(y1,x1)</span><span style="color: #800080;">'</span><span style="color: #808080;">,</span><span style="color: #800080;">'</span><span style="color: #ff9900;">location</span><span style="color: #800080;">'</span><span style="color: #808080;">,</span><span style="color: #800080;">'</span><span style="color: #ff9900;">northwest</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>

Now instead of looking at the area under the line, we are going to look at the difference between the nearest

y3

values i.e. the difference between a bar with the bar on its left. For instance the tenth bar at

x3=10

and the 9th bar at

x3=9

is going to correspond to a new value of

x4

that is 0.5 less than 9 i.e.

x4=8.5

. The next value is going to be the difference of the points at

x3=9

and

x3=8

and correspond to a new value of

x4

that is 0.5 less than  i.e.

x4=7.5

and so on and so forth.

We will plot this as a scatter plot on the same chart.

y4=<span style="color: #ff0000;">[<span style="color: #ff6600;">[</span><span style="color: #0000ff;">y3(</span>1<span style="color: #0000ff;">)</span><span style="color: #ff6600;">]</span><span style="color: #ff00ff;">;</span>...</span>
<span style="color: #ff6600;">[</span><span style="color: #0000ff;">y3(</span>2<span style="color: #0000ff;">)</span>-<span style="color: #0000ff;">y3(</span>1<span style="color: #0000ff;">)</span><span style="color: #ff6600;">]</span><span style="color: #ff00ff;">;</span><span style="color: #ff0000;">...</span>
<span style="color: #ff6600;">[</span><span style="color: #0000ff;">y3(</span>3<span style="color: #0000ff;">)</span>-<span style="color: #0000ff;">y3(</span>2<span style="color: #0000ff;">)</span><span style="color: #ff6600;">]</span><span style="color: #ff00ff;">;</span><span style="color: #ff0000;">...</span>
<span style="color: #ff6600;">[</span><span style="color: #0000ff;">y3(</span>4<span style="color: #0000ff;">)</span>-<span style="color: #0000ff;">y3(<span style="color: #000000;">3</span></span><span style="color: #0000ff;">)</span><span style="color: #ff6600;">]</span><span style="color: #ff00ff;">;</span><span style="color: #ff0000;">...</span>
<span style="color: #ff6600;">[</span><span style="color: #0000ff;">y3(</span>5<span style="color: #0000ff;">)</span>-<span style="color: #0000ff;">y3(</span>4<span style="color: #0000ff;">)</span><span style="color: #ff6600;">]</span><span style="color: #ff00ff;">;</span><span style="color: #ff0000;">...</span>
<span style="color: #ff6600;">[</span><span style="color: #0000ff;">y3(</span>6<span style="color: #0000ff;">)</span>-<span style="color: #0000ff;">y3(</span>5<span style="color: #0000ff;">)</span><span style="color: #ff6600;">]</span><span style="color: #ff00ff;">;</span><span style="color: #ff0000;">...</span>
<span style="color: #ff6600;">[</span><span style="color: #0000ff;">y3(</span>7<span style="color: #0000ff;">)</span>-<span style="color: #0000ff;">y3(</span>6<span style="color: #0000ff;">)</span><span style="color: #ff6600;">]</span><span style="color: #ff00ff;">;</span><span style="color: #ff0000;">...</span>
<span style="color: #ff6600;">[</span><span style="color: #0000ff;">y3(</span>8<span style="color: #0000ff;">)</span>-<span style="color: #0000ff;">y3(</span>7<span style="color: #0000ff;">)</span><span style="color: #ff6600;">]</span><span style="color: #ff00ff;">;</span><span style="color: #ff0000;">...</span>
<span style="color: #ff6600;">[</span><span style="color: #0000ff;">y3(</span>9<span style="color: #0000ff;">)</span>-<span style="color: #0000ff;">y3(</span>8<span style="color: #0000ff;">)</span><span style="color: #ff6600;">]</span><span style="color: #ff00ff;">;</span><span style="color: #ff0000;">...</span>
<span style="color: #ff6600;">[</span><span style="color: #0000ff;">y3(</span>10<span style="color: #0000ff;">)</span>-<span style="color: #0000ff;">y3(</span>9<span style="color: #0000ff;">)</span><span style="color: #ff6600;">]</span><span style="color: #ff0000;">]</span><span style="color: #ff00ff;">;</span>
x4=<span style="color: #ff0000;">[</span><span style="color: #ff6600;">[</span>1<span style="color: #ff0000;">:</span>10<span style="color: #ff6600;">]</span>-0.5<span style="color: #ff0000;">]</span><span style="color: #800080;">'</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">figure(</span>4<span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">scatter(</span>x3<span style="color: #808080;">,</span>y3<span style="color: #808080;">,</span>100<span style="color: #808080;">,</span><span style="color: #800080;">'</span><span style="color: #ff9900;">fill</span><span style="color: #800080;">'</span>,<span style="color: #800080;">'</span><span style="color: #ff9900;">r</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">hold(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">on</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">scatter(</span>x4<span style="color: #808080;">,</span>y4<span style="color: #808080;">,</span>100<span style="color: #808080;">,</span><span style="color: #800080;">'</span><span style="color: #ff9900;">fill</span><span style="color: #800080;">'</span>,<span style="color: #800080;">'</span><span style="color: #ff9900;">b</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">hold(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">off</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">grid(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">minor</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">xlabel(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">x</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">ylabel(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">y</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
ax=<span style="color: #0000ff;">gca</span><span style="color: #ff00ff;">;</span>
ax<span style="color: #ff0000;">.</span>YAxisLocation=<span style="color: #800080;">'</span><span style="color: #ff9900;">right</span><span style="color: #800080;">'</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">legend(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">y3=1</span><span style="color: #800080;">'</span><span style="color: #808080;">,</span><span style="color: #800080;">'</span><span style="color: #ff9900;">y4=diff(y3,x3)</span><span style="color: #800080;">'</span><span style="color: #808080;">,</span><span style="color: #800080;">'</span><span style="color: #ff9900;">location</span><span style="color: #800080;">'</span><span style="color: #808080;">,</span><span style="color: #800080;">'</span><span style="color: #ff9900;">NorthWest</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>

In this case since

y3

is a constant, the difference in the

y3

values

y4

is zero across the board as expected.

y4=<span style="color: #ff0000;">[<span style="color: #ff6600;">[</span><span style="color: #0000ff;">y3(</span>1<span style="color: #0000ff;">)</span><span style="color: #ff6600;">]</span><span style="color: #ff00ff;">;</span>...</span>
<span style="color: #ff6600;">[</span><span style="color: #0000ff;">y3(</span>2<span style="color: #0000ff;">)</span>-<span style="color: #0000ff;">y3(</span>1<span style="color: #0000ff;">)</span><span style="color: #ff6600;">]</span><span style="color: #ff00ff;">;</span><span style="color: #ff0000;">...</span>
<span style="color: #ff6600;">[</span><span style="color: #0000ff;">y3(</span>3<span style="color: #0000ff;">)</span>-<span style="color: #0000ff;">y3(</span>2<span style="color: #0000ff;">)</span><span style="color: #ff6600;">]</span><span style="color: #ff00ff;">;</span><span style="color: #ff0000;">...</span>
<span style="color: #ff6600;">[</span><span style="color: #0000ff;">y3(</span>4<span style="color: #0000ff;">)</span>-<span style="color: #0000ff;">y3(<span style="color: #000000;">3</span></span><span style="color: #0000ff;">)</span><span style="color: #ff6600;">]</span><span style="color: #ff00ff;">;</span><span style="color: #ff0000;">...</span>
<span style="color: #ff6600;">[</span><span style="color: #0000ff;">y3(</span>5<span style="color: #0000ff;">)</span>-<span style="color: #0000ff;">y3(</span>4<span style="color: #0000ff;">)</span><span style="color: #ff6600;">]</span><span style="color: #ff00ff;">;</span><span style="color: #ff0000;">...</span>
<span style="color: #ff6600;">[</span><span style="color: #0000ff;">y3(</span>6<span style="color: #0000ff;">)</span>-<span style="color: #0000ff;">y3(</span>5<span style="color: #0000ff;">)</span><span style="color: #ff6600;">]</span><span style="color: #ff00ff;">;</span><span style="color: #ff0000;">...</span>
<span style="color: #ff6600;">[</span><span style="color: #0000ff;">y3(</span>7<span style="color: #0000ff;">)</span>-<span style="color: #0000ff;">y3(</span>6<span style="color: #0000ff;">)</span><span style="color: #ff6600;">]</span><span style="color: #ff00ff;">;</span><span style="color: #ff0000;">...</span>
<span style="color: #ff6600;">[</span><span style="color: #0000ff;">y3(</span>8<span style="color: #0000ff;">)</span>-<span style="color: #0000ff;">y3(</span>7<span style="color: #0000ff;">)</span><span style="color: #ff6600;">]</span><span style="color: #ff00ff;">;</span><span style="color: #ff0000;">...</span>
<span style="color: #ff6600;">[</span><span style="color: #0000ff;">y3(</span>9<span style="color: #0000ff;">)</span>-<span style="color: #0000ff;">y3(</span>8<span style="color: #0000ff;">)</span><span style="color: #ff6600;">]</span><span style="color: #ff00ff;">;</span><span style="color: #ff0000;">...</span>
<span style="color: #ff6600;">[</span><span style="color: #0000ff;">y3(</span>10<span style="color: #0000ff;">)</span>-<span style="color: #0000ff;">y3(</span>9<span style="color: #0000ff;">)</span><span style="color: #ff6600;">]</span><span style="color: #ff0000;">]</span><span style="color: #ff00ff;">;</span>

We can use

y4=<span style="color: #ff0000;">[</span><span style="color: #0000ff;">y3(</span>1<span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span><span style="color: #0000ff;">diff(</span>y3<span style="color: #0000ff;">)</span><span style="color: #ff0000;">]</span><span style="color: #ff00ff;">;</span>
x4=<span style="color: #ff0000;">[</span><span style="color: #ff9900;">[</span>1<span style="color: #ff0000;">:</span>10<span style="color: #ff9900;">]</span>-0.5<span style="color: #ff0000;">]</span>'<span style="color: #ff00ff;">;</span>

A value for

x3=0

was not selected and is the reason for

y4(0)=1

opposed to its actual value of

0

. As this is an outlier it is better to ignore this first value and instead look at:

y4=<span style="color: #ff0000;">[</span><span style="color: #0000ff;">diff(</span>y3<span style="color: #0000ff;">)</span><span style="color: #ff0000;">]</span><span style="color: #ff00ff;">;</span>
x4=<span style="color: #ff0000;">[</span><span style="color: #ff9900;">[</span>2<span style="color: #ff0000;">:</span>10<span style="color: #ff9900;">]</span>-0.5<span style="color: #ff0000;">]</span>'<span style="color: #ff00ff;">;</span>

y3=1

(constant) to

y3=x3

. Now the bar chart from right to left looks like a set of stairs and as we climb down the step size remains constant:

As a result

y4

is a straight line and is independent of

x4

.

Okay so let's now change

y3=x3.^2

. Here the bar chart from right to left stepping down we see the first step is the larges, the the second step, then the third and it is a much shallower step down on the left hand side:

Actually we can see that every value of

y4

is equal to

2*x4

i.e.

y4=2*x4

# Integration vs Differentiation

The integration of

y1=2*x1

with respect to

x1

gives

y2=x2^3

and the differentiation of

y3=x3^3

with respect to

x3

gives

y4=2*x4

i.e. as you can clearly see they are the inverse process of one another.

We can think of integration as adding the sum of all the bars as we move from left to right – climbing the stairs i.e. starting at the origin and our first plot point being

0+(step size/2

).

And we can think of differentiation as being the difference in the bar height as we step down from the right to left. The first step from the right being

end-(step size)/2

.

Of course as we seen with integration the above is only an approximation as we used finite relatively large step sizes.

# Uncertainty in Results

In the above we had the bin width equaling to the finite bin width of 1. For integration and differentiation we use an infinitely small bin width. Let's constrict our bin width

x1step=0.0001
<span style="color: #ff0000;">[</span>m1<span style="color: #808080;">,</span>n1<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">size(</span>x1<span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
x1=<span style="color: #ff0000;">[</span>1<span style="color: #ff0000;">:<span style="color: #000000;">x1step</span>:</span>10<span style="color: #ff0000;">]</span><span style="color: #800080;">'</span><span style="color: #ff00ff;">;</span>
y1=2<span style="color: #ff0000;">*</span>x1<span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">figure(</span>1<span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">bar(</span>x1<span style="color: #808080;">,</span>y1<span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">hold(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">on</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">plot(</span>x1<span style="color: #808080;">,</span>y1<span style="color: #808080;">,</span><span style="color: #800080;">'</span><span style="color: #ff9900;">LineWidth</span><span style="color: #800080;">'</span><span style="color: #808080;">,</span>3<span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">hold(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">off</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">grid(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">minor</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">xlabel(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">x</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">ylabel(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">y</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
ax=<span style="color: #0000ff;">gca</span><span style="color: #ff00ff;">;</span>
ax<span style="color: #ff0000;">.</span>YAxisLocation=<span style="color: #800080;">'</span><span style="color: #ff9900;">right</span><span style="color: #800080;">'</span><span style="color: #ff00ff;">;</span>

y2=<span style="color: #ff0000;">[</span>x1step<span style="color: #ff0000;">]</span>*<span style="color: #0000ff;">cumsum(</span>y1<span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
y2=<span style="color: #0000ff;">y2(</span>2<span style="color: #ff0000;">:</span>end<span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
x2=<span style="color: #ff0000;">[</span>x1step<span style="color: #ff0000;">]</span>*<span style="color: #0000ff;">[</span><span style="color: #ff6600;">[</span>2<span style="color: #ff0000;">:</span>m1<span style="color: #ff6600;">]</span>+<span style="color: #ff6600;">[</span>x1step/2<span style="color: #ff6600;">]</span><span style="color: #0000ff;">]</span>';
<span style="color: #0000ff;">figure(</span>2<span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">scatter(</span>x<span style="color: #808080;">,</span>y<span style="color: #808080;">,</span>100<span style="color: #808080;">,</span><span style="color: #800080;">'</span><span style="color: #ff9900;">fill</span><span style="color: #800080;">'</span>,<span style="color: #800080;">'</span><span style="color: #ff9900;">r</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">hold(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">on</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">scatter(</span>x2<span style="color: #808080;">,</span>y2<span style="color: #808080;">,</span>100<span style="color: #808080;">,</span><span style="color: #800080;">'</span><span style="color: #ff9900;">fill</span><span style="color: #800080;">'</span><span style="color: #808080;">,</span><span style="color: #800080;">'</span><span style="color: #ff9900;">b</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">hold(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">off</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">grid(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">minor</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">xlabel(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">x</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">ylabel(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">y</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
ax=<span style="color: #0000ff;">gca</span><span style="color: #ff00ff;">;</span>
ax<span style="color: #ff0000;">.</span>YAxisLocation=<span style="color: #800080;">'</span><span style="color: #ff9900;">right</span>'<span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">legend(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">y1=2*x1</span><span style="color: #800080;">'</span><span style="color: #808080;">,</span><span style="color: #800080;">'</span><span style="color: #ff9900;">2=int(y1,x1)</span><span style="color: #800080;">'</span><span style="color: #808080;">,</span><span style="color: #800080;">'</span><span style="color: #ff9900;">location</span><span style="color: #800080;">'</span><span style="color: #808080;">,</span><span style="color: #800080;">'</span><span style="color: #ff9900;">northwest</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>

x3step=0.0001
x3=<span style="color: #ff0000;">[</span>1<span style="color: #ff0000;">:<span style="color: #000000;">x3step</span>:</span>10<span style="color: #ff0000;">]</span><span style="color: #800080;">'</span><span style="color: #ff00ff;">;</span>
<span style="color: #ff0000;">[</span>m3<span style="color: #808080;">,</span>n3<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">size(</span>x3<span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
y3=x3.^2<span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">figure(</span>3<span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">scatter(</span>x3<span style="color: #808080;">,</span>y3<span style="color: #808080;">,</span>100<span style="color: #808080;">,</span><span style="color: #800080;">'</span><span style="color: #ff9900;">fill</span><span style="color: #800080;">'</span><span style="color: #808080;">,</span><span style="color: #800080;">'</span><span style="color: #ff9900;">r</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">grid(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">minor</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">xlabel(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">x</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">ylabel(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">y</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
ax=<span style="color: #0000ff;">gca</span>
ax<span style="color: #ff0000;">.</span>YAxisLocation=<span style="color: #800080;">'</span><span style="color: #ff9900;">right</span><span style="color: #800080;">'</span><span style="color: #ff00ff;">;</span>

y4=<span style="color: #ff0000;">[<span style="color: #ff6600;"><span style="color: #0000ff;">diff(</span></span><span style="color: #0000ff;">y3)</span>].<span style="color: #000000;">/x3step</span></span>
x4=x3step*<span style="color: #ff0000;">[</span><span style="color: #ff6600;">[</span>2<span style="color: #ff0000;">:</span>m3<span style="color: #ff6600;">]</span>-<span style="color: #ff6600;">[</span>x3step/2]<span style="color: #ff6600;">]</span><span style="color: #800080;">'</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">figure(</span>4<span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">scatter(</span>x3<span style="color: #808080;">,</span>y3<span style="color: #808080;">,</span>100<span style="color: #808080;">,</span><span style="color: #800080;">'</span><span style="color: #ff9900;">fill</span><span style="color: #800080;">'</span>,<span style="color: #800080;">'</span><span style="color: #ff9900;">r</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">hold(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">on</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">scatter(</span>x4<span style="color: #808080;">,</span>y4<span style="color: #808080;">,</span>100<span style="color: #808080;">,</span><span style="color: #800080;">'</span><span style="color: #ff9900;">fill</span><span style="color: #800080;">'</span>,<span style="color: #800080;">'</span><span style="color: #ff9900;">b</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">hold(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">off</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">grid(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">minor</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">xlabel(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">x</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">ylabel(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">y</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>
ax=<span style="color: #0000ff;">gca</span><span style="color: #ff00ff;">;</span>
ax<span style="color: #ff0000;">.</span>YAxisLocation=<span style="color: #800080;">'</span><span style="color: #ff9900;">right</span><span style="color: #800080;">'</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">legend(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">y3=x3^2</span><span style="color: #800080;">'</span><span style="color: #808080;">,</span><span style="color: #800080;">'</span><span style="color: #ff9900;">y4=diff(y3,x3)</span><span style="color: #800080;">'</span><span style="color: #808080;">,</span><span style="color: #800080;">'</span><span style="color: #ff9900;">location</span><span style="color: #800080;">'</span><span style="color: #808080;">,</span><span style="color: #800080;">'</span><span style="color: #ff9900;">NorthWest</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span><span style="color: #ff00ff;">;</span>

# Rules of Integration and Differenciation

Taking

$\displaystyle y={{x}^{n}}$

For integration we elevate the original power by 1 and then divide by the new power.

$\displaystyle \text{int}\left( y \right)=\frac{{{{x}^{{\left( {n+1} \right)}}}}}{{\left( {n+1} \right)}}$

For differentiation we multiply by the original power and then devalue the power by 1:

$\displaystyle \text{diff}(y)=n{{x}^{{\left( {n-1} \right)}}}$

# Symbolic

We can set x to be a symbol and write down our starting equations with respect to x:

<span style="color: #0000ff;">syms(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">x</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span>
z1=1
z2=x
z3=x^2
z4=x^3

$\displaystyle z1=1$

$\displaystyle z2=x$

$\displaystyle z3={{x}^{2}}$

$\displaystyle z4={{x}^{3}}$

Now we can differentiate the functions with respect to x:

dz1=<span style="color: #0000ff;">diff(</span>z1<span style="color: #808080;">,</span>x<span style="color: #0000ff;">)</span>
dz2=<span style="color: #0000ff;">diff(</span>z2<span style="color: #808080;">,</span>x<span style="color: #0000ff;">)</span>
dz3=<span style="color: #0000ff;">diff(</span>z3<span style="color: #808080;">,</span>x<span style="color: #0000ff;">)</span>
dz4=<span style="color: #0000ff;">diff(</span>z4<span style="color: #808080;">,</span>x<span style="color: #0000ff;">)</span>

$\displaystyle \text{dz1}=0$

$\displaystyle \text{dz2}=1$

$\displaystyle \text{dz3}=2x$

$\displaystyle \text{dz4}=3{{x}^{2}}$

Now we can integrate the functions with respect to x:

iz1=<span style="color: #0000ff;">int(</span>z1<span style="color: #808080;">,</span>x<span style="color: #0000ff;">)</span>
iz2=<span style="color: #0000ff;">int(</span>z2<span style="color: #808080;">,</span>x<span style="color: #0000ff;">)</span>
iz3=<span style="color: #0000ff;">int(</span>z3<span style="color: #808080;">,</span>x<span style="color: #0000ff;">)</span>
iz4=<span style="color: #0000ff;">int(</span>z4<span style="color: #808080;">,</span>x<span style="color: #0000ff;">)</span>

$\displaystyle \text{iz1}=x$

$\displaystyle \text{iz2}=\frac{{{{x}^{2}}}}{2}$

$\displaystyle \text{iz3}=\frac{{{{x}^{3}}}}{3}$

$\displaystyle \text{iz4}=\frac{{{{x}^{4}}}}{4}$

This site uses Akismet to reduce spam. Learn how your comment data is processed.