Ho to perform Monte Carlo Simulation with a factor and a vector.
3 views (last 30 days)
Show older comments
Jonas Reibenspies
on 12 May 2022
Commented: Jonas Reibenspies
on 17 May 2022
Hey everybody, I'm trying to perform a Monte Carlo Simulation by randomly choosing 10 numbers of the factor and its standard deviaton 0.5859+-0.2321. Then these factors has to be multiplied with the vector TSS which has 353665 values. I found two possible ways of doing it, but non of them works.
The first:
clc
clear all
%% Read Data
data_TSS=readtable('turb_danuube_15min.csv'); % data TSS & time
TSS=data_TSS{1:1:353665,2};
time=data_TSS{1:1:353665,1};
%% TSS-PAH-Factor
data_Corr2=readtable('Factor_York.xlsx'); % data corr. factor TSS - PAH
factor=data_Corr2{:,3};
fac=mean(factor); %mean of the different factors of York River = 0.5859
S=std(factor); %standard deviation = 0.2321
%% Calculate PAH with Monte Carlo
TSS=data_TSS{1:1:353665,2};
nsamples = 10;
MCfactor= 0.3538+0.4642*rand(nsamples,1); %(Mean-Std)+2*Std, always (10 times) choose one random Number in between 0.3538 and 0.8180
PAH=TSS.*MCfactor;
this is my error:
Arrays have incompatible sizes for this operation.
Error in Monte_Carlo_Var2 (line 21)
PAH=TSS.*MCfactor;
The second:
%% Read Data
data_TSS=readtable('turb_danuube_15min.csv'); % data TSS & time
TSS=data_TSS{1:1:353665,2};
time=data_TSS{1:1:353665,1};
%% TSS-PAH-Factor
data_Corr2=readtable('Factor_York.xlsx'); % data corr. factor TSS - PAH
factor=data_Corr2{:,3};
fac=mean(factor); %mean of the different factors of York River = 0.5859
S=std(factor); %standard deviation = 0.2321
%% Calculate PAH with Monte Carlo
TSS=data_TSS{1:1:353665,2};
nsamples = 10;
for i=1:nsamples
MCfactor= 0.3538+0.4642*rand(1); %(Mean-Std)+2*Std, always choose one random Number in between 0.3538 and 0.8180
PAH(i)=MCfactor.*TSS;
end
this is my error:
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
Error in Monte_Carlo_Var1 (line 20)
PAH(i)=MCfactor.*TSS;
If anybody has an idea how to solve this problem I would be very happy. Thanks in advance.
Greetings Jonas
2 Comments
Accepted Answer
Torsten
on 16 May 2022
Edited: Torsten
on 16 May 2022
data_TSS=readtable('turb_danuube_15min.csv'); % data TSS & time
TSS=data_TSS(1:1:353665,2);
time=data_TSS(1:1:353665,1);
%% TSS-PAH-Factor
data_Corr2=readtable('Factor_York.xlsx'); % data corr. factor TSS - PAH
factor=data_Corr2(:,3);
fac=mean(factor); %mean of the different factors of York River = 0.5859
S=std(factor); %standard deviation = 0.2321
%% Calculate PAH with Monte Carlo
nsamples = 10;
MCfactor= 0.3538+0.4642*rand(nsamples,1); %(Mean-Std)+2*Std, always (10 times) choose one random Number in between 0.3538 and 0.8180
TSS_rand = [TSS*MCfactor(1),TSS*MCfactor(2),TSS*MCfactor(3),TSS*MCfactor(4),...
TSS*MCfactor(5),TSS*MCfactor(6),TSS*MCfactor(7),TSS*MCfactor(8),...
TSS*MCfactor(9),TSS*MCfactor(10)];
3 Comments
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!