Главная » Просмотр файлов » Press, Teukolsly, Vetterling, Flannery - Numerical Recipes in C

Press, Teukolsly, Vetterling, Flannery - Numerical Recipes in C (523184), страница 19

Файл №523184 Press, Teukolsly, Vetterling, Flannery - Numerical Recipes in C (Press, Teukolsly, Vetterling, Flannery - Numerical Recipes in C) 19 страницаPress, Teukolsly, Vetterling, Flannery - Numerical Recipes in C (523184) страница 192013-09-15СтудИзба
Просмтор этого файла доступен только зарегистрированным пользователям. Но у нас супер быстрая регистрация: достаточно только электронной почты!

Текст из файла (страница 19)

The other input arrays are not modified, and can be left in place for successive callswith different right-hand sides.{unsigned long i,k,l;int mm;float dum;mm=m1+m2+1;l=m1;for (k=1;k<=n;k++) {Forward substitution, unscrambling the permuted rowsi=indx[k];as we go.if (i != k) SWAP(b[k],b[i])if (l < n) l++;for (i=k+1;i<=l;i++) b[i] -= al[k][i-k]*b[k];}l=1;for (i=n;i>=1;i--) {Backsubstitution.dum=b[i];for (k=2;k<=l;k++) dum -= a[i][k]*b[k+i-1];b[i]=dum/a[i][1];if (l < mm) l++;}}The routines bandec and banbks are based on the Handbook routines bandet1 andbansol1 in [1].CITED REFERENCES AND FURTHER READING:Keller, H.B.

1968, Numerical Methods for Two-Point Boundary-Value Problems (Waltham, MA:Blaisdell), p. 74.Dahlquist, G., and Bjorck, A. 1974, Numerical Methods (Englewood Cliffs, NJ: Prentice-Hall),Example 5.4.3, p. 166.Ralston, A., and Rabinowitz, P. 1978, A First Course in Numerical Analysis, 2nd ed.

(New York:McGraw-Hill), §9.11.Wilkinson, J.H., and Reinsch, C. 1971, Linear Algebra, vol. II of Handbook for Automatic Computation (New York: Springer-Verlag), Chapter I/6. [1]Golub, G.H., and Van Loan, C.F. 1989, Matrix Computations, 2nd ed. (Baltimore: Johns HopkinsUniversity Press), §4.3.552.5 Iterative Improvement of a Solution to Linear EquationsAx+δxb + δbxbδxδbA−1Figure 2.5.1. Iterative improvement of the solution to A · x = b. The first guess x + δx is multiplied byA to produce b + δb.

The known vector b is subtracted, giving δb. The linear set with this right-handside is inverted, giving δx. This is subtracted from the first guess giving an improved solution x.2.5 Iterative Improvement of a Solution toLinear EquationsObviously it is not easy to obtain greater precision for the solution of a linearset than the precision of your computer’s floating-point word. Unfortunately, forlarge sets of linear equations, it is not always easy to obtain precision equal to, oreven comparable to, the computer’s limit. In direct methods of solution, roundofferrors accumulate, and they are magnified to the extent that your matrix is closeto singular.

You can easily lose two or three significant figures for matrices which(you thought) were far from singular.If this happens to you, there is a neat trick to restore the full machine precision,called iterative improvement of the solution. The theory is very straightforward (seeFigure 2.5.1): Suppose that a vector x is the exact solution of the linear setA·x=b(2.5.1)You don’t, however, know x.

You only know some slightly wrong solution x + δx,where δx is the unknown error. When multiplied by the matrix A, your slightly wrongsolution gives a product slightly discrepant from the desired right-hand side b, namelyA · (x + δx) = b + δb(2.5.2)Subtracting (2.5.1) from (2.5.2) givesA · δx = δb(2.5.3)56Chapter 2.Solution of Linear Algebraic EquationsBut (2.5.2) can also be solved, trivially, for δb.

Substituting this into (2.5.3) givesA · δx = A · (x + δx) − b(2.5.4)In this equation, the whole right-hand side is known, since x + δx is the wrongsolution that you want to improve. It is essential to calculate the right-hand sidein double precision, since there will be a lot of cancellation in the subtraction of b.Then, we need only solve (2.5.4) for the error δx, then subtract this from the wrongsolution to get an improved solution.An important extra benefit occurs if we obtained the original solution by LUdecomposition. In this case we already have the LU decomposed form of A, and allwe need do to solve (2.5.4) is compute the right-hand side and backsubstitute!The code to do all this is concise and straightforward:#include "nrutil.h"void mprove(float **a, float **alud, int n, int indx[], float b[], float x[])Improves a solution vector x[1..n] of the linear set of equations A · X = B.

