Linux Help
guides forums blogs
Home Desktops Distributions ISO Images Logos Newbies Reviews Software Support & Resources Linuxhelp Wiki

Welcome Guest ( Log In | Register )



Advanced DNS Management
New ZoneEdit. New Managment.

FREE DNS Is Back

Sign Up Now
> shell script from c
noobie
post Dec 10 2008, 08:41 AM
Post #1


Whats this Lie-nix Thing?
*

Group: Members
Posts: 3
Joined: 10-December 08
Member No.: 13,789



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;
}



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


Go to the top of the page
 
+Quote Post
 
Start new topic
Replies
michaelk
post Dec 10 2008, 05:10 PM
Post #2


Its GNU/Linuxhelp.net
*******

Group: Support Specialist
Posts: 1,797
Joined: 23-January 03
Member No.: 360



AFAIK bash only supports one dimensional arrays. However I did find the following information.
http://codeandfury.blogspot.com/2006/12/ba...-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?
Go to the top of the page
 
+Quote Post
noobie
post Dec 11 2008, 05:41 AM
Post #3


Whats this Lie-nix Thing?
*

Group: Members
Posts: 3
Joined: 10-December 08
Member No.: 13,789



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....
Go to the top of the page
 
+Quote Post

Posts in this topic


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 18th October 2017 - 07:03 PM