在Matlab中模拟自定义函数

时间:2015-10-15 23:25:07

标签: matlab function simulation

我想模拟以下功能:

GetMessage(&msg, msgWinHwnd, ...);

我写了这个函数如下:

l(t) = mu + Σ (1 + (t-t_i)/alpha)^(beta)

现在,如何在t = 1000,par.mu = 0.5,par.alpha = 0.1,par.beta = 0.3?

的情况下模拟此函数

我有以下代码用于模拟此功能,但效率不高......我怎样才能让它变得更好?

function[l] = custom(m,t,H,par) 
k = length(H);
n = length(t);
l = par.mu(m)*ones(n,1);
  for i = 1:n
    for j = 1:k
    h = H{j};
    h = h(h < t(i));
    if ~isempty(h)
       d = t(i) - h;
       l(i) = l(i) + sum((1+ (d/par.alpha(m,j)))^ par.beta(m,j));
    end   
  end
end 

以下是申请表:

function[h] = simcustom(t,par)
h = -log(rand)/par.mu;
if h < t
   do5 = 1;
   i = 0;
   j = 0;
   k = 0;
   n = 1;
   while true
    if do5;
     k = k + 1;
     Lstar(k) = custom(1,h(n),{h},par);            %#ok
  end
  j = j + 1;
  U(j) = rand;                                         %#ok
  i = i + 1;
  u(i) = -log(U(j))/Lstar(k);                          %#ok
  if i == 1
     Tstar(i) = u(i);                                  %#ok
  else
     Tstar(i) = Tstar(i-1) + u(i);
  end   
  if Tstar(i) > t
     h = {h};
     break
  end   
  j = j + 1;
  U(j) = rand;
  if U(j) <= custom(1,Tstar(i),{h},par)/Lstar(k)
     n = n + 1;
     h = [h Tstar(i)];
     do5 = true;
  else
     k = k + 1;
     Lstar(k) = custom(1,Tstar(i),{h},par);
     do5 = false;
  end
 end   
  else
   h = {[]};
  end

0 个答案:

没有答案