1

I wrote a code in C to solve equations, but I don't know why some equations that I input into this calculator, give me wrong values, the algorithm is correct because I execute it in C and give me the correct answers but when I use it on the arduino sometimes it doesn't give me the correct answer, well here's the full code https://mega.co.nz/#!BFt0FLLA!S5xUtvbmZT6PKyyVSdKO5smDCMyQiqTnCY_qM8Y48yo and here are the important parts of the code:

 #include <LiquidCrystal.h>
 #include <Keypad.h>
 #include <SPI.h>
.
.
.
.
declaration code and variables
.
 void(){
  nothing interesting here
  }
 loop(){
  valuereturned=entrada();
  .
  .
  .
  here's more code
  .
  .
  a few loops for reading
  .
  .
  jordan();
 }
 /*this part is for reading the numbers from keypad maybe here's the problem*/
int entrada(){
int flag=0,flag2=0,ent=0;
long lgtd=0,numero=0;
double rnum=0,numero2=0;
String num="";
      char key=keypad.waitForKey();
ctt=0;
while(key!='#'){
      switch (key){
             case NO_KEY:
             break;

             case 'A':
             loop();
             break;

             case '.':
             if(ctt<=8){
             num=(String)numero;
             lgtd = num.length();
             if(numero==0){
                  lcd.setCursor(0,1);
                  lcd.print("0.");
             }else{
                  lcd.setCursor(lgtd,1);
                  lcd.print(".");
             }
             flag2=1;
           }
           break;

     case '0': case '1': case '2': case '3': case '4':
     case '5': case '6': case '7': case '8': case '9':
        ctt++;
        if(ctt<=8){
           if(flag2==0){
              lcd.setCursor(0,1);
              numero = numero * 10 + (key - '0');
              lcd.print(numero);
           }
           if(flag2==1){
              ent++;
              lcd.setCursor(lgtd+ent,1);
              lcd.print(key-'0');
              numero2 = numero2 + ((key - '0')/(pow(10,ent)));
           }
         }
        break;

     case '-':
      lcd.setCursor(15,1);
      lcd.print("-");
      flag=1;
     break; 

     case '\n': /*clearing and erasing*/
        numero=0;
        numero2=0;
        flag = 0;
        flag2=0;
        ctt=0;
        ent=0;
        lcd.setCursor(0,1);
        lcd.print("                ");
        break;
  }
     key = keypad.waitForKey();
 }
  rnum=numero+numero2;
  if (flag==1){
     flag=0;
     rnum=(-1)*rnum;
  }
  lcd.setCursor(0,1);
  lcd.print("                 ");
  return rnum;
 }

int jordan(){ /*This part solve by gauss, and It works fine on the pc*/
  int FilaMax,k;
  double maxEl,tmp,fracc;
   lcd.clear();
for (colum=0; colum<cant-1; colum++) {
    /* Busca la Maxima Columna*/
    maxEl = abs(a[colum][colum]);
    FilaMax = colum;
    for (k=colum+1; k<cant; k++) {
        if (abs(a[k][colum]) > maxEl) {
            maxEl = abs(a[k][colum]);
            FilaMax = k;
        }
    }
    /* Se hace el intercambio de la maxima fila con la actual*/
    for (k=colum; k<cant+1;k++) {
        tmp = a[FilaMax][k];
        a[FilaMax][k] = a[colum][k];
        a[colum][k] = tmp;
    }
    /*Aqui se realiza la triangulacion inferior de ceros*/
    for (k=colum+1;k<cant; k++) {
        fracc = -a[k][colum]/a[colum][colum];
        for (fila=colum; fila<cant+1; fila++) {
            if (colum==fila) {
                a[k][fila] = 0;
            }else{
                a[k][fila] += fracc * a[colum][fila];
            }
        }
             } 
} 

    /*print solutions or print that there is no solution*/
   .
   .
   .printing code goes here
   .
   .
   return 0;
 }

Try the code with this:

 input:
    # size
    4
    elements:
    1 -2 1 1 2
    3 0 2 -2 -8
    0 4 -1 -1 1
    5 0 3 -1 -3 
 output:
 some numbers

 it should print without solution.
  • Can you provide us with some sample data and what it should result in and what it actually results in? – Majenko Jun 11 '15 at 22:20
  • # size : 4 elements: {1 -2 1 1 2},{3,0,2,-2,-8},{0,4,-1,-1,1},{5,0,3,-1,-3} it should print without solution but it prints me values,somthing that doesn't do in the pc, I just copy and paste the algorithm – user2461687 Jun 11 '15 at 22:23
  • Chances are you're suffering from a change in word size - int on the Arduino is only 16 bits not 32 bits, for instance. – Majenko Jun 11 '15 at 22:31
  • ok, so I'll change everyting to long it could? – user2461687 Jun 11 '15 at 22:34
  • 4
    I'm voting to close this question as off-topic because the link needed to answer this question had died, so we don't have access to the OP's sketch, needed to solve the problem. – user31481 Nov 22 '17 at 9:23