Search This Blog

Monday, November 14, 2011

The Trapezoidal Rule

Problem: Find
math expression
We put u = x2 + 1 and as x = 0 → 1,u = 1 → 2
If u = x2 + 1 then du = 2x dx.
But the question does not contain an x dxterm so we cannot solve it using any of the normal integration methods.
We need to use numerical approaches. When software like Mathcad or graphics calculators perform definite integrals, they use numerical methods given earlier.
We can use one of two methods:

The Trapezoidal Rule

We saw the basic idea in our first attempt at solving the area under the arches problem earlier.
Instead of using rectangles as we did in the arches problem, we'll use trapezoids(trapeziums) and we'll find that it gives a better approximation to the area.
math expression
Recall that we write "Δx" to mean "a small change in x".
Let's see this in LiveMath. Note that our approximation is much better than using rectangles.
Now, the area of a trapezoid (trapezium) is given by:
math expression
math expression
So the approximate area under the curve is found by adding the area of the trapezoids. (Our trapezoids are rotated 90° so that their new base is actually the height. So h = Δx.)
Area ≈
math expression
We can simplify this to give us the Trapezoidal Rule, for n trapezoids:
math expression
To find Δx for the area from x = a to x = b, we use:
math expression
and we also need
y0 = f(a)
y1 = f(a + Δx)
y2 = f(a + 2Δx)
yn = f(b)

Note:
  • We get a better approximation if we take more trapezoids [up to a limit!].
  • The more trapezoids we take, we have: Δx → 0.
  • We can write (if the curve is above the x-axis only between x = a and x = b):
math expression

Exercise: Using n = 5, approximate the integral:
math expression
Here, a = 0 and b = 1.
math expression
y0 = f(a) = f(0) = math expression = 1
y1 = f(a + Δx) = f(0.2) = math expression
y2 = f(a + 2Δx) = f(0.4) = math expression
y3 = f(a + 3Δx) = f(0.6) = math expression
y4 = f(a + 4Δx) = f(0.8) = math expression
y5 = f(b) = f(1) = math expression
So the area ≈
math expression
So math expression 1.150

Sunday, November 13, 2011

Metal Tidbits, Aerospace

matlab task -array and function and matrix and plot

x=[1 2 1/2 -3 -1]
y=[2 0 -3 1/3 2]
x.*y
A=[-1 3.5 2;0 1 -1.3;1.1 2 1.9]
B=[1 0 -1;-1.5 1.5 -3;1 1 1]
A*B
a=[-1 3.5 2;0 1 -1.3;1.1 2 1.9]
d=[0 -3.5 -2; 0 0 1.3;-1.1 -2 0]
c=a+d
d=[3 3;1 2]
dinv=[0.667 -1;-0.333 1]
b=[1;1]
d\b
dinv*b
d/b
d*dinv
M=[1 1 1;1 0 1; -1 0 0]
A=[1 1 1;1 2 1; 1 1 1]
c=M\A
Minv=c/a
A=[-1 3.5 2;0 1 -1.3;1.1 2 1.9]
B=[1 0 -1;-1.5 1.5 -3;1 1 1]
A|B
c=xor(A, B)
~A
~B
x=[1 -3 3 14 -10 12]
y=[12 6 0 -1 -10 2]
D=x<=y
F=x>=y
K=x==y
G=x~=y
C=[1 2 3 4 10;-22 1 11 -12 4;8 1 6 -11 5;18 1 11 6 4]
compvector=10*ones(4,5)
comp=C==10
D=[7 2 3 10;-2 -3 11 3;8 1 6 5;18 1 11 4]
comp=D==7|D==-3|D==6|D==4
result=D(comp)
t=(0:0.1:10)
in(7*3.142*5*t).*cos(2*3.142*3*t)+exp(-0.1*t)
sin(2*3.142*5.3*t).*sin(2*3.142*5.3*t)
r=[j j+1 j-7 j+1 -3]
r=[j;j+1;j-7;j+1;-3]
k=20*sin(5.3*3.142*2*t)
round(k)
t=(0:0.1:0.5)
k=20*sin(5.3*3.142*2*t)
round(k)


