invalid types 'double[11][double]' for array subscript

this is the error that apears like 200 times ;_;

Page 1 of 1

1 Replies - 5559 Views - Last Post: 22 May 2008 - 07:09 AM Rate Topic: -----

#1 kaomy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 21-May 08

invalid types 'double[11][double]' for array subscript

Posted 21 May 2008 - 10:12 PM

PLEASE HEEEEELLLLPP!!
I have been this code like 12 hours... I am not system engineering.. don't understand very well array concept.. i have been reading about it, but even cant understand what its bad. I also have been searching about this problem, but even..... i really aprecciate if you can say why U[i][j]=To and code like it is bad, because i had made a similar code and it had worked... why this no?? :crazy:

this is the code

#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <math.h>
#include <cstdlib>
#include<cmath>

//definir constantes constantes
//propiedades
#define den0 650 //Kg m^-3
#define h 84 //Coeficiente de trans calor W m^-2 K^-1
#define kg 0.02577 //conductividad térmica del gas, W m^-1 K^-1
#define dH -255000 //Calor de reaccion j kg^-1
#define e 0.95 //Coeficiente de emisividad
#define alfa0 0.000000179 //difusividad termica inicial m^12 s^-1

//constanes universales
#define o 0.0000000000000000000000138 //constante de Boltzmann J K^-1
#define Rc 8.314 //constante de los gases 8.314 J mol^-1 K^-1

//de cambio volumen
#define d 0.00002 //Diametro del poro, m
#define ev 0.5 //factor de vacios inicial

//otros del modelo en si
#define b 2 //factor geometrico de un cilindro
#define n 10//tamaño de la matriz en radio
#define m 10//tamaño de la matriz en tiempo

//para las constantes de reaccion
#define A1 0.00009973 //s^-1
#define D1 17254.4 // K
#define L1 -909061227 //k^2
#define A2 0.001068 //s^-1
#define D2 10224.4 //K
#define L2 -6123081 //K^-2
#define A3 0.000057 //s^-1
#define E3 81000 //J mol^-1

using namespace std;

//calculo de cosas que dependen de la temperatura y otras cosas

//Globales


class calculos{

private:
double R;
double Mbo;
double T;
double Mb;
double To, Tf;
double kb, kc, denso;
public:
void iniVariables(/*double **U,*/ double Tini, double Tfin, double Rad, double Mb0, double Mbj,double dens0){
int i;
// for (i=0; i<=n; i++){
// U[i][0]=To;}
// for (i=0; i<=n; i++){
// U[i][m]=Tf;}
R=Rad;
Mbo=Mb0;
Mb=Mbj;
To=Tini;
Tf=Tfin;
denso=dens0;
}
void definirTj(double Tj){ T=Tj; }
double Cp(void){
return 1112 + 4.85*(T-273);}
double keff(void){
double nn;
kb=0.013-0.0003*(T-273);
kc=0.08-0.0001*(T-273);
nn=Mb/Mbo;
return nn*kb+(-nn)*kc+ev*kg+13.5*o*T*T*T*d/e;}
double calkb(void){kb=0.013-0.0003*(T-273); return kb;}
double calkc(void){kc=0.08-0.0001*(T-273); return kc;}
double k1(double temp){ return A1*exp(D1/temp)+(L1/(temp*temp));}
double k2(double temp){ return A2*exp(D2/temp)+(L2/(temp*temp));}
double k3(double temp){ return A3*exp(-E3/(temp*Rc));}
double dens(void){
return denso+k1(To)*To/(D1*To*exp(To)-L1)-k1(T)*T/(D1*T*exp(T)-L1);}; //hay q cambiar exp por ln

};




//----------------------------------main----------------------------------------

main(){

double i, j, dt, dx, k, H, T;
double R=0.003, keff, To=303, Tf= 773, Mbo=650; //valores iniciales
double U[m+1][n+1];//temperatura a tiempo j radio i
double A[m+1][m+1], B[m+1], Uj[m+1];
calculos varios;
double s, c; //util y constante para la matriz Aj
double Q, Cp, alfa, dens, kb,k1 ;



//inicializar condicion inicial de temperatura
for(j=1; j<=n; j++){
for(i=1; i<=m; i++){
U[i][j]=To;
}
}



//otras constantes e inicializaciones
s=dt/(dx*dx);
varios.iniVariables( To,Tf, R,Mbo,Mbo,den0);



//calcular eso que por ahora decimos que es constante
T=(Tf+To)/2;
varios.definirTj(T);
keff=varios.keff();
H=(R/keff)*(h+e*o*(T*T*T+T*T*Tf+T+Tf*Tf+Tf*Tf*Tf));
Cp= varios.Cp();
k1=varios.k1(T);
dens=varios.dens();
Q=(-dH+Cp*T)/(dens*Cp*(To-Tf)),
kb=varios.calkb();
alfa=kb/(dens*Cp);
c=dt*Q*R*R*k1/alfa;


//iteracion para cada tiempo
for(j=0; j<=n; j++){
//llenar la matriz A de resolver, segun condiciones en x
for(i=1; i<=m; i++){
if(i==1){ //para la primera fila
A[1][1]=2*b*s+1; A[1][2]=-2*b*s;
for (k=3; k<=m; k++){
A[1][k]=0;}
}
else if(i!=1 || i!= m){
A[i][i-1]=(b-1)*s/(2*i)-s; //ai
A[i][i]=2*s+1; //b1
A[i][i+1]=-(b-1)*s/(2*i)-s;
for(k=0; k<=m && (k!=i-1 || k!=i || k!= i+1); k++){
A[i][k]=0;}
}
else if(i==m){
A[m][m-1]=-2*s;
A[m][m]=2*s+2*s*H+(b-1)*dt*H;
for(k=0; k<m-1; k++){
A[m][k]=0;}
}
}

//agregar constante a lado derecho

for(k=1; k<=m; k++){
B[k]=U[k][j]+c;}

//resolver para el tiempo futuro teniendo en cuenta los resultados este tiempo
// thomas(A, Uj, B); //aqui me soluciono la matriz , es decir, me dio el siguietne tiempo
double g, bkm1, ckm1,dkm1;
double ck, bk;
double ak;

for(k=2; k<m; k++){
ak=A[k][k-1];
bkm1=A[k-1][k-1];
ckm1=A[k-1][k];
dkm1=B[k-1];
g=ak/bkm1;
A[k][k]+=-g*ckm1;

Uj[k]+=-g*dkm1;}

Uj[n]=B[n]/A[n][m];

for(k=n-1; k>0; k--){
bk=A[k][k];
ck=A[k][k+1];
Uj[k]=(B[k]-ck*Uj[k+1])/bk;
}
//pasar uj1 resulto a uj1 de la matriz

for(k=1; k<=m; k++){
U[k][j+1]=Uj[k];}

}


//aqui imprimir resultados de t vs T o T vs R para el tiempo que quieras :)





return 0;
}


a lot of thanks for your help! and sorry my "not so good" english

Is This A Good Question/Topic? 0
  • +

Replies To: invalid types 'double[11][double]' for array subscript

#2 mikeblas   User is offline

  • D.I.C Regular
  • member icon

Reputation: 44
  • View blog
  • Posts: 390
  • Joined: 08-February 08

Re: invalid types 'double[11][double]' for array subscript

Posted 22 May 2008 - 07:09 AM

When you index an array, you do so using integers. Looking at U[1][2] makes sense because you'll find the second column in the first row. Looking for U[3.4][1.1] doesn't make sense because a floating point number doesn't precisely identify a single element in the array.

You should be using ints, not doubles, as the indexes for your array.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1