[問題]請問MATLAB累加後,減法的問題 已回收

看板MATLAB作者 (緣份的天梯)時間15年前 (2011/02/28 19:19), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
題目如下圖所示 http://a.imageshack.us/img231/5792/matlab.jpg
以下為小弟自行編寫之MATLAB程式碼 ============= clear all;clc;close all; job_num = 8; p = [4 8 7 3 10 12 6 5]; d = [15 20 15 20 30 40 25 50]; [edd_d_sort_val,edd_d_sort_ind] = sort(d); sum_al = 0; for j = 1:job_num tmp = 1; for i = 1:j-1 tmp = tmp+p(edd_d_sort_ind(i)); end z = tmp; sum_al = sum_al+p(edd_d_sort_ind(j))*z; lateness = cumsum(sum_al)-d(edd_d_sort_ind(j)); end Lmax = max(lateness) ============== 上述為小弟寫的程式碼 不知何處寫錯了 僅能算出第一筆延誤時間(lateness)為-11 而第二筆的延誤時間(lateness)應為-4 可是小弟寫的第二筆延誤時間(lateness)計算為24,爾後皆有問題 麻煩知道如何修正的大大幫忙小弟一下 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.41.84.193 ※ 編輯: perasa 來自: 114.41.84.193 (02/28 19:20)
文章代碼(AID): #1DQuIupD (MATLAB)