• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What must be done in for loop.

 
Ranch Hand
Posts: 621
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well,here is my doubt i am working on pivot method of matrix.Each time i have to get the pivot element by different condition,although the condition is same that (i==j) in a for loop,i have to do this bcoz column go on incrementing.
Below shown is my code,here in the code what i am actualy trying to do is...as i==j "condition 1" gets executed again the execution must go to the top and next time if i==j than condition 2 must get executed and so on,but i dont know where i am wrong
what happens actualy is the first time when i==j the value which i get that value is used through out my program thats why each time i have to put condition for i or j so as to get the next pivot element.
What i must do in the for loop so as to get the next pivot element each time .
I am realy stuck into it
But if i want to work on 50-100 matrix than the code will become larger so if any solution for my problem ,the advice is most welcome.




public void operation1(Matr I) throws NumberFormatException, IOException
{
Matr A=this;
double d1=0;
double d2=0;
double d3=0;



for(i=0;i<1;i++)
{
for(j=0;j<N;j++)
{
if(i==j)
{
d1=A.data[i][j];
}

I.data[i][j]=(I.data[i][j]/d1);
A.data[i][j]=(A.data[i][j]/d1);

}
}
refresh(A);


for(i=1;i<M;i++)
{
for(j=N-1;j>=0;j--)
{
I.data[i][j]=(I.data[i][j]-(A.data[i][j-j]*I.data[i-i][j]));
A.data[i][j]=(A.data[i][j]-(A.data[i][j-j]*A.data[i-i][j]));
}

}

refresh(A);

for(i=1;i<2;i++)
{
for(j=0;j<N;j++)
{
if(i==j)
{
d2=A.data[i][j];
}
}
}

for(i=1;i<2;i++)
{
for(j=0;j<N;j++)
{

I.data[i][j]=(I.data[i][j]/d2);
A.data[i][j]=(A.data[i][j]/d2);
}
}


refresh(A);
//this is condition 1
for(i=0;i<1;i++)
{

for(j=0;j<N;j++)
{

if(j>i)
{
d3=A.data[i][j];
}

}




for(i=0;i<1;i++)
{
for(j=0;j<N;j++)
{

I.data[i][j]=(I.data[i][j]-(d3*I.data[i+(j-(j-1))][j]));
A.data[i][j]=(A.data[i][j]-(d3*A.data[i+(j-(j-1))][j]));


}
}

}
//this is condition 2
for(i=2;i<M;i++)
{
for(j=0;j<N;j++)
{

if(j!=1)
{
I.data[i][j]=(I.data[i][j]-(A.data[i][j-(j-1)]*I.data[i-(i-1)][j]));
A.data[i][j]=(A.data[i][j]-(A.data[i][j-(j-1)]*A.data[i-(i-1)][j]));
}




}
}



for(i=2;i<M;i++)
{
for(j=0;j<N;j++)
{

if(j==1)
{
I.data[i][j]=(I.data[i][j]-(A.data[i][j-(j-1)]*I.data[i-(i-1)][j]));
A.data[i][j]=(A.data[i][j]-(A.data[i][j-(j-1)]*A.data[i-(i-1)][j]));
}


}
}
refresh(A);
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic