VIEWS: 38 PAGES: 11 POSTED ON: 11/4/2009
Numerical Techniques Laboratory Manual [For Specific Focus to Laboratory Work] Name of Faculty Name of the Department PSITPranveer Singh Institute of Technology Bhauti, Kalpi Road, Kanpur List of Content S.No. Content 1. Index 2. Introduction 3. Page No. PSITPranveer Singh Institute of Technology Bhauti, Kalpi Road, Kanpur INDEX S. No. 1. 2. 3. Roll No………………… Name of Experiment Page No. Exp. No. Date Signature Remarks PSITPranveer Singh Institute of Technology Bhauti, Kalpi Road, Kanpur Experiment No. Date of Experiment ___________ Grade_________Faculty’s Signature_________Date___________ Objective To find solution of simultaneous linear equations using Gauss Elimination method and Gauss Jordan method. Gauss Elimination method: in this method, the unknowns are eliminated successively and the system is reduced to an upper triangular system from which the unknowns are found by back substitution. The method is quite general and is well – adapted for computer operations. Here we shall explain it by considering a system of three equations for sake of clarity. Consider the equations a1x + b1y + c1 z = d1 a2x + b2y + c2 z = d2 a3x + b3y + c3 z = d3 ……………….(1) Step-1. To eliminate x from second and third equations. Assuming a1 ≠0, we eliminate x from the second equation by subtracting (a 2/a1) times the first equation from the second equation. Similarly we eliminate x from the third equation by subtracting (a3 /a1) times the first equation from the third equation. We thus, get the new system a1x + b1y + c1 z = d1 b2 'y + c2 'z = d2 ' b3 'y +c3 'z = d3" …………………(2) Here the first equation is called the pivotal equation and a 1 is called the first pivot. Step 2. To eliminate y from third equation in (2). Assuming b2 '≠0, we eliminate y from the third equation of (2), by subtracting (b3 '/b2 ') times the second equation from the third equation. We thus, get the new system a1 x + b1 y + c1 z = d1 b2 y + c2 'z = d2 ' c3 "z = d3" ……....…………(3) Here the second equation is the pivotal equation and b2 ' is the new pivot. Step 3. To evaluate the unknown. The values of x,y,z are found from the reduced system (3) by back substitution. Gauss-Jordan method: This in a modification of the Guass-Elimination method. In this Method, elimination of unknowns is performed not in the equation below but in the equation above also, ultimately reducing the system to a diagonal matrix form i.e. each equation involving only one unknown. From these equations the unknowns x,y,z can be obtained readily. Thus, in this method, the labour of back-substitution for finding the unknown is saved at the cost of additional calculation. PSITPranveer Singh Institute of Technology Bhauti, Kalpi Road, Kanpur Note: For a system of 10 equations, the number of multiplications required for Guass-Jordan method is about 500 whereas for Guass-Elimination method, we need only 333 multiplications. This implies that though Guass-Jordan method appears to be easier but required 50% more operations than the Guass-Elimination method. Algorithm Guass-Elimination Method 1. Assign float space for a[n] [n+1], x[n], t and s. 2. Assign integer space for i, j, k. 3. Assign i=0, j=0. 4. Accept value of a[i] [j]. 5. Repeat step (4) & increment I & j by 1 till i<n, j<n+1. 6. Assign j=0 & i=j+1. 7. Assign t with a[i] [j]/a[j] [j]. 8. Assign k=0 and repeat step (9) till k<n+1, increment k by 1. 9. a[i] [j] -= a[j] [k]*t. 10. Increment value of I with 1. 11. Repeat steps (7) to (10) till i<n. 12. Repeat step (7) to (11) till j<(n-1) and incrementing by 1 each time. 13. Assign i=0, j=0. Accept a[i] [j], increment i & j with 1. 14. Repeat step (13) till i<n, j<n+1. 15. Assign i with n-1, s with 0. 16. Assign j with i+1. 17. Assign s with a[i] [j]*x[j]. 18. Assign x[i] = (a[i] [n]-s)/a[i] [j]. 19. Decrement I by 1 & increment j by 1 till j<n & i>=0. (Repeat steps 16 to 19) 20. Display value of i+1 7 x[i], I varies from 0 to n-1. PSITPranveer Singh Institute of Technology Bhauti, Kalpi Road, Kanpur Program for Guass-Elimination Method Output (Self Input) PSITPranveer Singh Institute of Technology Bhauti, Kalpi Road, Kanpur Algorithm for Guass-Jordan Method Program for Guass-Jordan Method Output (Self Input) PSITPranveer Singh Institute of Technology Bhauti, Kalpi Road, Kanpur Important Questions Q.1 What is difference between Guass’s Seidal iteration and Guass’s Elimination method? Q. 2 What is pivoting? Distinguish between partial pivoting and complete pivoting? Q.3 Compare critically Guass Elimination and Guass Jordan methods of solving simultaneous equations? Q.4 Define upper triangular and lower triangular matrices. Q.5 What are elementary row transformation? PSITPranveer Singh Institute of Technology Bhauti, Kalpi Road, Kanpur Experiment No. Date of Experiment ___________ Roll No. ____________________ Group No._______________ Date of submission ___________Grade (if any)____________Faculty’s Signature_____________ Aim Write a program to implement quick sort technique Theory This sort is also called partition exchange sort. The quick sort is an in-place, divide-and-conquer, massively recursive sort. As a normal person would say, it’s essentially a faster in-place version of the merge sort. The quick sort algorithm is simply in theory, but very difficult to put into code (computer scientists tied themselves into knots for years trying to write a practical implementation of the algorithm, and it still has that effect on university students). The recursive algorithm consists of four steps (which closely resemble the merge sort): 1. If there are one or less elements in the array to be sorted, return immediately. 2. Pick an element in the array to serve as a “pivot” point. (Usually the left-most element in the array is used.) 3. Split the array into two parts – one with elements larger than the pivot and the other with elements smaller than the pivot. 4. Recursively repeat the algorithm for both halves of the original array. The efficiency of the algorithm is majorly impacted by which element is chosen as the pivot pint. The worst-case efficiency of the quick sort, O(n2), occurs when the list is sorted and the left-most element is chosen. Randomly choosing a pivot point rather than using the left-most element is recommended, if the data to be sorted isn’t random. As long as the pivot point is chosen randomly, the quick sort has an algorithmic complexity of O(n log n). Pros: Extremely fast. Cons: Very complex algorithm, massively recursive. The quick sort is by far the fastest of the common sorting algorithms. It’s possible to write a special purpose sorting algorithm that can beat the quick sort for some data sets, but for general general-case sorting there isn’t anything faster. As soon as students figure out, their immediate impulse is to use the quick sort for everything – after all, faster is better, right? It’s important to resist this urge – the quick sort isn’t always the best choice. As mentioned earlier, it’s massively recursive (which means that for very large sorts, you can run the system out of stack space pretty easily). It’s also a complex algorithm – a little too complex to make it practical for a one-time sort of 25 items, for example. PSITPranveer Singh Institute of Technology Bhauti, Kalpi Road, Kanpur With that said, in most cases the quick sort is the best choice if speed is important (and it almost always is). Use it for repetitive sorting, sorting of medium to large lists, and as a default choice when you’re not really sure which sorting algorithm to use. Ironically, the quick sort has horrible efficiency when operating on lists that are mostly sorted in either forward or reverse order – avoid it in those situations. Algorithm 1. Quick Sort (A,p,r) 2. then q<-- PARTITION(A,p.r) 3. QUICK SORT (A,p,r) 4. QUICK SORT (A,q+1,r) PSITPranveer Singh Institute of Technology Bhauti, Kalpi Road, Kanpur Student Work Area PSITPranveer Singh Institute of Technology Bhauti, Kalpi Road, Kanpur
"Lab Manual - PSIT-PSAT"