>> x=[1 2 1/2 -3 -1]
x =
  Columns 1 through 3
    1.0000    2.0000    0.5000
  Columns 4 through 5
   -3.0000   -1.0000
>> y=[2 0 -3 1/3 2]
y =
  Columns 1 through 3
    2.0000         0   -3.0000
  Columns 4 through 5
    0.3333    2.0000
> x.*y
ans =
  Columns 1 through 3
    2.0000         0   -1.5000
  Columns 4 through 5
   -1.0000   -2.0000
>> A=[-1 3.5 2;0 1 -1.3;1.1 2 1.9]
A =
   -1.0000    3.5000    2.0000
         0    1.0000   -1.3000
    1.1000    2.0000    1.9000
>> B=[1 0 -1;-1.5 1.5 -3;1 1 1]
B =
    1.0000         0   -1.0000
   -1.5000    1.5000   -3.0000
    1.0000    1.0000    1.0000

>> A*B
ans =
   -4.2500    7.2500   -7.5000
   -2.8000    0.2000   -4.3000
         0    4.9000   -5.2000
>> a=[-1 3.5 2;0 1 -1.3;1.1 2 1.9]
a =
   -1.0000    3.5000    2.0000
         0    1.0000   -1.3000
    1.1000    2.0000    1.9000
>> d=[0 -3.5 -2; 0 0 1.3;-1.1 -2 0]
d =
         0   -3.5000   -2.0000
         0         0    1.3000
   -1.1000   -2.0000         0
>> c=a+d
c =
   -1.0000         0         0
         0    1.0000         0
         0         0    1.9000
>> d=[3 3;1 2]
d =
     3     3
     1     2
>> dinv=[0.667 -1;-0.333 1]
dinv =
    0.6670   -1.0000
   -0.3330    1.0000
>> b=[1;1]
b =
     1
     1
>> d\b
ans =
   -0.3333
    0.6667
>> dinv*b
ans =
   -0.3330
    0.6670
>>d/b
ans=
6
3
>> d*binv
ans =
     6
     3
M=[1 1 1;1 0 1; -1 0 0]
M =
     1     1     1
     1     0     1
    -1     0     0
>> A=[1 1 1;1 2 1; 1 1 1]
A =
     1     1     1
     1     2     1
     1     1     1
>> c=M\A
c =
    -1    -1    -1
     0    -1     0
     2     3     2
>> Minv=c/a
Minv =
    0.1683   -0.0769   -0.7561
   -0.1222   -0.3503   -0.1111
   -0.2144    0.5041    1.6232
>> A=[-1 3.5 2;0 1 -1.3;1.1 2 1.9]
A =
   -1.0000    3.5000    2.0000
         0    1.0000   -1.3000
    1.1000    2.0000    1.9000
>> B=[1 0 -1;-1.5 1.5 -3;1 1 1]
B =
    1.0000         0   -1.0000
   -1.5000    1.5000   -3.0000
    1.0000    1.0000    1.0000
>> A|B
ans =
     1     1     1
     1     1     1
     1     1     1
> c=xor(A, B)
c =
     0     1     0
     1     0     0
     0     0     0
>> ~A
ans =
     0     0     0
     1     0     0
     0     0     0
> ~B
ans =
     0     1     0
     0     0     0
     0     0     0
>> x=[1 -3 3 14 -10 12]
x =
     1    -3     3    14   -10    12
>> y=[12 6 0 -1 -10 2]
y =
    12     6     0    -1   -10     2
>> D=x<=y
D =
     1     1     0     0     1     0
>> F=x>=y
F =
     0     0     1     1     1     1
>> K=x==y
K =
     0     0     0     0     1     0
>> G=x~=y
G =

     1     1     1     1     0     1
>> C=[1 2 3 4 10;-22 1 11 -12 4;8 1 6 -11 5;18 1 11 6 4]
C =
     1     2     3     4    10
   -22     1    11   -12     4
     8     1     6   -11     5
    18     1    11     6     4
>> compvector=10*ones(4,5)
compvector =
    10    10    10    10    10
    10    10    10    10    10
    10    10    10    10    10
    10    10    10    10    10
>> comp=C==10
comp =
     0     0     0     0     1
     0     0     0     0     0
     0     0     0     0     0
     0     0     0     0     0
