Write a program, in the language of your preference, that computes solutions for linear systems. The program should take as input a file which contains data for a linear system in the following format:

computer science

Description

Assignment Info

1.    Write a program, in the language of your preference, that computes solutions for linear systems. The program should take as input a file which contains data for a linear system in the following format:

n
a11 a12 ... a1n
a21 a22 ... a2n
...
an1 an2 ... ann
b1   b2   ... bn

The file should have extension .lin, for example, sys1.lin could a suitable file name. The program should use Naive Gaussian Elimination by default and should place the solution in a file with the same name as the input, but with extension .sol and with the following format:

x1 x2 ... xn

Additionally, the user should be able to modify the programs behavior with optional flag --spp, in which case the program will use Scaled Partial Pivoting to produce the solution. For example, for a system placed in file sys1.lin, the user could run:

> gaussian sys1.lin

or,

> gaussian --spp sys1.lin

In the first case the program will use NGE, and in the second it will us SPP. In both cases, the solution will be placed in file sys1.sol.

 

2.       Using your program, computing solutions for the following system:

4
0.0001  -5.0300  5.8090  7.8320
2.2660   1.9950  1.2120  8.0080
8.8500   5.6810  4.5520  1.3020
6.7750  -2.2530  2.9080  3.9700
9.5740   7.2190  5.7300  6.2910

Run your program in both modes. Compare and discuss your results.


Related Questions in computer science category