Ho to perform Monte Carlo Simulation with a factor and a vector.

1 visualizzazione (ultimi 30 giorni)
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 Commenti
Torsten
Torsten il 12 Mag 2022
Modificato: Torsten il 12 Mag 2022
Then these factors has to be multiplied with the vector TSS which has 353665 values.
... to get what ? A matrix of size 10 x 353665 ?
Jonas Reibenspies
Jonas Reibenspies il 16 Mag 2022
Hello Torsten, thanks for your answer. I want to get a matrix of the size 353665x10 with these 10 random picked factors as columns and every factor multiplied with every single value of TSS in the lines.
In the secon version in the end the factor is multiplied with TSS but it doesnt work properly.
I also tried adding something like:
TSS=data_TSS{1:1:353665,2};
nsamples = 10;
A=nan(length(TSS),nsamples);
%%
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
MCPAH=MCfactor.*TSS;
end
A(:,i)=MCPAH(i);
but it still doesnt work.

Accedi per commentare.

Risposta accettata

Torsten
Torsten il 16 Mag 2022
Modificato: Torsten il 16 Mag 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 Commenti
Torsten
Torsten il 17 Mag 2022
TSS_rand = repmat(TSS,1,nsamples)*diag(MCfactor)

Accedi per commentare.

Più risposte (0)

Prodotti


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by