The matrixa[1..n][1..n], and the vectors b[1..n] and x[1..n] are input, as is the dimension n.Also input is alud[1..n][1..n], the LU decomposition of a as returned by ludcmp, andthe vector indx[1..n] also returned by that routine. On output, only x[1..n] is modified,to an improved set of values.{void lubksb(float **a, int n, int *indx, float b[]);int j,i;double sdp;float *r;r=vector(1,n);for (i=1;i<=n;i++) {Calculate the right-hand side, accumulatingsdp = -b[i];the residual in double precision.for (j=1;j<=n;j++) sdp += a[i][j]*x[j];r[i]=sdp;}lubksb(alud,n,indx,r);Solve for the error term,for (i=1;i<=n;i++) x[i] -= r[i];and subtract it from the old solution.free_vector(r,1,n);}You should note that the routine ludcmp in §2.3 destroys the input matrix as itLU decomposes it.

Since iterative improvement requires both the original matrixand its LU decomposition, you will need to copy A before calling ludcmp. Likewiselubksb destroys b in obtaining x, so make a copy of b also. If you don’t mindthis extra storage, iterative improvement is highly recommended: It is a processof order only N 2 operations (multiply vector by matrix, and backsubstitute — seediscussion following equation 2.3.7); it never hurts; and it can really give you yourmoney’s worth if it saves an otherwise ruined solution on which you have alreadyspent of order N 3 operations.You can call mprove several times in succession if you want.

Unless you arestarting quite far from the true solution, one call is generally enough; but a secondcall to verify convergence can be reassuring.572.5 Iterative Improvement of a Solution to Linear EquationsMore on Iterative ImprovementIt is illuminating (and will be useful later in the book) to give a somewhat more solidanalytical foundation for equation (2.5.4), and also to give some additional results. Implicit inthe previous discussion was the notion that the solution vector x + δx has an error term; butwe neglected the fact that the LU decomposition of A is itself not exact.A different analytical approach starts with some matrix B0 that is assumed to be anapproximate inverse of the matrix A, so that B0 · A is approximately the identity matrix 1.Define the residual matrix R of B0 asR ≡ 1 − B0 · A(2.5.5)which is supposed to be “small” (we will be more precise below).

Note that thereforeB0 · A = 1 − R(2.5.6)Next consider the following formal manipulation:−1−1· B−1· B0A−1 = A−1 · (B−10 · B0 ) = (A0 ) · B0 = (B0 · A)= (1 − R)−1 · B0 = (1 + R + R2 + R3 + · · ·) · B0(2.5.7)We can define the nth partial sum of the last expression byBn ≡ (1 + R + · · · + Rn ) · B0(2.5.8)so that B∞ → A−1 , if the limit exists.It now is straightforward to verify that equation (2.5.8) satisfies some interestingrecurrence relations. As regards solving A · x = b, where x and b are vectors, definex n ≡ Bn · b(2.5.9)xn+1 = xn + B0 · (b − A · xn )(2.5.10)Then it is easy to show thatThis is immediately recognizable as equation (2.5.4), with −δx = xn+1 − xn , and with B0taking the role of A−1 .

We see, therefore, that equation (2.5.4) does not require that the LUdecompositon of A be exact, but only that the implied residual R be small. In rough terms, ifthe residual is smaller than the square root of your computer’s roundoff error, then after oneapplication of equation (2.5.10) (that is, going from x0 ≡ B0 · b to x1 ) the first neglected term,of order R2 , will be smaller than the roundoff error.

Equation (2.5.10), like equation (2.5.4),moreover, can be applied more than once, since it uses only B0 , and not any of the higher B’s.A much more surprising recurrence which follows from equation (2.5.8) is one thatmore than doubles the order n at each stage:B2n+1 = 2Bn − Bn · A · Bnn = 0, 1, 3, 7, . . .(2.5.11)Repeated application of equation (2.5.11), from a suitable starting matrix B0 , convergesquadratically to the unknown inverse matrix A−1 (see §9.4 for the definition of “quadratically”). Equation (2.5.11) goes by various names, including Schultz’s Method and Hotelling’sMethod; see Pan and Reif [1] for references.

In fact, equation (2.5.11) is simply the iterativeNewton-Raphson method of root-finding (§9.4) applied to matrix inversion.Before you get too excited about equation (2.5.11), however, you should notice that itinvolves two full matrix multiplications at each iteration.

