Matlab-如何绘制函数?

时间:2017-05-16 16:01:38

标签: matlab

我创建了一个接收某些输入并为队列理论模拟生成一些输出的函数。

  function [Ws, Wq, c_util, p_drop, p_state] =  MMCQ(lambda, mu, c, Nwait)

  rho = lambda./mu;
  Lq = (rho.^2)/(1-rho);  %lenght of queue
  Ls = rho./(1-rho);  %lenght of system
  c_bar = Ls - Lq;
  c_util = c_bar./c ; 
  Wq = Lq/c*mu*c_util;
  Ws = Ls/lambda;

  Po = (1-rho)*(rho.^0);
  Pi = (1-rho)*(rho.^1);
  p_drop = 1-Po-Pi;
  p_state = (1-rho)*rho.^0;


  end

我需要创建一个Wq图,作为c的函数,从c的最小值开始,在20处停止。我怎样才能实现这个目标?

1 个答案:

答案 0 :(得分:1)

循环显示c的值,将结果存储到矩阵(假设Wq是标量),然后针对Wq绘制c

% Define lambda, mu, Nwait first
c = (1:20); % List of c values to input
Wq = zeros(size(c));
for ii = 1:numel(c)
    % Only interested in Wq, so use tilde for other outputs
    % Store to (ii)th element of Wq
    [~, Wq(ii), ~, ~, ~] = MMCQ(lambda, mu, c(ii), Nwait)
end
plot(c,Wq);