result =
    10
>> D=[7 2 3 10;-2 -3 11 3;8 1 6 5;18 1 11 4]
D =
     7     2     3    10
    -2    -3    11     3
     8     1     6     5
    18     1    11     4
> comp=D==7|D==-3|D==6|D==4

comp =
     1     0     0     0
     0     1     0     0
     0     0     1     0
     0     0     0     1
>> result=D(comp)
result =
     7
    -3
     6
     4
>> t=(0:0.1:10)
in(7*3.142*5*t).*cos(2*3.142*3*t)+exp(-0.1*t)
ans =
  Columns 1 through 3
    1.0000    1.2993    0.9825
  Columns 4 through 6
    1.7799    0.9625    1.9512
  Columns 7 through 9
    0.9391    1.7404    0.9139
  Columns 10 through 12
    1.2208    0.8906    0.5843
  Columns 13 through 15
    0.8731    0.0674    0.8633
  Columns 16 through 18
   -0.1391    0.8593    0.0373
  Columns 19 through 21
    0.8561    0.5225    0.8472
  Columns 22 through 24
    1.1243    0.8278    1.6064
  Columns 25 through 27
    0.7970    1.7781    0.7594
  Columns 28 through 30
    1.5679    0.7233    1.0503
  Columns 31 through 33
    0.6981    0.4175    0.6895
  Columns 34 through 36
   -0.0939    0.6972   -0.2940
  Columns 37 through 39
    0.7140   -0.1118    0.7280
  Columns 40 through 42
    0.3776    0.7273    0.9816
  Columns 43 through 45
    0.7051    1.4641    0.6628
  Columns 46 through 48
    1.6355    0.6103    1.4254
  Columns 49 through 51
    0.5630    0.9095    0.5353
  Columns 52 through 54
    0.2805    0.5352   -0.2256
  Columns 55 through 57
    0.5599   -0.4199    0.5969
  Columns 58 through 60
   -0.2326    0.6274    0.2601
  Columns 61 through 63
    0.6342    0.8653    0.6086
  Columns 64 through 66

    1.3473    0.5541    1.5176
  Columns 67 through 69
    0.4864    1.3073    0.4274
  Columns 70 through 72
    0.7931    0.3970    0.1678
  Columns 73 through 75
    0.4049   -0.3330    0.4464
  Columns 76 through 78
   -0.5218    0.5030   -0.3300
  Columns 79 through 81
    0.5494    0.1651    0.5631
  Columns 82 through 84
    0.7705    0.5334    1.2511
  Columns 85 through 87
    0.4663    1.4199    0.3829
  Columns 88 through 90
    1.2092    0.3120    0.6966
  Columns 91 through 93
    0.2786    0.0752    0.2945
  Columns 94 through 96
   -0.4204    0.3523   -0.6038
  Columns 97 through 99
    0.4281   -0.4082    0.4899
  Columns 100 through 101
    0.0885    0.5099
>> sin(2*3.142*5.3*t).*sin(2*3.142*5.3*t)
ans =
  Columns 1 through 3
         0    0.0353    0.1361
  Columns 4 through 6
    0.2883    0.4703    0.6566
  Columns 7 through 9
    0.8207    0.9396    0.9965
  Columns 10 through 12
    0.9833    0.9020    0.7639
  Columns 13 through 15
    0.5886    0.4008    0.2270
  Columns 16 through 18
    0.0917    0.0140    0.0049
  Columns 19 through 21
    0.0656    0.1877    0.3537
  Columns 22 through 24
    0.5404    0.7214    0.8712
  Columns 25 through 27
    0.9686    0.9999    0.9606
  Columns 28 through 30
    0.8564    0.7019    0.5189
  Columns 31 through 33
    0.3332    0.1711    0.0554
  Columns 34 through 36
    0.0024    0.0196    0.1046
  Columns 37 through 39
    0.2453    0.4220    0.6098
  Columns 40 through 42
    0.7820    0.9144    0.9884
  Columns 43 through 45
    0.9935    0.9289    0.8038
  Columns 46 through 48
    0.6359    0.4488    0.2689
  Columns 49 through 51
    0.1216    0.0277    0.0005
  Columns 52 through 54
    0.0437    0.1512    0.3080
  Columns 55 through 57
    0.4919    0.6769    0.8370
  Columns 58 through 60
    0.9495    0.9986    0.9773
  Columns 61 through 63
    0.8887    0.7453    0.5673
  Columns 64 through 66
    0.3797    0.2092    0.0796
  Columns 67 through 69
    0.0094    0.0084    0.0767
  Columns 70 through 72
    0.2048    0.3745    0.5619
  Columns 73 through 75
    0.7406    0.8853    0.9757
  Columns 76 through 78
    0.9990    0.9518    0.8409
  Columns 79 through 81
    0.6820    0.4973    0.3130
  Columns 82 through 84
    0.1551    0.0459    0.0007
  Columns 85 through 87
    0.0260    0.1181    0.2641
  Columns 88 through 90
    0.4434    0.6307    0.7995
  Columns 91 through 93
    0.9261    0.9926    0.989
  Columns 94 through 96
    0.9174    0.7864    0.6150
  Columns 97 through 99
    0.4274    0.2500    0.1079
  Columns 100 through 101
    0.0211    0.0019
