Hallo i am totally new with linux and i am trying to make a shell script for gaussian elimination.I have written the code in c because it is easier for me to understand.But i have some problems when trying to write it in a shell script.

here is the c code

CODE

#include <stdio.h>

#include<conio.h>

int main()

{

int n;

float a[10][11],t;

int i, j,k,max;

for(i = 0; i < n; ++i)

for (j = 0; j < n + 1; ++j)

scanf("%f", &a[i][j]);

for (i = 0; i < n; ++i)

{

max = i;

for (j = i + 1; j < n; ++j)

if (a[j][i] > a[max][i])

max = j;

for (j = 0; j < n + 1; ++j)

{

t = a[max][j];

a[max][j] = a[i][j];

a[i][j] = t;

}

}

for (j = n; j >= i; --j)

for (k = i + 1; k < n; ++k)

a[k][j] -= a[k][i]/a[i][i] * a[i][j];

for (i = n - 1; i >= 0; --i) {

a[i][n] = a[i][n] / a[i][i];

a[i][i] = 1;

for (j = i - 1; j >= 0; --j) {

a[j][n] -= a[j][i] * a[i][n];

a[j][i] = 0;

}

}

for (i = 0; i < n; ++i) {

for (j = 0; j < n + 1; ++j)

printf("%.2f\t", a[i][j]);

printf("\n");

}

getch();

return 0;

}

#include<conio.h>

int main()

{

int n;

float a[10][11],t;

int i, j,k,max;

for(i = 0; i < n; ++i)

for (j = 0; j < n + 1; ++j)

scanf("%f", &a[i][j]);

for (i = 0; i < n; ++i)

{

max = i;

for (j = i + 1; j < n; ++j)

if (a[j][i] > a[max][i])

max = j;

for (j = 0; j < n + 1; ++j)

{

t = a[max][j];

a[max][j] = a[i][j];

a[i][j] = t;

}

}

for (j = n; j >= i; --j)

for (k = i + 1; k < n; ++k)

a[k][j] -= a[k][i]/a[i][i] * a[i][j];

for (i = n - 1; i >= 0; --i) {

a[i][n] = a[i][n] / a[i][i];

a[i][i] = 1;

for (j = i - 1; j >= 0; --j) {

a[j][n] -= a[j][i] * a[i][n];

a[j][i] = 0;

}

}

for (i = 0; i < n; ++i) {

for (j = 0; j < n + 1; ++j)

printf("%.2f\t", a[i][j]);

printf("\n");

}

getch();

return 0;

}

i cannot find out how to create a table in my script for reading the matrix...

Any help appreciated...

AFAIK bash only supports one dimensional arrays. However I did find the following information.

http://codeandfury.blogspot.com/2006/12/bash-hacks-using-2-comma-delimited.html

Another limitation is bash can only perform integer math.

Obviously bash is extremely limited compared to c.

And here is a good link to bash scripting.

http://tldp.org/LDP/abs/html/

And why do you have to use bash? Homework assignment?

Thanks a lot for your help...i did not know that bash supports only one dimension array...

It is a project for university and it counts 30% for the final grade for this lesson so i have to find a solution ...

I tried to use awk but i didnt figure out how to do it...

The time has come and i have to give the project until tomorrow..so i guess i have to hurry....

after a lot of trying and searching,i am sure now that i cannot do it using arrays..but how am i going to do it?does anyone has an idea of creating this script?

our deadline has moved to january so i have still the time to do this..

Most forums do not allow homework questions unless they ask specific questions.

At the moment I do not have any good ideas.

I think its a very poor script.

Where is the retention?

What happen with the writing in HD?. You have to be careful with your HD and the bigs databases.

And the bandwith? Why not use a temporal directory and make a synchronization to a final directory to save some of bandwith in the ftp connection? Or much more better.... why ftp?? you can save more time an bandwith if you make rsync

What happen with big databases? You spend more time, CPU and bandwith in make the dumps all hours and move it to the ftp that let the applications runs through db

I think that is a script that make the job but.... is very poor

edwardthompson

I do not understand your post and how it relates to the OP questions.

Powered by Invision Power Board (http://www.invisionboard.com)

© Invision Power Services (http://www.invisionpower.com)