Chapter 1Practical ExercisesIntroductionThis document contains the practicum assignments of this course.From now on, the ‘real’ numerical part is going to start: we consider problems from mathematics,all of which originate from physics, chemistry and/or engineering, where in general,we cannot find closed-form solutions. In such cases, we have to use the computer to find ananswer, together with a numerical method. In Matlab, many of those numerical methodsare built in, and we will use them as a tool.However, there is a problem: whatever you do, and whatever mistakes you make, thecomputer will nevertheless give an answer, and that answer may have nothing to do withthe answer you were looking for. That’s why in the exercises you are asked to criticallyexamine your answers, and adapt your answers accordingly.Whenever an answer with error is requested, we always want to see the answer= A ± ∆ in such a form, that ∆ has 1 significant digit and that the number ofdigits of A is in accordance with that.Example:approximation = 1.234567890 ± 0.000067890 leads to answer = 1.23457 ± 7 · 10−5.Indeed, the (wrong!) answersanswer = 1.23457 ± 0.000067890 and answer = 1.234567890 ± 7 · 10−5do not look consistent!11.0 Matlab1.0.5 Executing a part of a program many timesIn programs, you often want to perform certain calculations very often, possibly each timeslightly different. For example if you want to add up the first billion natural numbers. Inthat case you know how often it has to be done (namely, one billion times), but sometimesyou don’t and then you use a while (because there is no alternative!); in the first case, youuse a for.While statementThe way of writing a while (’zolang’) is as follows:while(expression)do;endAs long as expression is true, do is executed. THUS, the following program won’t stop(except when pulling the plug, or Ctrl-Alt-Del):i=1;while(i>0)i=i+1;endSo the while statement is very error-prone, therefore avoid it if possible.For statementThe following example hopefully speaks for itself and adds up the first billion naturalnumbers (500000500000): 11Using File-Preferences...-Command Window, set the Numeric Format to ‘long e‘ and the Numeric Displayto ’loose’, and press Apply and OK!! It can also be done with the Matlab command >> format longe.2sum=0;for i=1:1000000sum=sum+i;endExercise 1.0.6. Write a function Q(m, n) which computes Pnk=m k−1for various m, n.Now compute z = Q(1, 109) − log(109) (analytical answer Q(1, n) − log(n) as n → ∞:γEuler = 0.5772156649015328606065121 . . .)1.1 Error analysis1.1.1 Condition of linear equationsIn this exercise, we will look more closely at solving linear equations:solve x from: A · x = b.If the matrix is nonsingular, then (mathematically) the system can be solved exactly. Ona computer however, the answer is not exact in general.It is therefore an important question how good the solution we find is, or, stated in a slightlydifferent way:• How sensitive is the answer x under small perturbations of e.g. the right hand sideb?2Slightly more mathematically formulated:• How large is δx := R(b + δb) − R(b) in relation to δb, or: to what extent is the outputperturbed as a result of a perturbation of the input?If the perturbation of the output is small, relatively speaking, in relation to the perturbationof the input, also relatively speaking, then we say the problem is well-conditioned. If thatratio is large, then the problem is said to be ill-conditioned.We will illustrate some things using the problem above. As matrix A we use a so-calledHilbert matrix. Hilbert matrices are known for being ill-conditioned. Now we choosethe right hand side vector b such that b = A · (1, 1, . . . , 1)t,3so the exact solution x =(1, 1, . . . , 1)tis known.Write a function which, given n,1. determines the n × n Hilbert matrix A, (help hilb),2. determines the n × 1 vector x with ones, (help ones),2Indeed, it is almost always the case that b is not exactly known, for example because of round-off errors.3In Matlab, [1, 1, 1] is a row vector, so with size 3 × 1, and [1; 1; 1] a column vector, so with size 1 × 3.Hence, we have that [1, 1, 1] = [1; 1; 1]t.43. computes the right hand side b, which equals the exact solution x = (1, . . . ,1)t,4. subsequently determines the actual numerical solution xn: xn = A\b,5. finally computes the quantities kA · xn − bk ´and kxn − (1, . . . , 1)tk, (help norm).Complete the following table by calling the function for different values of n. Here, δb :=A · xn − b can be interpreted as the perturbation of the input which causes a perturbationδx := xn − (1, . . . , 1)t of the output, since by linearity:δx = R(b + δb) − R(b) = ANote that, although the numerical solution xn seems good because kA · xn − bk ≈ 0 (thetype double implies approximately 15 significant digits), we see that, particularly whenn > 10, this need not be true! That is the consequence of an ill-conditioned system.1.1.2 Accuracy and conditionSometimes an answer must be given very precisely, such asanswer = 1.234567890123456 · 10−4,but sometimes, only the order of magnitude suffices:answer = 1 · 10−4.The number of digits you include depends on the accuracy of the result, or how accurateyou think it is.In some cases, the computation of a function value can be strongly influenced by:51. the way a computation is performed, and/or2. the order of the operations, and/or3. round-off errors.We are going to examine this using the computation of the polynomial R(x),R(x) = 177 − 21x + 3(9x + 550)2 − 38x3 − 558x4 + 2(3x + 434)5 − x6for x = 972 in the following 4 ways:• Algorithm A: by “completely expanding” every term,for example: 558x4 = 558 * x * x * x * x ,or: 2(3x + 434)5 = 2 * h * h * h * h * h with h = 3*x + 434.• Algorithm B: using the standard functions exp( ) and log( ) (’natural logarithm’!),for example: 558x4 = 558 e4 ln x = 558 * exp(4 * log(x)) ,or: 2(3x + 434)5 = 2 e5 ln(3x+434) = 2 * exp(5 * log(3*x + 434)).You also have to compute the value of the polynomial by interchanging terms:• R1(x) = 177 − 21x + 3(9x + 550)2 − 38x3 − 558x4 + 2(3x + 434)5 − x6• R2(x) = −x6 + 2(3x + 434)5 − 558x4 − 38x3 + 3(9x + 550)2 − 21x + 177For every possibility, write a separate function (thus, four functions).method answer that Matlab givesC[R1A(972)]C[R1B(972)]C[R2A(972)]C[R2B(972)]The correct result is R(972) = 1.6With one of the outcomes, namely C[R . . .(972)] we obtain an estimate of the conditionnumber:It is given that, on basis of (??), we find as exact value cP (972) ≈ 1.4 · 1018.Do you prefer one of the ways of computation? Yes / no , because . . . . . . . . . . . . . . . . . . . . . .1.1.3 Problems and algorithmsIn this exercise, we want to make clear the difference between well- and ill-conditionedproblems, but also between good and bad algorithms: if you want to compute something,you can do that in a stupid way, but sometimes also in a (more) intelligent way.As an example, we are interested in the following integralsyn := Z 1.In principle, all these integrals can be determined analytically, but looking at the solutionof the integral in this exercise, you won’t like that (except for a few mathematicians).We consider the problem P:for which we have that (we have calculated that using Maple, not by hand!)y13 = −2541865828329 log (10) + 5083731656658 log (3) + 1072320426800656740040.Of course, we are much more interested in the numerical value of the integral.Part AThe following trick provides a way to compute y13.we can determine y13 from the recursion: that is, fromyn = −9yn−1 +1n(1.1.1)with n = 1 we can compute y1; subsequently, using (1.1.1) and n = 2 we can compute y2as well, etc. Equation (1.1.1) is called the recursion formula.Hence, this algorithm, which we will call algorithm A, has the following form:A : yn = −9yn−1 +1n, n = 1, 2, . . . , 13, and y0 = log(10/9). (1.1.2)If we execute this algorithm on a computer, than we must realise that errors occur immediatelywhen computing y0 numerically, namely a round-off error. And this error, and allother round-off errors which we will make thereafter, propagate to the final result. Thenthe question is: how strongly will this propagate? Or, in other words, is this algorithmsufficiently stable or not (well- or ill-conditioned)?A: Numerical experimentWrite a Matlab program, which executes algorithm A, and write down (in 16 decimals; useformat long e) the results for y0 and y13:Algorithm A :Answer (using common sense) the following question: The approximation of y13 is (good /reasonable / very bad)daa.4In order to ‘measure’ the stability of the algorithm, we now do the following: we perturbthe value of the input (that is, y0) on purpose, and observe the effect on the answer, y13.Execute the same Matlab program with algorithm A, but now with y, and write down the results again:Algorithm A4daa = delete as appropriate.8And answer (using common sense) the following question: This y∗13 as an approximation ofy13 is (good / reasonable / very bad)daa.A: StabilityUsing these answers, we can estimate the condition of the algorithm A 5(and using that,say whether the algorithm is stable):1. PA is the solution of the problem P when using algorithm A, so y13,2. x is the input, so here y0,3. |�| is the relative error in the input.From this, the approximation follows:cA,P ≈ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .And we can go one step further: the y0 = log(10/9) which we have used in the algorithmA to compute y13 isn’t exact either! The relative error in y0 will have at most the value11�C, with machine precision �C ≈ 2.2 · 10−16, becauseC[y0] = log(10/9 (1 + �1)) (1 + �2) = . . . ≈ y0 + �1 + y0�2 , with |�i| ≤ �C.What can you say about the possible error in y13 as computed using algorithm A?relative error in y13 ≤ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .and hence,absolute error in y13 ≤ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Is the value of y13 we have found with this error estimate consistent with the exact valueof y13?(yes / no)daa , because y13 = . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .NB. You can compute the exact value with the function quad in Matlab (see help quad?)using the call:5Actually, we should say: the condition of problem P when we solve the problem using algorithm A.9>> quad(@(x) x.^13./(x+9),...)A: Stability explainedAn absolute error dn−1 in yn−1 propagates to the error of yn during one step of algorithmA, use (1.1.2):yn + dn = −9(yn−1 + dn−1) + 1n, so dn = . . . . . . dn−1. (1.1.3)and henced13 = . . . . . . d0. (1.1.4)And this (is / is not)daa consistent in good approximation with the data:the true absolute error in y13 = . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .and using the above, we find that this should bethe expected absolute error in y13 = d13 = . . . . . . d0 = . . . . . . �C = . . . . . . . . . . . . . . . . . .Part BNow, we ‘turn around’ the equation (1.1.1) and we are going to use it for B:For further investigation of this recursion, we will, assuming a chosen initial value yN ,continue the backward recursion up to y0. The result obtained can be compared with theexact value, namely log(10/9) = 0.10536051565782630122.B: Numerical experimentWe choose N = 25 and as an approximation of y25, we choose for convenience the value 0.Write down the following outcomes of the algorithm B:Algorithm B :B: StabilityIf we start with y25 = 10000, the same correct value for y0 is found (verify it) !!?? It followsthat (the stability of) algorithm B is much better than (that of) algorithm A. Estimate,just as in the equations (1.1.3)-(1.1.4), the error amplification/reduction when computingy0 given an absolute error d25 in y25d0 = . . . . . . d25,and if the error in y25 approximately equals 10000, it follows thatd0 = . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .and this (is / is not)daa consistent with the value found.What should we choose for N in order to find y13 in 15 significant digits as well, assumingyN = 0?N = is sufficient because . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Conclusion: It follows from the above that the condition of the problem “compute y13 = R 10x13x+9 dx” (is good / is good, provided that the correct algorithm is used / (strongly)depends on the algorithm that is used)daa (choose one answer!).111.2 Errors in numerical differentiationLater in the course, we will repeatedly encounter one of the most practical problems innumerical mathematics, namely solving ordinary and also partial differential equations(ODE, PDE).One of the numerical methods which is very popular, is called discretisation. In that case,you look for an approximate solution to a differential equation which you only know ata finite number of points, and not at ´every point. And because you have to computederivatives of functions as well (after all, a DE is an equation which contains derivatives!)it is necessary to be able to estimate derivatives on the basis of a function which you onlyknow at a number of points.We consider the following formula to determine the third derivative of a function f, or thevalue of f(3)(x0):D3(h) = f(x0 + 2h) − 2f(x0 + h) + 2f(x0 − h) − f(x0 − 2h)2h3= f(3)(x0) + C · h2 + O(h4), C = f(5)(x0)/4.From this formula (plus error), at first sight you would say that you have to make h assmall as possible. After all, the error O(h2) then becomes smaller and smaller.Remarkably (?) enough, this is not correct, but that is because we also make round-offerrors. That’s what we want to investigate in more detail in this exercise.By means of an error analysis, we want to determine the optimal choice for h. Thereafter,we verify this analytical result with a simple experiment.If we compute D3(h), then we make errors. For convenience, in the following error analysiswe only consider the round-off error in computing the function values of f and we makethe rough assumptionabsolute error in computing f(x) ≈ |f(x0)| �C.Then it follows that:|computed D3(h) − f(3)(x0)| ≈ |C| h2 + . . . . . . �CHence, the error we make is the sum of the last two terms. This is minimised as functionWe are going to verify the analytical expressions we have found experimentally. ComputeD3(h) as approximation of the value f(3)(1) of f(x) = exfor h = ( 12)j, j = 0, 1, 2, . . . , 20.The best value of h which follows from the experiment is h ≈ . . . . . . . . . . . . . . .In this example, the best value for the analytical derivative is h ≈ . . . . . . . . . . . . . . .Conclusion: the experimental results are consistent with the theoretical values. The minordeviations are caused by . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 代写mathematics、Matlab编程语言代做、代写M. . . . . . . .. . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .131.3 InterpolationOne of the ways to draw a smooth function through discrete points is by means of interpolation.Usually, polynomials are used for that (but certainly not always!) and for now, werestrict ourselves to that.Interpolation means that that smooth function has to pass through the data points; anatural property, at least if the data doesn’t contain much noise (we will address thatproblem in section 1.6).1.3.1 Polynomial interpolationIn order to investigate the properties of interpolation (e.g. how well the method works, andwhat you have to do, but also what you shouldn’t do), we proceed as follows.We choose a function with certain properties (e.g. a simple function, a smooth function,or a wild function – we will come back to what this exactly means mathematically later),and we draw discrete data from that, that is, we take as data the values of the function ata certain (finite) set of points. Thereafter, we are going to test our method (in this case,determining a polynomial that passes through those points) to find out how good it is. 6And we can also (try to) analyse how we should choose the data points in order to obtainan optimal result, i.e. that the resulting function lies ‘as close as possible’ to the originalfunction.We need the following ingredients:1. a function from which we draw the data,2. a grid, i.e. the set of points where we assume the function values are given,3. a numerical code which computes the polynomial (the interpolant),4. and subsequently visualises the results – you can read off the error from this.Instructions for the outline of an M-file (or multiple M-files):1. write a function f which determines, for given values of x (a vector), the associatedfunction values (and this function is adapted repeatedly),6In reality, we don’t know the function of course, but then we do know where the data comes from, whichmight give us a hint of the function associated with it.142. we consider two types of grids, namely an equidistant gridxk = −1 +2kn∈ [−1, 1], k = 0, . . . , n,and a so-called Chebyshev grid:xk = − cos((2k + 1)π2n + 2) ∈ [−1, 1], k = 0, . . . , n;do this in two functions, with argument n, which outputs a set of points x, y (inthose functions, first create a set k=[0:n], and subsequently the grid x and usingthat, the function values y; see also the Matlab exercise ??NB. when using a for-statement to fill the vector x, you should note that every indexshould be a positive integer, so x(1) = x0, x(2) = x1, etc.)3. the Matlab codep = polyfit(x,y,n);computes the coefficients of the polynomial p that interpolates,4. and since Matlab works completely discrete, we create another data set xf, finer thanthe given data set, to compare the result (polynomial) with the original function, e.g.xf = -1:0.001:1;pf = polyval(p,xf);ff = f(xf);plot(xf,pf,’o’,xf,ff,’-’)You also can change the latter such that you see the plot of the difference (how?).We hope that the programming didn’t take too much effort (surely not – they are just afew lines) and we can now start to work. We consider data from different functions. Onemore notation: ∆pn means the maximum value of the truncation error of the problem, forgiven n and f, for the equidistant grid, ∆qn for the Chebyshev grid.i. Data: n ∆pnf(x) = x3 1x ∈ [−1, 1] 23The program works well because . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .15. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .The interpolation polynomials for n = 1 and n = 2 are identical since (use symmetry!). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .ii.Data: n ∆pn ∆qnf(x) = ex(= exp(x)) 4x ∈ [−1, 1] 812The truncation errors are consistent with the theory, because it should hold that (informulas):∆pn ≤ . . . . . . . . . and ∆qn ≤ . . . . . . . . .iii-a. Data: n ∆pn ∆qnf(x) = 125x2+1 4x ∈ [−1, 1] 1220iii-b. Data: n ∆pn ∆qnf(x) = 1x2+1 4x ∈ [−1, 1] 1220The truncation errors in iii-b are significantly smaller than those in iii-a. Can yougive an explanation for that?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .16The graphs of the difference functions show an oscillating behaviour in all cases (i,ii andiii). Nonetheless, there is a remarkable difference between graphs based on an equidistantgrid on the one hand, and those based on a Chebyshev grid on the other hand, namely. . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1.3.2 Interpolation with rational functionsWe consider the interpolation problem once more (and we also use the notation from theprevious section and the M-file(s), but make sure you make a backup of the programs).Even if a function behaves ‘neatly’ on the interpolation interval, then that is not a guaranteefor a good interpolation (with a small truncation error). For example, a singular point(“pool”; at that point, the function has an asymptote) just outside the interpolation intervalhas quite some influence on the truncation error. We illustrate this using the function tan x(with an asymptote at x = π/2).We only use an equidistant grid (with interpolation polynomial pn and truncation error∆pn). We now take [1, 1.5] as interpolation interval (so, not [−1, 1]: adjustments?), so thatthe point π/2 = 1.57 . . . lies outside, but very close to the interval.Data: n ∆pnf(x) = tan x 6x ∈ [1, 1.5] 912It is (has become) clear that the interpolation of tan x on [1,1.5] is being influenced quitestrongly by the singular point at π/2, even for n = 12. Can we improve this?Instead of approximating the data set tan xi, we do the following: we consider the data(xi − π/2) tan xi, xi ∈ [1, 1.5]or in other words, we interpolate data drawn from this functiong(x) = (x − π/2) tan xThis function doesn’t have a singularity anymore at the point π/2, and therefore this datacan be interpolated more easily.17It seems a bit silly to approximate data which we cannot approximate well by changing thedata itself, but it is not:1. we draw data from g(x) = (x − π/2) tan x.2. we interpolate that data just as before; this yields a polynomial p(x).3. we divide this polynomial again by x − π/2:r(x) = p(x)x − π/2We now consider this function to be an approximation of the data drawn from f(x) =tan x. This function has the form of a polynomial divided by a polynomial, and forthat reason we cannot speak of polynomial interpolation anymore.Indeed, a function of this type is called a rational function.Show that r(x) interpolates the original data drawn from f:. . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Adjust your program such that you compute r(x) and subsequently, complete the followingtable: ∆rn now means the absolute error of r(x) against f(x).Data: n ∆rnf(x) = tan x 6x ∈ [1, 1.5] 912If everything went well, you observe better convergence behaviour! What you should notice(remember for the future) is that polynomial interpolation is not the Holy Grail. On theother hand: here, we knew that the data was drawn from a function with a singularitynearby, and we could adjust our method accordingly. In reality however, you often don’tknow that to do.181.4 ExtrapolationExtrapolation is a simple technique to obtain better results with ‘little effort’, and to obtainerror estimates. Because this technique can be applied to many problems, we will encounterextrapolation in the next sessions as well, but then as a part of a problem! In the problembelow, extrapolation is the central element.Compute xn for the following values of n = 1, . . . , 1024:Do this with the help of the following questions:1. we have that x1 = . . . . . .2. the relation between xn and xn−1 is the followingxn = Cn xn−1 with Cn = . . . . . .3. Why is it more efficient to use these two relations instead of the definition(1.4.1)?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4. A few values that you have found:Of course, it is impossible to compute the limit x∞ explicitly on a computer, and in thiscase you see from the numbers that the solution is not yet in sight. Therefore, we firstinvestigate the kind of convergence.195. In order to estimate how fast the series converges, we consider, just as in the lecturenotes, the following quotients:Numerically, we find from the previous table:Both quotients are so-called convergence factors. We conclude from the values in thelast table that the process converges as ( 1n/1n2 /1n3 )daa. In other words: the convergenceis (linear/quadratic/cubic)daa as a function of n.6. On the basis of the result above we can perform another extrapolation: we can approximatex∞ better with the following linear combination:yn = . . . . . . xn − . . . . . . xn/27. Using this last number, we can extrapolate another time:x∞ ≈ . . . . . . y512 − . . . . . . y256 = . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .but also en estimate of the error: the final answer (which is familiar to you, hopefully)x∞ = . . . . . . . . . . . . . . . . . . . . . . . . ± . . . . . . . . . . . .201.5 Boundary Value Problems1.5.1 A simple exampleIn example ??, the boundary value problemy00(x) = x · y(x) − 5 , 0 ≤ x ≤ 1 , y(0) = 0 , y(1) = 0 ,has been discussed extensively. Application of the finite difference method led to a systemof linear equations A · y = r.The solution of this system (together with the two boundary conditions) is a numericalapproximation of the exact solution y(x), x ∈ [0, 1], of the boundary value problem, whichis plotted in figure ??.It is now intended that you devise a strategy yourself for the question: give the bestpossible approximation of the solution in the middle of the interval, including a reliableerror estimate.Instructions:- fill A and r in Matlab, and determine the value of the solution in the middle of the interval,i.e. with Pn = yn/2.- for given n, define the matrix A as follows:A = sparse(n-1,n-1);A(1,1) = ....;..... % set the nonzero elements of A (for loop?)A(n-1,n-1) = ....;full(A) % check: take fore example n = 10 so that h = 1/10Now complete the following:I can determine the order of this method by e.g. carrying out the experiment for the followingvalues of n ≤ 128: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Therefore I have run the program for the following values of n ≤ 128, with correspondingresults:n = . . . . . . with Pn = . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .n = . . . . . . with Pn = . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .n = . . . . . . with Pn = . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .21n = . . . . . . with Pn = . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .The best answer, resulting from these measurements, is:y(0.5) = . . . . . . . . . . . . . . . . . . ± . . . . . . . . .Both those values are obtained as follows:The order of the method equals . . ., because . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Therefore the best value is determined from . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .with error estimate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1.5.2 The “buckling” problemToday, we are trainee research assistant (AIO) at prof. Van Huetink’s group (UT, mechanics,strength of materials). In order to get trained, we have to do a first calculation on the“buckling” problem (with thanks to Kees Vuik, TUD).We consider a rod with length L, width b and height d. It is clamped to the wall at the leftend (x = 0), and at the other end (x = L), pressure S is applied to the rod. The rod willalso bend by gravity.We want to know how the rod behaves for different values of S, i.e. how the deflection ydepends on the place x under the influence of the pressure S.We can formulate the problem mathematically as(0) = 0. E is the elastic modulus of the material, K the moment of inertia,and the term with q is responsible for the gravity:where ρ is the density and g the gravitational constant转自:http://www.3daixie.com/contents/11/3444.html