0
$\begingroup$

I want to simulate the demand of a factory. This is not a real problem, the demand follows this relation $D= AB^2C^3$ where $A$, $B$ and $C$ have normal distributions: $$A\sim N(10,2.5),\quad B\sim(6,0.4),\quad C\sim(5,0.9).$$

I have the covariance matrix of this problem which is $$\text{cov}_x=\begin{bmatrix}2.5&0.1&0.2\\0.1&0.4&0.3\\0.2&0.3&0.9\end{bmatrix}.$$

The problems asks to

  • Generate demand data in a non-correlated context and use eigenvalue and eigenvector for this.

  • Fit these demands using the Kumaraswamy distribution function, which is $$Z= Z_\min + (Z_\max-Z_\min)(1-(1-F(Z))^{1/b})^{1/a}$$

I attach my code below. I don't know why this code has an error.

clc
clear
cov_x=[2.5 0.1 0.2;0.1 0.4 0.3;0.2 0.3 0.9];
E_x=[10 6 5];
[V, landa]=eig(cov_x);
E_w=V'*E_x';
var_w= landa;
W=repmat(E_w,1,1000)+sqrt(var_w)*(randn(3,1000));
X=V*W;
A= X(1,:);  B= X(2,:);  C=X(3,:);
%D= A'*B.^2*C.^3';
for k=1:1000
   D(:,k)=A(:,k)'*B(:,k).^2*C(:,k).^3;
end

%now we use kumara
Z=sort(D);
FZ= @(i)i/1001;
f=@(y,FDS) y(1)+((y(2)-y(1)).*((1-((1-FDS).^(1/y(3)))).^(1/ y(4))));
y0=[0.1 0.1 0.1 0.1];
y =lsqcurvefit(f,y0,FZ,Z)

This is my error: enter image description here

$\endgroup$

1 Answer 1

1
$\begingroup$

My professor helped me for solving this error like below:

clc
clear
cov_x=[2.5 0.1 0.2;0.1 0.4 0.3;0.2 0.3 0.9];
E_x=[10 6 5];
[V, landa]=eig(cov_x);
E_w=V'*E_x';
var_w= landa;
W=repmat(E_w,1,1000)+sqrt(var_w)*(randn(3,1000));
X=V*W;
A= X(1,:);  B= X(2,:);  C=X(3,:);
%D= A'*B.^2*C.^3';
for k=1:1000
   D(:,k)=A(:,k)'*B(:,k).^2*C(:,k).^3;
end
 
%now we use komara
Z=sort(D);
i=1:1000;
FZ=@(i)i/1001;
 
f=@(y,Ramin)y(1)+((y(2)-y(1)).*((1-((1-Ramin).^(1/y(3)))).^(1/ y(4))));
y0=[0.1 0.1 0.1 0.1];

y =lsqcurvefit(f,y0,FZ(i),Z)

this code has not a error.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.