Each matrix multiplication involvesN 3 adds and multiplies. But we already saw in §§2.1–2.3 that direct inversion of A requiresonly N 3 adds and N 3 multiplies in toto. Equation (2.5.11) is therefore practical only whenspecial circumstances allow it to be evaluated much more rapidly than is the case for generalmatrices. We will meet such circumstances later, in §13.10.In the spirit of delayed gratification, let us nevertheless pursue the two related issues:When does the series in equation (2.5.7) converge; and what is a suitable initial guess B0 (if,for example, an initial LU decomposition is not feasible)?58Chapter 2.Solution of Linear Algebraic EquationsWe can define the norm of a matrix as the largest amplification of length that it isable to induce on a vector,R ≡ maxv=0|R · v||v|(2.5.12)If we let equation (2.5.7) act on some arbitrary right-hand side b, as one wants a matrix inverseto do, it is obvious that a sufficient condition for convergence isR < 1(2.5.13)Pan and Reif [1] point out that a suitable initial guess for B0 is any sufficiently small constant times the matrix transpose of A, that is,B0 = ATR = 1 − AT · Aor(2.5.14)To see why this is so involves concepts from Chapter 11; we give here only the briefestsketch: AT · A is a symmetric, positive definite matrix, so it has real, positive eigenvalues.In its diagonal representation, R takes the formR = diag(1 − λ1 , 1 − λ2 , .

Характеристики

Тип файла
PDF-файл
Размер
5,29 Mb
Тип материала
Учебное заведение
Неизвестно

Список файлов книги

Свежие статьи
Популярно сейчас
А знаете ли Вы, что из года в год задания практически не меняются? Математика, преподаваемая в учебных заведениях, никак не менялась минимум 30 лет. Найдите нужный учебный материал на СтудИзбе!
Ответы на популярные вопросы
Да! Наши авторы собирают и выкладывают те работы, которые сдаются в Вашем учебном заведении ежегодно и уже проверены преподавателями.
Да! У нас любой человек может выложить любую учебную работу и зарабатывать на её продажах! Но каждый учебный материал публикуется только после тщательной проверки администрацией.
Вернём деньги! А если быть более точными, то автору даётся немного времени на исправление, а если не исправит или выйдет время, то вернём деньги в полном объёме!
Да! На равне с готовыми студенческими работами у нас продаются услуги. Цены на услуги видны сразу, то есть Вам нужно только указать параметры и сразу можно оплачивать.
Отзывы студентов
Ставлю 10/10
Все нравится, очень удобный сайт, помогает в учебе. Кроме этого, можно заработать самому, выставляя готовые учебные материалы на продажу здесь. Рейтинги и отзывы на преподавателей очень помогают сориентироваться в начале нового семестра. Спасибо за такую функцию. Ставлю максимальную оценку.
Лучшая платформа для успешной сдачи сессии
Познакомился со СтудИзбой благодаря своему другу, очень нравится интерфейс, количество доступных файлов, цена, в общем, все прекрасно. Даже сам продаю какие-то свои работы.
Студизба ван лав ❤
Очень офигенный сайт для студентов. Много полезных учебных материалов. Пользуюсь студизбой с октября 2021 года. Серьёзных нареканий нет. Хотелось бы, что бы ввели подписочную модель и сделали материалы дешевле 300 рублей в рамках подписки бесплатными.
Отличный сайт
Лично меня всё устраивает - и покупка, и продажа; и цены, и возможность предпросмотра куска файла, и обилие бесплатных файлов (в подборках по авторам, читай, ВУЗам и факультетам). Есть определённые баги, но всё решаемо, да и администраторы реагируют в течение суток.
Маленький отзыв о большом помощнике!
Студизба спасает в те моменты, когда сроки горят, а работ накопилось достаточно. Довольно удобный сайт с простой навигацией и огромным количеством материалов.
Студ. Изба как крупнейший сборник работ для студентов
Тут дофига бывает всего полезного. Печально, что бывают предметы по которым даже одного бесплатного решения нет, но это скорее вопрос к студентам. В остальном всё здорово.
Спасательный островок
Если уже не успеваешь разобраться или застрял на каком-то задание поможет тебе быстро и недорого решить твою проблему.
Всё и так отлично
Всё очень удобно. Особенно круто, что есть система бонусов и можно выводить остатки денег. Очень много качественных бесплатных файлов.
Отзыв о системе "Студизба"
Отличная платформа для распространения работ, востребованных студентами. Хорошо налаженная и качественная работа сайта, огромная база заданий и аудитория.
Отличный помощник
Отличный сайт с кучей полезных файлов, позволяющий найти много методичек / учебников / отзывов о вузах и преподователях.
Отлично помогает студентам в любой момент для решения трудных и незамедлительных задач
Хотелось бы больше конкретной информации о преподавателях. А так в принципе хороший сайт, всегда им пользуюсь и ни разу не было желания прекратить. Хороший сайт для помощи студентам, удобный и приятный интерфейс. Из недостатков можно выделить только отсутствия небольшого количества файлов.
Спасибо за шикарный сайт
Великолепный сайт на котором студент за не большие деньги может найти помощь с дз, проектами курсовыми, лабораторными, а также узнать отзывы на преподавателей и бесплатно скачать пособия.
Популярные преподаватели
Добавляйте материалы
и зарабатывайте!
Продажи идут автоматически
6439
Авторов
на СтудИзбе
306
Средний доход
с одного платного файла
Обучение Подробнее