Re: [問題] 請問一下數學公式的問題已回收
※ 引述《perasa (緣份的天梯)》之銘言:
: 小弟最近要學習將數學式寫入MATLAB
: 程式如下圖
: http://9i2.cc/dl/images/1274434453/1274434453.jpg

: 可是寫完後,trace程式碼
: 發現會少幾項
: 請問這是何處寫錯呢
: 能否麻煩版上的大大幫小弟看一下程式碼
: =================
: sum = 0;
: for h = 1:job_num
: for j = 1:h
: tmp = 1;
: for i = 1:j-1
: tmp = 1+p(sort_ind(i));
: end
: z = tmp^a;
: sum = sum + w(sort_ind(h))*p(sort_ind(j))*z;
: end
: end
: =================
: 謝謝
能否麻煩版上的大大幫小弟看一下
全部的程式碼 如下
================
clear all;clc;close all;
job_num = 5;
p_max = 100;
w_max = 10;
a = -0.5;
% v_AccTemp=0;
w_AccTemp=0;
tic;
for y = 1:10
series = randperm(p_max);
p = series(1:job_num);
cnt = job_num;
for k = 1:ceil(job_num/w_max)
series = randperm(w_max);
if( cnt > w_max )
w(1+(k-1)*w_max:k*w_max) = series;
else
w(1+(k-1)*w_max:job_num) = series(1:cnt);
end
cnt = cnt - w_max;
end
p;
w;
%p = p';
%w = w';
%p = [68 75 86 21 72];
%w = [3 2 1 5 4];
% p = [1 2];
% w = [10 21];
p = [91 41 37];
w = [87 90 16];
%--------------------------WSPT----------------------------
wspt = p./w;
[sorted_val, sort_ind ] = sort(wspt);
sum = 0;
for h = 1:job_num
for j = 1:h
tmp = 1;
for i = 1:j-1
tmp = tmp+1+p(sort_ind(i));
end
z = tmp^a;
sum = sum + w(sort_ind(h))*p(sort_ind(j))*z;
end
end
wspt_result = sum;
%------------------------最佳排法-------------------------------
n_1 = prod(1:job_num);
row = n_1;
col = job_num;
allorder_K = zeros(1,job_num-1);
cnt = 0;
period = n_1/1000;
max_result = 0;
min_result = 100000000;
total = 0;
for allorder_m=1:n_1
allorder_flag=zeros(1,job_num);
allorder_P=zeros(1,job_num);
for allorder_i=1:job_num-1
position=job_num-allorder_K(allorder_i);
allorder_j=job_num;
while(allorder_j>=position)
if (allorder_flag(allorder_j)==1)
position=position-1;
end
allorder_j=allorder_j-1;
end
allorder_P(position)=job_num+1-allorder_i;
allorder_flag(position)=1;
end
for allorder_i=1:job_num
if (allorder_flag(allorder_i)==0)
allorder_P(allorder_i)=1;
break;
end
end
%%%%以下更新K
for allorder_i=1:job_num-1
allorder_K(job_num-allorder_i)=mod(allorder_K(job_num-allorder_i)+1,allorder_i+1);
if (allorder_K(job_num-allorder_i)~=0)
break;
end
end
%%%下面,可以引用allorder_P?行相??理
cnt = cnt + 1;
%----------------------------------------------------------------------
% for m = 1:row
% sort_ind = matrix(m, :); % 取出第m列的組合
sort_ind = allorder_P;
%-------------------------------以下是計算WSPT最佳排法--------------------
sum = 0;
for h = 1:job_num
for j = 1:h
tmp = 1;
for i = 1:j-1
tmp = tmp+1+p(sort_ind(i));
end
z = tmp^a;
sum = sum + w(sort_ind(h))*p(sort_ind(j))*z;
end
end
result(cnt,1) = sum; % 記錄每一次的結果存成行向量
min_result = min(result);
end
wspt_min = wspt_result / min_result;
w_total(y,1) = wspt_min
for i=1:length(wspt_min)
w_SumTemp=wspt_min(i);
w_AccTemp=w_AccTemp+w_SumTemp;
end
end
%....................以下為結果.........................................
fprintf('花費: %f 秒',toc);
general_mean = w_AccTemp / 20
% general_min = min(w_total)
general_max = max(w_total)
% general_op = ((1+alpha)^job_num) / job_num^a
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 125.230.130.186
※ 編輯: perasa 來自: 125.230.130.186 (05/21 20:26)
※ 編輯: perasa 來自: 125.230.130.186 (05/21 21:50)
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):