>> r=[j j+1 j-7 j+1 -3]
r =
        0 + 1.0000i   1.0000 + 1.0000i  -7.0000 + 1.0000i   1.0000 + 1.0000i  -3.0000         
>> r=[j;j+1;j-7;j+1;-3]
r =
        0 + 1.0000i
   1.0000 + 1.0000i
  -7.0000 + 1.0000i
   1.0000 + 1.0000i
  -3.0000         
>> k=20*sin(5.3*3.142*2*t)
k =
  Columns 1 through 12
         0   -3.7561    7.3785  -10.7384   13.7161  -16.2057   18.1185  -19.3866   19.9648  -19.8324   18.9943  -17.4802
  Columns 13 through 24
   15.3440  -12.6618    9.5290   -6.0570    2.3695    1.4023   -5.1242    8.6638  -11.8950   14.7029  -16.9876   18.6677
  Columns 25 through 36
  -19.6835   19.9988  -19.6024   18.5084  -16.7558   14.4068  -11.5451    8.2726   -4.7057    0.9713    2.7977   -6.4671
  Columns 37 through 48
    9.9063  -12.9930   15.6174  -17.6859   19.1250  -19.8836   19.9345  -19.2760   17.9315  -15.9489   13.3987  -10.3717
  Columns 49 through 60
    6.9755   -3.3312   -0.4318    4.1793   -7.7781   11.1001  -14.0271   16.4549  -18.2971   19.4882  -19.9857   19.7720
  Columns 61 through 72
  -18.8546   17.2663  -15.0635   12.3246   -9.1471    5.6441   -1.9403   -1.8327    5.5404   -9.0509   12.2393  -14.9922
  Columns 73 through 84
   17.2115  -18.8183   19.7554  -19.9895   19.5122  -18.3405   16.5161  -14.1040   11.1899   -7.8776    4.2849   -0.5398
  Columns 85 through 96
   -3.2245    6.8741  -10.2791   13.3182  -15.8834   17.8834  -19.2469   19.9254  -19.8949   19.1564  -17.7361   15.6846
  Columns 97 through 101
  -13.0750   10.0001   -6.5693    2.9047    0.8633
>> round(k)
ans =
  Columns 1 through 20
     0    -4     7   -11    14   -16    18   -19    20   -20    19   -17    15   -13    10    -6     2     1    -5     9
  Columns 21 through 40
   -12    15   -17    19   -20    20   -20    19   -17    14   -12     8    -5     1     3    -6    10   -13    16   -18
  Columns 41 through 60
    19   -20    20   -19    18   -16    13   -10     7    -3     0     4    -8    11   -14    16   -18    19   -20    20
  Columns 61 through 80
   -19    17   -15    12    -9     6    -2    -2     6    -9    12   -15    17   -19    20   -20    20   -18    17   -14
  Columns 81 through 100
    11    -8     4    -1    -3     7   -10    13   -16    18   -19    20   -20    19   -18    16   -13    10    -7     3
  Column 101
     1
>> t=(0:0.1:.5)
t =
         0    0.1000    0.2000    0.3000    0.4000    0.5000
