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