PHP 板


LINE

看板 PHP  RSS
$file=fopen("USA-15_Restart_P.txt","r"); $line_num=0; while($line=fgets($file,10)) { $digit=preg_split("/[ ]/",$line); $Restart_p[0][$line_num]=$digit[0]; echo $Restart_p[0][$line_num]."<br>"; $line_num++; } fclose($file); $file=fopen("USA-15 network.txt","r"); $line_num=0; while($line=fgets($file,10)) { $number[$line_num]=preg_split("/[ ]/",$line); /* if($number[$line_num][0]=="link") { $linkout_node[]=intval($number[$line_num][1]); continue; } */ $digit_size[]=intval($number[$line_num][0]); $digit_size[]=intval($number[$line_num][1]); $nei[intval($number[$line_num][0])][intval($number[$line_num][1])]=1; $nei[intval($number[$line_num][1])][intval($number[$line_num][0])]=1; $line_num++; } fclose($file); //echo "count = ".count($digit_size)."<br>"; $maximum=0; $minimum=1000; for($i=0;$i<count($digit_size);$i++) { if($maximum<$digit_size[$i]) { $maximum=$digit_size[$i]; } if($minimum>$digit_size[$i]) { $minimum=$digit_size[$i]; } } //echo "maximum = ".$maximum."<br>"; //echo "minimum = ".$minimum."<br>"; //echo for($i=$minimum;$i<=$maximum;$i++) { for($j=$minimum;$j<=$maximum;$j++) { if($nei[$i][$j]==NULL) { $nei[$i][$j]=0; } //echo /*$i."|".$j."->".*/$nei[$i][$j]." ; "; $sum_i[$j]+=$nei[$i][$j]; } //echo "<br>"; } for($j=$minimum;$j<=$maximum;$j++) { //echo $sum_i[$j]." ; "; } $a=0; $b=0; for($i=$minimum;$i<=$maximum;$i++) { for($j=$minimum;$j<=$maximum;$j++) { if($nei[$i][$j]==NULL) { $nei[$i][$j]=0; } $adjacent_matrix[$a][$b]= $nei[$i][$j]/$sum_i[$j]; //echo /*$i."|".$j."->".*/$nei[$i][$j]/$sum_i[$j]." ; "; echo $adjacent_matrix[$a][$b]." ; "; $b++; } $a++; echo "<br>"; } //echo "a,b = ".matrix_print(matrix_operation($a, $b, '*' ))."<br>"; echo matrix_print(matrix_operation($adjacent_matrix, $Restart_p, '*' ))."<br>"; function _matrix_rows($matrix) { return count($matrix); } // A function to return the columns in a matrix - // Does not check for validity, it assumes the matrix is well formed. function _matrix_columns($matrix) { return count($matrix[0]); } function _matrix_well_formed($matrix) { // If this is not an array, it is badly formed, return false. if (!(is_array($matrix))) { return false; } else { // Count the number of rows. $rows = count($matrix); // Now loop through each row: for ($r = 0; $r < $rows; $r++) { // Make sure that this row is set, and an array. Checking to // see if it is set is ensuring that this is a 0 based // numerically indexed array. if (!(isset($matrix[$r]) && is_array($matrix[$r]))) { return false; } else { // If this is row 0, calculate the columns in it: if ($r == 0) { $cols = count($matrix[$r]); // Ensure that the number of columns is identical else exit } elseif (count($matrix[$r]) != $cols) { return false; } // Now, loop through all the columns for this row for ($c = 0; $c < $cols; $c++) { // Ensure this entry is set, and a number if (!(isset($matrix[$r][$c]) && is_numeric($matrix[$r][$c]))) { return false; } } } } } // Ok, if we actually made it this far, then we have not found // anything wrong with the matrix. return true; } function matrix_operation($a, $b, $operation) { // Verify both matrices are well formed $valid = false; if (_matrix_well_formed($a) && _matrix_well_formed( $b)) { // Make sure they have complementary numbers of rows and columns. // The number of rows in A should be the number of columns in B $rows = _matrix_rows($a); $columns = _matrix_columns($a); if (($columns == _matrix_rows( $b)) && ($rows == _matrix_columns( $b))) { // We have a valid setup for continuing $valid = true; } } // If invalid, return false if (!($valid)) { return false; } // Create a blank matrix the appropriate size, initialized to 0 $new = array_fill(0, $rows, array_fill(0, $rows, 0)); // For each row in a ... for ($r = 0; $r < $rows; $r++) { // For each column in b ... for ($c = 0; $c < $rows; $c++) { // Take each member of column b, with each member of row a // and add the results, storing this in the new table: // Loop over each column in A ... for ($ac = 0; $ac < $columns; $ac++) { // Evaluate the operation eval('$new[$r][$c] += $a[$r][$ac] '. $operation.' $b[$ac][$c];'); } } } // Return the finished matrix: return $new; } function matrix_print($matrix) { // Verify it is well formed if (_matrix_well_formed($matrix)) { $rows = _matrix_rows($matrix); $columns = _matrix_columns($matrix); // Start the table echo '<table>'; // For each row in the matrix: for ($r = 0; $r < $rows; $r++) { // Begin the row: echo '<tr>'; // For each column in this row for ($c = 0; $c < $columns; $c++) { // Echo the element: echo "<td>".sprintf("%8.4f",$matrix[$r][$c])."</td>"; } // End the row. echo '</tr>'; } // End the table. //echo "</table>/n"; echo "</table><br>"; } else { // It wasn't well formed: return false; } } ?> --