>> k=20*sin(5.3*3.142*2*t)
k =
         0   -3.7561    7.3785  -10.7384   13.7161  -16.2057
>> round(k)
ans =
     0    -4     7   -11    14   -16
x=[1 2 1/2 -3 -1]
y=[2 0 -3 1/3 2]
x.*y
A=[-1 3.5 2;0 1 -1.3;1.1 2 1.9]
B=[1 0 -1;-1.5 1.5 -3;1 1 1]
A*B
a=[-1 3.5 2;0 1 -1.3;1.1 2 1.9]
d=[0 -3.5 -2; 0 0 1.3;-1.1 -2 0]
c=a+d
d=[3 3;1 2]
dinv=[0.667 -1;-0.333 1]
b=[1;1]
d\b
dinv*b
d/b
d*dinv
M=[1 1 1;1 0 1; -1 0 0]
A=[1 1 1;1 2 1; 1 1 1]
c=M\A
Minv=c/a
A=[-1 3.5 2;0 1 -1.3;1.1 2 1.9]
B=[1 0 -1;-1.5 1.5 -3;1 1 1]
A|B
c=xor(A, B)
~A
~B
x=[1 -3 3 14 -10 12]
y=[12 6 0 -1 -10 2]
D=x<=y
F=x>=y
K=x==y
G=x~=y
C=[1 2 3 4 10;-22 1 11 -12 4;8 1 6 -11 5;18 1 11 6 4]
compvector=10*ones(4,5)
comp=C==10
D=[7 2 3 10;-2 -3 11 3;8 1 6 5;18 1 11 4]
comp=D==7|D==-3|D==6|D==4
result=D(comp)
t=(0:0.1:10)
in(7*3.142*5*t).*cos(2*3.142*3*t)+exp(-0.1*t)
sin(2*3.142*5.3*t).*sin(2*3.142*5.3*t)
r=[j j+1 j-7 j+1 -3]
r=[j;j+1;j-7;j+1;-3]
k=20*sin(5.3*3.142*2*t)
round(k)
t=(0:0.1:0.5)
k=20*sin(5.3*3.142*2*t)
round(k)


plot with matlab

x = 0:1:15;
y1=(14.*(x.^2))+(3.*(x)-(25));
y2=(-8.*(x.^2))+(7.*(x)+(30));
[AX,H1,H2] = plotyy(x,y1,x,y2,'plot');

>> x=[1:1:15];
y1=(14.*(x.^2))+(3.*(x)-(25));
(y1(x))

ans =
Columns 1 through 7
-8          37         110         211         340         497         682
Columns 8 through 14
895        1136        1405        1702        2027        2380        2761
Column 15
3170

>> x=[1:1:15];
y2=(-8.*(x.^2))+(7.*(x)+(30));
(y2(x))

ans =
Columns 1 through 7
29          12         -21         -70        -135        -216        -313
Columns 8 through 14
-426        -555        -700        -861       -1038       -1231       -1440
Column 15
-1665









x=-pi:0.1:pi;
y1=4*sin(x);
x1=4*cos(x);
plot(x1,y1);
hold on
x=-pi:0.1:pi;
y2=2*sin(x);
x2=2*cos(x);
plot(x2,y2);
hold on
z=-2.8:0.1:2.8;
q=-2.8:0.1:2.8;
y3=2.8;
x3=-2.8;
plot(y3,q,'r');
hold on
plot(x3,q);
hold on
plot(z,y3);
hold on
plot(z,x3)

 


n = 23;
t = -pi:0.5:pi;
x = (n.*t)-(sin(n.*t));
plot(t,x)
x =
Columns 1 through 8
-72.2566  -61.6321  -50.1029  -37.6991  -25.3548  -13.9424   -3.3714    7.3182
Columns 9 through 13
18.9639   31.4151   43.6888   54.9855   65.5153













n = 23;
t = -pi:0.5:pi;
y = (n.*sin(t))./(cos(n.*t));
stem(t,y)
box

y =
  Columns 1 through 8
    0.0000   22.8154  -36.3225  -22.9804  -48.3917   23.7080    3.2674  -21.2528
  Columns 9 through 13
 
 





















   27.7861   22.8221   67.6937  -24.2122   -6.6005