对äºä¸ä¸ªmÃnçç©éµï¼è®¾s为ç©éµçå ç´ æ»ä¸ªæ°s=mÃnï¼è®¾t为ç©éµä¸éé¶å ç´ ç个æ°ï¼æ»¡è¶³t<<sçç©éµç§°ä¸ºç¨çç©éµãä¸ä¸ªä¸ç¨ççç©éµç§°ä½ç¨ å¯ç©éµã
ç¨çç©éµçé¶å ç´ é常å¤ï¼ä¸åå¸æ è§å¾ï¼æ以ç¨çç©éµçå缩åå¨æ¹æ³ä¸ºï¼åªåå¨ç©éµä¸çéé¶å ç´ ï¼æç §ä¸å ç»çå½¢å¼åå¨ãä¸å ç»ç±éé¶å ç´ ï¼è¯¥å ç´ è¡ä¸æ å该å ç´ åä¸æ ä¸ä¸ªæ°æ®ææï¼æ¾å¨ä¸ä¸ªåæ°ä¸º3çæ°ç»ä¸ã
åå¨ç»æååæ°ç»ç»æåé¾è¡¨ç»æ两个大类ï¼å ¶ä¸é¾è¡¨ç»æåæä¸è¬é¾è¡¨ãè¡æéæ°ç»é¾è¡¨åè¡æéçååé¾è¡¨åå¨ç»æï¼æ¯é¾è¡¨çç´æ¥åºç¨åç»ååºç¨ã
æ°ç»ç»æ
åºäºåéç±»ï¼é¦å è¦è®¾è®¡ä¸å ç»ç±»ï¼ç¨äºåæ¾ä½ç½®åæ°å¼ä¿¡æ¯ï¼
[java] view plain copy
package ArrayVectorSetMatrix;
/**
* @author sun
* å建æ¶é´ï¼2017å¹´4æ15æ¥ä¸å3:54:37
*/
public class Three {
public int row;//è¡å·
public int col;//åå·
public double value;//æ°å¼
public Three(int r,int c,double v){
row = r;
col = c;
value = v;
}
Three(){
this(0,0,0.0);
}
}
[java] view plain copy
package ArrayVectorSetMatrix;
/**
* @author sun
* å建æ¶é´ï¼2017å¹´4æ15æ¥ä¸å3:57:32
*/
//åç¨MyVectorç±»
public class SpaMatrix {
int rows;//è¡æ°
int cols;//åæ°
int dNum;//éé¶å ç´ ä¸ªæ°
MyVector v;
SpaMatrix(int max){
rows = cols = dNum = 0;
v = new MyVector(max);
}
public void evaluate(int r,int c,int d,Three[] item)throws Exception{
//ç»ç©éµèµå¼
rows = r;
cols = c;
dNum = d;
for(int i=0;i<d;i++){
v.add(i,item[i]);
}
}
public SpaMatrix transpose(){//转置
SpaMatrix a = new SpaMatrix(v.size());
a.cols = rows;
a.rows = cols;
a.dNum = dNum;
for(int i=0;i<dNum;i++){
Three t = (Three)v.get(i);//åå¾ä¸å ç»
a.v.add(i,new Three(t.col,t.row,t.value));//注æè¡åå·åæ¢
}
return a;
}
public void print(){
System.out.print("ç©éµè¡æ°ä¸ºï¼"+rows);
System.out.print(",ç©éµåæ°ä¸ºï¼"+cols);
System.out.println(",éé¶å ç´ ä¸ªæ°ä¸ºï¼"+dNum);
System.out.println("ç©éµéé¶å ç´ ä¸å ç»ä¸ºï¼");
for(int i=0;i<dNum;i++){
System.out.println("a<"+((Three)v.get(i)).row+","
+((Three)v.get(i)).col+">="
+((Three)v.get(i)).value);
}
}
}
[java] view plain copy
package ArrayVectorSetMatrix;
/**
* @author sun
* å建æ¶é´ï¼2017å¹´4æ15æ¥ä¸å4:15:38
*/
public class TestSpaMatrix {
public static void main(String[] args) {
SpaMatrix matrixA = new SpaMatrix(10);
SpaMatrix matrixB;
Three[] a = new Three[6];
a[0] = new Three(1,3,11.0);
a[1] = new Three(1,5,17.0);
a[2] = new Three(2,2,25.0);
a[3] = new Three(4,1,19.0);
a[4] = new Three(5,4,37.0);
a[5] = new Three(6,7,50.0);
try{
matrixA.evaluate(6, 7, 6, a);
System.out.println("åç©éµï¼");
matrixA.print();
System.out.println("转置åçç©éµï¼");
matrixB = matrixA.transpose();
matrixB.print();
}
catch(Exception e){
System.out.println(e.getMessage());
}
}
}
/*
åç©éµï¼
ç©éµè¡æ°ä¸ºï¼6,ç©éµåæ°ä¸ºï¼7,éé¶å ç´ ä¸ªæ°ä¸ºï¼6
ç©éµéé¶å ç´ ä¸å ç»ä¸ºï¼
a<1,3>=11.0
a<1,5>=17.0
a<2,2>=25.0
a<4,1>=19.0
a<5,4>=37.0
a<6,7>=50.0
转置åçç©éµï¼
ç©éµè¡æ°ä¸ºï¼7,ç©éµåæ°ä¸ºï¼6,éé¶å ç´ ä¸ªæ°ä¸ºï¼6
ç©éµéé¶å ç´ ä¸å ç»ä¸ºï¼
a<3,1>=11.0
a<5,1>=17.0
a<2,2>=25.0
a<1,4>=19.0
a<4,5>=37.0
a<7,6>=50.0
*/
ï¼1ï¼å¸¦å¤´ç»ç¹çä¸å ç»é¾è¡¨ï¼å¤´ç»ç¹åå¨ç©éµçè¡æ°åæ°ï¼å ¶ä»ç»ç¹æè¡å·æåºï¼æ¯ä¸ªç»ç¹åçæ¯ä¸å ç»ä¸çä¸ä¸ªå ç´ ã该æ³å®ç°ç©éµè¿ç®çæ¶é´æçä¸é«ï¼å 为访é®æ ¢ã
ï¼2ï¼è¡æéæ°ç»ç»æçä¸å ç»é¾è¡¨ï¼æ²¡æ头ç»ç¹ï¼å°±æ¯è®¾ç½®ä¸ä¸ªè¡æéæ°ç»ï¼ç¬¬ä¸å为è¡å·ï¼ç¬¬äºå为æéï¼æ¯ä¸ªæéæå该è¡ç第ä¸ä¸ªä¸ä¸º0å ç´ å¼åå ¶åå·ææçç»ç¹ï¼ç¶å继ç»ååç´å°ææ¬è¡ææä¸ä¸º0å ç´ ç»ç¹è¿æ¥å®æãè¿æ ·ï¼ä»æè¡è¿å ¥æ¾æåå ç´ çæä½æ¯è¾å®¹æï¼ä½ä»åè¿å ¥æ¾æ¯è¾é¾ã
ï¼3ï¼ä¸å ç»ååé¾è¡¨ç»æï¼å¨ä¸ä¸é®é¢åºç¡ä¸åå ä¸ä¸ªåæéæ°ç»ï¼è¿æ ·æ¯ä¸ªç»ç¹æ¢æ横åå¾è¿ï¼ä¹æ纵åå¾è¿ï¼é½æ²¡æ头ç»ç¹ï¼ä½æ¯ä¸ªç»ç¹çè¡å·ååå·ä¸è½çç¥ã
ä¸åæ¼ç¤ºã