plotting a function from anothe .m file , please help
1 回表示 (過去 30 日間)
古いコメントを表示
i am facing a problem plotting this function
.m
function f=objfun244(tp)
% The objective function: total cost per unit time if replacement interval is tp
% Assumption: The smallest time unit is week.
% f: total cost per unit time
% tp: Length of the time interval in Weeks (preventive replacement interval)
global Cp Cf % cost of preventive replacement and failure replacement, respectively
T =ceil(tp);
% f: total cost per unit time C_tp
f=(Cp+Cf*HT(T))/tp;
% % Test
% objfun244(4)
then on another .m file which is called plotting2.m here is the code i wrote
clear all;
clc;
t = i:1:12;
plot(t,objfun244(t));
grid on
xlabel('t')
ylabel('COST')
---------------------------------------
there is another function called H T , here is its code
function H=HT(T)
% The recursive function H(T)
% Calculate the Expected number of failures in (0,T], for Weibull
% Distribution
% Assumption: T's unit is week, the smallest time unit.
% H: the Expected number of failures in (0,T]
% T: length of the time interval in weeks (preventive replacement interval)
% T is a nonnegative integer: 0, 1, 2, 3, ...
global Al Be % Alpha and Beta for the Weibull distribution, respectively % #####
global HT_vec HT_flag % Calculated H(T) values: HT_flag(T)=1 if it has been calculated
H=0; % H(0)=0: initial value
if T<0.001
% H=0; % If T=0, H(T)=0;
elseif HT_flag(T)>0
% If HT(T) has been calculated, used the saved value
H=HT_vec(T); % Assign the value from HT_vec
else
% Otehrwise, recursively calculate H(T)
% i: time from 0 to T-1
for i=0:(T-1)
H=H+(1+HT(T-i-1))*(wblcdf(i+1,Al,Be)-wblcdf(i,Al,Be)); % #####
end
% Save the calculated H(T) value
HT_vec(T)=H;
HT_flag(T)=1;
end
----------------------------------------------------
i got error : ??? Subscript indices must either be real positive integers or logicals.
Error in ==> HT at 20
elseif HT_flag(T)>0
Error in ==> objfun244 at 12
f=(Cp+Cf*HT(T))/tp;
Error in ==> plotting2 at 11
plot(t,objfun244(t));
-----------------------------
pleaseeee hellpppppp
0 件のコメント
採用された回答
Matt Fig
2012 年 8 月 11 日
編集済み: Matt Fig
2012 年 8 月 11 日
The problem is here:
clear all;
clc;
t = i:1:12;
Did you mean
t = 1:12;
10 件のコメント
Matt Fig
2012 年 8 月 11 日
Please use the {} Code button when pasting code. And be specific in your questions. What did the error message say? I bet it is here:
for i=0:(T(i)-1)
In this line you are defining i for the first time (masking MATLAB's imaginary unit, I might add), so you cannot refer to it in the same line.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Probability Distributions についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!