※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.126.132.4
1F:→ tkdmaf:可以明白的表述一下......你的問題是什麼? 08/28 17:40
2F:→ fly1102:我要做的是二維的矩陣相乘,兩個矩陣都ECHO 得出來,但是 08/28 18:42
3F:→ fly1102:ECHO出來卻是空白的????為什麼 08/28 18:43
4F:→ fly1102:帶入矩陣相乘的FUNCTION卻是空白的???為什麼 08/28 18:44
5F:→ PsMonkey:我可以推「因為愛」嗎? [逃] 08/28 18:48
6F:→ tkdmaf:除了單元測試,我想不到其他你能做的事了。 08/28 23:12
7F:→ tails32100:為何要用eval @@ 08/29 08:31
8F:→ fly1102:function是我在網路上找到的code,用他網路上提共的範例是 08/30 12:51
9F:→ fly1102:echo得出結果的,還是有其他矩陣相乘的code可以借我參考呢 08/30 12:53
10F:推 bobju:這大概得自己debug,或是付錢找人debug了.. 08/31 07:10
11F:推 cwlin0416:既然還沒相乘都可以正常,那問題應該就出在相乘的地方, 09/22 19:19
12F:→ cwlin0416:先看看相乘的地方能否正常取得兩個矩陣的值吧,其次就是 09/22 19:19
13F:→ cwlin0416:那個eval到底有沒有做他該做的事 09/22 19:19
14F:推 cwlin0416:不過說真的,你把所有程式貼出來,又都是範例的內容, 09/22 19:23
15F:→ cwlin0416:裡面又一堆註解,應該沒多少人會理你 09/22 19:23







like.gif 您可能會有興趣的文章
icon.png[問題/行為] 貓晚上進房間會不會有憋尿問題
icon.pngRe: [閒聊] 選了錯誤的女孩成為魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一張
icon.png[心得] EMS高領長版毛衣.墨小樓MC1002
icon.png[分享] 丹龍隔熱紙GE55+33+22
icon.png[問題] 清洗洗衣機
icon.png[尋物] 窗台下的空間
icon.png[閒聊] 双極の女神1 木魔爵
icon.png[售車] 新竹 1997 march 1297cc 白色 四門
icon.png[討論] 能從照片感受到攝影者心情嗎
icon.png[狂賀] 賀賀賀賀 賀!島村卯月!總選舉NO.1
icon.png[難過] 羨慕白皮膚的女生
icon.png閱讀文章
icon.png[黑特]
icon.png[問題] SBK S1安裝於安全帽位置
icon.png[分享] 舊woo100絕版開箱!!
icon.pngRe: [無言] 關於小包衛生紙
icon.png[開箱] E5-2683V3 RX480Strix 快睿C1 簡單測試
icon.png[心得] 蒼の海賊龍 地獄 執行者16PT
icon.png[售車] 1999年Virage iO 1.8EXi
icon.png[心得] 挑戰33 LV10 獅子座pt solo
icon.png[閒聊] 手把手教你不被桶之新手主購教學
icon.png[分享] Civic Type R 量產版官方照無預警流出
icon.png[售車] Golf 4 2.0 銀色 自排
icon.png[出售] Graco提籃汽座(有底座)2000元誠可議
icon.png[問題] 請問補牙材質掉了還能再補嗎?(台中半年內
icon.png[問題] 44th 單曲 生寫竟然都給重複的啊啊!
icon.png[心得] 華南紅卡/icash 核卡
icon.png[問題] 拔牙矯正這樣正常嗎
icon.png[贈送] 老莫高業 初業 102年版
icon.png[情報] 三大行動支付 本季掀戰火
icon.png[寶寶] 博客來Amos水蠟筆5/1特價五折
icon.pngRe: [心得] 新鮮人一些面試分享
icon.png[心得] 蒼の海賊龍 地獄 麒麟25PT
icon.pngRe: [閒聊] (君の名は。雷慎入) 君名二創漫畫翻譯
icon.pngRe: [閒聊] OGN中場影片:失蹤人口局 (英文字幕)
icon.png[問題] 台灣大哥大4G訊號差
icon.png[出售] [全國]全新千尋侘草LED燈, 水草

請輸入看板名稱,例如:Soft_Job站內搜尋

TOP