numerical method for engineers-chapter 19
TRANSCRIPT
-
8/2/2019 Numerical Method for engineers-chapter 19
1/25
1
CHAPTER 19
19.1 The angular frequency can be computed as 0 = 2/24 = 0.261799. The various summationsrequired for the normal equations can be set up as
t y cos( 0t ) sin( 0t ) sin(
0t )cos(
0t ) cos 2( 0t ) sin 2( 0t ) y cos(
0t ) y sin( 0t )0 7.6 1.00000 0.00000 0.00000 1.00000 0.00000 7.60000 0.00000
2 7.2 0.86603 0.50000 0.43301 0.75000 0.25000 6.23538 3.60000
4 7.0 0.50000 0.86603 0.43301 0.25000 0.75000 3.50000 6.06218
5 6.5 0.25882 0.96593 0.25000 0.06699 0.93301 1.68232 6.27852
7 7.5 -0.25882 0.96593 -0.25000 0.06699 0.93301 -1.94114 7.24444
9 7.2 -0.70711 0.70711 -0.50000 0.50000 0.50000 -5.09117 5.09117
12 8.9 -1.00000 0.00000 0.00000 1.00000 0.00000 -8.90000 0.00000
15 9.1 -0.70711 -0.70711 0.50000 0.50000 0.50000 -6.43467 -6.43467
20 8.9 0.50000 -0.86603 -0.43301 0.25000 0.75000 4.45000 -7.70763
22 7.9 0.86603 -0.50000 -0.43301 0.75000 0.25000 6.84160 -3.95000
24 7.0 1.00000 0.00000 0.00000 1.00000 0.00000 7.00000 0.00000
sum 84.8 2.31784 1.93185 0.00000 6.13397 4.86603 14.94232 10.18401
The normal equations can be assembled as
=18401.1094232.14
8.84
866025.40931852.10133975.63178.2
931852.1317837.211
1
1
0
B A A
This system can be solved for A0 = 8.02704, A1 = 0.59717, and B1 = 1.09392. Therefore, the best-fit sinusoid is
)sin(09392.1)cos(59717.002704.8 00 t t pH =The data and the model can be plotted as
6
7
8
9
10
0 6 12 18 24
19.2 The angular frequency can be computed as 0 = 2/360 = 0.017453. Because the data areequispaced, the coefficients can be determined with Eqs. 19.14-19.16. The varioussummations required to set up the model can be determined as
PROPRIETARY MATERIAL . The McGraw-Hill Companies, Inc. All rights reserved. No part of this Manual may be displayed, reproduced or distributed in any form or by any means, without the prior written permission of the publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw-Hill for their individualcourse preparation. If you are a student using this Manual, you are using it without permission.
-
8/2/2019 Numerical Method for engineers-chapter 19
2/25
2
t Radiation cos( 0t ) sin( 0t )y cos( 0t
) y sin( 0t )15 144 0.96593 0.25882 139.093 37.270
45 188 0.70711 0.70711 132.936 132.936
75 245 0.25882 0.96593 63.411 236.652
105 311 -0.25882 0.96593 -80.493 300.403
135 351 -0.70711 0.70711 -248.194 248.194165 359 -0.96593 0.25882 -346.767 92.916
195 308 -0.96593 -0.25882 -297.505 -79.716
225 287 -0.70711 -0.70711 -202.940 -202.940
255 260 -0.25882 -0.96593 -67.293 -251.141
285 211 0.25882 -0.96593 54.611 -203.810
315 159 0.70711 -0.70711 112.430 -112.430
345 131 0.96593 -0.25882 126.536 -33.905
sum 2954 -614.175 164.429
The coefficients can be determined as
1667.24612
29540 === N
y A
363.102)175.614(122
)cos(2
01 === t y N A
4048.27)429.164(122
)sin(2
01 === t y N B
Therefore, the best-fit sinusoid is
)017453.0sin(4048.27)017453.0cos(363.1021667.246 t t R +=
The data and the model can be plotted as
0
100
200
300
400
0 60 120 180 240 300 360
The value for mid-August can be computed as
299.1698))225(017453.0sin(4048.27))225(017453.0cos(363.1021667.246 =+= R
PROPRIETARY MATERIAL . The McGraw-Hill Companies, Inc. All rights reserved. No part of this Manual may be displayed, reproduced or distributed in any form or by any means, without the prior written permission of the publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw-Hill for their individualcourse preparation. If you are a student using this Manual, you are using it without permission.
-
8/2/2019 Numerical Method for engineers-chapter 19
3/25
3
19.3 In the following equations, 0 = 2/T
( ) ( )[ ]( ) 00cos2cos
cossin 0000
00
=== T T
t
T
dt t T T
( ) ( )[ ]( ) 00sin2sin
sincos 0000
00
=== T T
t
T
dt t T T
( )( )
21
004
4sin24
2sin
2sin000
0
00
2
=+
=
= T
T
T
t t
T
dt t
T
T
( )( )
21
004
4sin24
2sin
2cos 000
0
00
2
=
+
=
+
=
T
T
T
t t
T
dt t
T
T
( ) ( ) ( )00
22sin
2sinsincos
0
2
00
02
000
=== T T
t
T
dt t t T T
19.4 a0 = 0
( )
( ) ( ) ( )
2/
2/
00
020
2/
2/0
sincos14
cos22
T
T
T
T k
t k k t
t k k T
dt t k t T
a
+=
=
( )
( )( ) ( )
2/
2/
00
020
2/
2/0
cossin14
sin22
T
T
T
T k
t k k
t t k
k T
dt t k t T
b
=
=
On the basis of these, all as = 0. For k = odd,
b k k =2
For k = even,
bk
k = 2
PROPRIETARY MATERIAL . The McGraw-Hill Companies, Inc. All rights reserved. No part of this Manual may be displayed, reproduced or distributed in any form or by any means, without the prior written permission of the publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw-Hill for their individualcourse preparation. If you are a student using this Manual, you are using it without permission.
-
8/2/2019 Numerical Method for engineers-chapter 19
4/25
4
Therefore, the series is
( ) ( ) ( ) ( )+++= t t t t t f 0000 4sin21
3sin32
2sin1
sin2
)(
The first 4 terms are plotted below along with the summation:
-1
0
1
-1 0 1
19.5 a0 = 0.5
( ) ( )
( )( )
( ) ( )( )
( )++=
+=
1
02
0
12
1
0
0
1
sincossincos1
coscos22
k t k t
k
t k k
t k t
k
t k
dt t k t dt t k t a k
( )( )1cos2= 2
k
k
bk = 0
Substituting these coefficients into Eq. (19.17) gives
( ) ( ) ( )+= t t t t f
5cos25
43cos
9
4cos
421
)(222
This function for the first 4 terms is displayed below:
-0.5
0
0.5
1
-2 -1 0 1 2
PROPRIETARY MATERIAL . The McGraw-Hill Companies, Inc. All rights reserved. No part of this Manual may be displayed, reproduced or distributed in any form or by any means, without the prior written permission of the publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw-Hill for their individualcourse preparation. If you are a student using this Manual, you are using it without permission.
-
8/2/2019 Numerical Method for engineers-chapter 19
5/25
5
19.6
2 4
-0.7
0
0.7
2 4
2 4
-0.7
0
0.7
2 4
19.7
2 4
-0.5
0
0.5
2 4
19.8
-0.6
0
0.6
1.2
0 5 10
19.9
-0.4
0
0.4
4
4
-0.4
0
0.4
4
4
4
PROPRIETARY MATERIAL . The McGraw-Hill Companies, Inc. All rights reserved. No part of this Manual may be displayed, reproduced or distributed in any form or by any means, without the prior written permission of the publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw-Hill for their individualcourse preparation. If you are a student using this Manual, you are using it without permission.
-
8/2/2019 Numerical Method for engineers-chapter 19
6/25
-
8/2/2019 Numerical Method for engineers-chapter 19
7/25
7
19.11 The program from Prob. 19.11 can be modified slightly to compute a DFT for thetriangular wave from Prob. 19.8. Here is the part that is modified up to the point that the DFTroutine is called. The remainder of the program is identical to the one from Prob. 19.11.
Option Explicit
Sub Dfourier()Dim i As Integer, N As IntegerDim f(127) As Double, re(127) As Double, im(127) As Double, t As DoubleDim pi As Double, Tp As Double, dt As Double, omega As DoubleDim t1 As Double, t2 As Double, Ni As Integerpi = 4# * Atn(1#)N = 32omega = 2 * pi / Nt = 0#Tp = 2 * pidt = 4 * Tp / NFor i = 0 To N - 1
f(i) = Sin(t)If f(i) < 0 Then f(i) = 0t = t + dt
Next iCall DFT(f, N, re, im, omega)
The results for the n = 32 case are displayed below:
index f(t) real imaginary0 0 0.3018 01 0.7071 0 0
2 1 0 0
3 0.7071 0 0
4 0 0 -0.25
5 0 0 06 0 0 0
7 0 0 0
8 0 -0.125 0
9 0.7071 0 0
10 1 0 0
11 0.7071 0 0
12 0 0 0
13 0 0 0
PROPRIETARY MATERIAL . The McGraw-Hill Companies, Inc. All rights reserved. No part of this Manual may be displayed, reproduced or distributed in any form or by any means, without the prior written permission of the publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw-Hill for their individualcourse preparation. If you are a student using this Manual, you are using it without permission.
-
8/2/2019 Numerical Method for engineers-chapter 19
8/25
-
8/2/2019 Numerical Method for engineers-chapter 19
9/25
9
dt = 0.01For i = 0 To N - 1
re(i) = Cos(2 * 12.5 * pi * t)im(i) = 0#f(i) = re(i)t = t + dt
Next iCall FFT(N, re, im)Range("A1").SelectActiveCell.Value = "INDEX"ActiveCell.Offset(0, 1).SelectActiveCell.Value = "f(t)"ActiveCell.Offset(0, 1).SelectActiveCell.Value = "REAL"ActiveCell.Offset(0, 1).SelectActiveCell.Value = "IMAGINARY"Range("A2:D1026").ClearContentsRange("A2").SelectFor i = 0 To N - 1
ActiveCell.Value = iActiveCell.Offset(0, 1).SelectActiveCell.Value = f(i)ActiveCell.Offset(0, 1).SelectActiveCell.Value = re(i)ActiveCell.Offset(0, 1).SelectActiveCell.Value = im(i)ActiveCell.Offset(1, -3).Select
Next iRange("A1").SelectEnd Sub Sub FFT(N, x, y)Dim i As Integer, j As Integer, m As IntegerDim N2 As Integer, N1 As Integer, k As Integer, l As IntegerDim pi As Double, xN As Double, angle As DoubleDim arg As Double, c As Double, s As DoubleDim xt As Double, yt As Double
xN = Nm = CInt(Log(xN) / Log(2#))pi = 4# * Atn(1#)N2 = NFor k = 1 To m
N1 = N2N2 = N2 / 2angle = 0#arg = 2 * pi / N1For j = 0 To N2 - 1
c = Cos(angle)s = -Sin(angle)For i = j To N - 1 Step N1
l = i + N2xt = x(i) - x(l)
x(i) = x(i) + x(l)yt = y(i) - y(l)y(i) = y(i) + y(l)x(l) = xt * c - yt * sy(l) = yt * c + xt * s
Next iangle = (j + 1) * arg
Next jNext k
PROPRIETARY MATERIAL . The McGraw-Hill Companies, Inc. All rights reserved. No part of this Manual may be displayed, reproduced or distributed in any form or by any means, without the prior written permission of the publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw-Hill for their individualcourse preparation. If you are a student using this Manual, you are using it without permission.
-
8/2/2019 Numerical Method for engineers-chapter 19
10/25
-
8/2/2019 Numerical Method for engineers-chapter 19
11/25
11
For i = 0 To N - 1re(i) = Sin(t)If re(i) < 0 Then re(i) = 0im(i) = 0f(i) = re(i)t = t + dt
Next iCall FFT(N, re, im)
The results for the n = 32 case are displayed below:
index f(t) real imaginary0 0 0.3018 01 0.7071 0 0
2 1 0 0
3 0.7071 0 0
4 0 0 -0.25
5 0 0 0
6 0 0 0
7 0 0 0
8 0 -0.125 0
9 0.7071 0 010 1 0 0
11 0.7071 0 0
12 0 0 0
13 0 0 0
14 0 0 0
15 0 0 0
16 0 -0.0518 0
17 0.7071 0 0
18 1 0 0
19 0.7071 0 0
20 0 0 0
21 0 0 0
22 0 0 0
23 0 0 024 0 -0.125 0
25 0.7071 0 0
26 1 0 0
27 0.7071 0 0
28 0 0 0.25
29 0 0 0
30 0 0 0
31 0 0 0
The runs for N = 32, 64 and 128 were performed with the following results obtained. (Notethat we had to call the function numerous times to obtain measurable times. These times werethen divided by the number of function calls to determine the time per call shown below)
N time (s)32 0.00021964 0.000484
128 0.001078
PROPRIETARY MATERIAL . The McGraw-Hill Companies, Inc. All rights reserved. No part of this Manual may be displayed, reproduced or distributed in any form or by any means, without the prior written permission of the publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw-Hill for their individualcourse preparation. If you are a student using this Manual, you are using it without permission.
-
8/2/2019 Numerical Method for engineers-chapter 19
12/25
12
A plot of time versus N log 2 N yielded a straight line (see plot below). Thus, the result verifiesthat the execution time N log 2 N .
0.0000
0.0002
0.0004
0.00060.0008
0.0010
0.0012
0 200 400 600 800 1000
19.14
19.15 An Excel worksheet can be developed with columns holding the dependent variable ( o)along with the independent variable ( T ). In addition, columns can be set up holding
progressively higher powers of the independent variable.
The Data Analysis Toolpack can then be used to develop a regression polynomial asdescribed in Example 19.4. For example, a fourth-order polynomial can be developed as
PROPRIETARY MATERIAL . The McGraw-Hill Companies, Inc. All rights reserved. No part of this Manual may be displayed, reproduced or distributed in any form or by any means, without the prior written permission of the publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw-Hill for their individualcourse preparation. If you are a student using this Manual, you are using it without permission.
-
8/2/2019 Numerical Method for engineers-chapter 19
13/25
13
Notice that we have checked off the Residuals box. Therefore, when the regression isimplemented, the model predictions (the column labeled Predicted Y) are listed along withthe fit statistics as shown below:
PROPRIETARY MATERIAL . The McGraw-Hill Companies, Inc. All rights reserved. No part of this Manual may be displayed, reproduced or distributed in any form or by any means, without the prior written permission of the publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw-Hill for their individualcourse preparation. If you are a student using this Manual, you are using it without permission.
-
8/2/2019 Numerical Method for engineers-chapter 19
14/25
14
As can be seen, the results match to the level of precision (second decimal place) of theoriginal data. If a third-order polynomial was used, this would not be the case. Therefore, weconclude that the best-fit equation is
473423 1013802.81029123.110023438.94116617.061976.14 T T T T o ++=
19.16 An Excel worksheet can be developed with columns holding the dependent variable ( o)along with the independent variable ( T ). The Data Analysis Toolpack can then be used todevelop a linear regression.
Notice that we have checked off the Confidence Level box and entered 90%. Therefore, whenthe regression is implemented, the 90% confidence intervals for the coefficients will be
computed and displayed as shown below:
As can be seen, the 90% confidence interval for the intercept ( 1.125, 4.325) encompasseszero. Therefore, we can redo the regression, but forcing a zero intercept. As shown below,this is accomplished by checking the Constant is Zero box.
PROPRIETARY MATERIAL . The McGraw-Hill Companies, Inc. All rights reserved. No part of this Manual may be displayed, reproduced or distributed in any form or by any means, without the prior written permission of the publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw-Hill for their individualcourse preparation. If you are a student using this Manual, you are using it without permission.
-
8/2/2019 Numerical Method for engineers-chapter 19
15/25
-
8/2/2019 Numerical Method for engineers-chapter 19
16/25
16
Here is the command to make the prediction:
>> yp=spline(x,y,1.5)
yp =21.3344
(b) To prescribe zero first derivatives at the end knots, the y vector is modified so that thefirst and last elements are set to the desired values of zero. The plot and the prediction bothindicate that there is less overshoot between the first two points because of the prescribedzero slopes.
>> yd=[0 y 0];>> yy=spline(x,yd,xx);>> plot(x,y,'o',xx,yy)>> yy=spline(x,yd,1.5)
yy =20.5701
PROPRIETARY MATERIAL . The McGraw-Hill Companies, Inc. All rights reserved. No part of this Manual may be displayed, reproduced or distributed in any form or by any means, without the prior written permission of the publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw-Hill for their individualcourse preparation. If you are a student using this Manual, you are using it without permission.
-
8/2/2019 Numerical Method for engineers-chapter 19
17/25
17
19.18 The following MATLAB session develops the fft along with a plot of the power spectraldensity versus frequency.
>> t=0:63;>> y=cos(10*2*pi*t/63)+sin(3*2*pi*t/63)+randn(size(t));>> Y=fft(y,64);>> Pyy=Y.*conj(Y)/64;>> f=1000*(0:31)/64;>> plot(f,Pyy(1:32))
19.19 (a) Linear interpolation
>> T=[0 8 16 24 32 40];>> o=[14.62 11.84 9.87 8.42 7.31 6.41];>> Ti=0:1:40;>> oi=interp1(T,o,Ti);>> plot(T,o,'o',Ti,oi)
PROPRIETARY MATERIAL . The McGraw-Hill Companies, Inc. All rights reserved. No part of this Manual may be displayed, reproduced or distributed in any form or by any means, without the prior written permission of the publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw-Hill for their individualcourse preparation. If you are a student using this Manual, you are using it without permission.
-
8/2/2019 Numerical Method for engineers-chapter 19
18/25
18
>> ol=interp1(T,o,10)ol =
11.3475
(b) Third-order regression polynomial
>> p=polyfit(T,o,3)p =
-0.0001 0.0074 -0.3998 14.6140>> oi=polyval(p,Ti);>> plot(T,o,'o',Ti,oi)>> op=polyval(p,10)op =
11.2948
(c) Cubic spline
>> oi=spline(T,o,Ti);>> plot(T,o,'o',Ti,oi)
PROPRIETARY MATERIAL . The McGraw-Hill Companies, Inc. All rights reserved. No part of this Manual may be displayed, reproduced or distributed in any form or by any means, without the prior written permission of the publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw-Hill for their individualcourse preparation. If you are a student using this Manual, you are using it without permission.
-
8/2/2019 Numerical Method for engineers-chapter 19
19/25
19
>> os=spline(T,o,10)os =
11.2839
19.20 (a) Eighth-order polynomial:
>> x=linspace(-1,1,9);>> y=1./(1+25*x.^2);>> p=polyfit(x,y,8);>> xx=linspace(-1,1);>> yy=polyval(p,xx);>> yr=1./(1+25*xx.^2);>> plot(x,y,'o',xx,yy,xx,yr,'--')
(b) linear spline:
>> x=linspace(-1,1,9);>> y=1./(1+25*x.^2);>> xx=linspace(-1,1);>> yy=interp1(x,y,xx);>> yr=1./(1+25*xx.^2);>> plot(x,y,'o',xx,yy,xx,yr,'--')
PROPRIETARY MATERIAL . The McGraw-Hill Companies, Inc. All rights reserved. No part of this Manual may be displayed, reproduced or distributed in any form or by any means, without the prior written permission of the publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw-Hill for their individualcourse preparation. If you are a student using this Manual, you are using it without permission.
-
8/2/2019 Numerical Method for engineers-chapter 19
20/25
20
(b) cubic spline:
>> x=linspace(-1,1,9);>> y=1./(1+25*x.^2);>> xx=linspace(-1,1);>> yy=spline(x,y,xx);>> yr=1./(1+25*xx.^2);>> plot(x,y,'o',xx,yy,xx,yr,'--')
19.21
PROGRAM FitpolyUse IMSLImplicit NONEInteger::ndeg,nobs,i,jParameter (ndeg=4, nobs=6)Real:: b (ndeg + 1), sspoly(ndeg + 1), stat(10)Real:: x(nobs), y(nobs), ycalc(nobs)Data x/0,8,16,24,32,40/Data y/14.62,11.84,9.87,8.42,7.31,6.41/Call Rcurv(nobs, x, y, ndeg, b, sspoly, stat)Print *, 'Fitted polynomial is'Do i = 1,ndeg+1
Print 10, i - 1, b(i)
PROPRIETARY MATERIAL . The McGraw-Hill Companies, Inc. All rights reserved. No part of this Manual may be displayed, reproduced or distributed in any form or by any means, without the prior written permission of the publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw-Hill for their individualcourse preparation. If you are a student using this Manual, you are using it without permission.
-
8/2/2019 Numerical Method for engineers-chapter 19
21/25
21
End DoPrint *Print 20, stat(5)Print *Print *, ' No. X Y YCALC'Do i = 1,nobs
ycalc = 0Do j = 1,ndeg+1
ycalc(i) = ycalc(i) + b(j)*x(i)**(j-1)End DoPrint 30, i, x(i), y(i), ycalc(i)
End Do10 Format(1X, 'X^',I1,' TERM: ',F12.7)20 Format(1X,'R^2: ',F8.3,'%')30 Format(1X,I8,3(5X,F8.4))End
Fitted polynomial isX^0 TERM: 0.146198E+02X^1 TERM: -.411661E+00
X^2 TERM: 0.902330E-02X^3 TERM: -.129118E-03X^4 TERM: 0.813734E-06
R^2: 100.000%
No. X Y YCALC1 0.0000 14.6200 14.61982 8.0000 11.8400 11.84123 16.0000 9.8700 9.86764 24.0000 8.4200 8.42245 32.0000 7.3100 7.30886 40.0000 6.4100 6.4102
19.22 Using Excel, plot the data and use the trend line function to fit a polynomial of specificorder. Obtain the r 2 value to determine the goodness of fit.
y = 7.6981E-04x 3 - 6.0205E-02x 2 + 1.0838E+00x - 2.2333E+00
R 2 = 9.0379E-01
-10
1
2
3
4
5
0 5 10 15 20 25
PROPRIETARY MATERIAL . The McGraw-Hill Companies, Inc. All rights reserved. No part of this Manual may be displayed, reproduced or distributed in any form or by any means, without the prior written permission of the publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw-Hill for their individualcourse preparation. If you are a student using this Manual, you are using it without permission.
-
8/2/2019 Numerical Method for engineers-chapter 19
22/25
-
8/2/2019 Numerical Method for engineers-chapter 19
23/25
23
-1.5
-1
-0.50
0.5
1
1.5
0 0.2 0.4 0.6 0.8 1
n=1
n=2
n=3
n=4n=5
n=6
sum
19.24 This problem is convenient to solve with MATLAB
(a) When we first try to fit a sixth-order interpolating polynomial, MATLAB displays thefollowing error message
>> x=[0 100 200 400 600 800 1000];>> y=[0 0.82436 1 .73576 .40601 .19915 .09158];>> p=polyfit(x,y,6);Warning: Polynomial is badly conditioned. Remove repeated data points
or try centering and scaling as described in HELP POLYFIT.> In polyfit at 79
Therefore, we redo the calculation but centering and scaling the x values as shown,
>> xs=(x-500)/100;>> p=polyfit(xs,y,6);
Now, there is no error message so we can proceed.
>> xx=linspace(0,1000);>> yy=polyval(p,(xx-500)/100);>> yc=xx/200.*exp(-xx/200+1);>> plot(x,y,'o',xx,yy,xx,yc,'--')
PROPRIETARY MATERIAL . The McGraw-Hill Companies, Inc. All rights reserved. No part of this Manual may be displayed, reproduced or distributed in any form or by any means, without the prior written permission of the publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw-Hill for their individualcourse preparation. If you are a student using this Manual, you are using it without permission.
-
8/2/2019 Numerical Method for engineers-chapter 19
24/25
24
This results in a decent plot. Note that the interpolating polynomial (solid) and the originalfunction (dashed) almost plot on top of each other:
(b) Cubic spline:
>> x=[0 100 200 400 600 800 1000];>> y=[0 0.82436 1 .73576 .40601 .19915 .09158];>> xx=linspace(0,1000);>> yc=xx/200.*exp(-xx/200+1);>> yy=spline(x,y,xx);>> plot(x,y,'o',xx,yy,xx,yc,'--')
For this case, the fit is so good that the spline and the original function are indistinguishable.
(c) Cubic spline with clamped end conditions (zero slope):
>> x=[0 100 200 400 600 800 1000];>> y=[0 0.82436 1 .73576 .40601 .19915 .09158];>> ys=[0 y 0];
PROPRIETARY MATERIAL . The McGraw-Hill Companies, Inc. All rights reserved. No part of this Manual may be displayed, reproduced or distributed in any form or by any means, without the prior written permission of the publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw-Hill for their individualcourse preparation. If you are a student using this Manual, you are using it without permission.
-
8/2/2019 Numerical Method for engineers-chapter 19
25/25
25
>> xx=linspace(0,1000);>> yc=xx/200.*exp(-xx/200+1);>> yy=spline(x,ys,xx);>> plot(x,y,'o',xx,yy,xx,yc,'--')
For this case, the spline differs from the original function because the latter does not have
zero end derivatives.
PROPRIETARY MATERIAL . The McGraw-Hill Companies, Inc. All rights reserved. No part of this Manual maybe displayed reproduced or distributed in any form or by any means without the prior written permission of the