# How to perform Monte Carlo simulationbased on built PCE to get histogram and confidence interval of output?

Greeting，the PCE is bulit,then how to perform Monte Carlo simulation based on PCE model to get histogram of output,and store output to print it?

As I have not find the Monte Carlo simulation in PCE tutorial…

PCE is for stochastic system,then if input X is known,then how to compute output Y?

Dear AmosJoseph

You can find an example on how to estimate statistical moments using PCE here:

Best regards,
Styfen

Once the PCE is bulit,we can get statistical moments.

But I ask how to perform Monte Carlo simulation based on the bulit PCE model to get histogram of output,and store the sampling output of Monte Carlo simulation.

Dear AmosJoseph

It’s in fact so straightforward that there is no example on this. We should add it!

Using the example mentioned by @styfen.schaer , once your PCE is built you use the following code:

N_MCS = 10000 ;                  % size of your sample for histogram
XX = uq_getSample(N_MCS);        % sample the inputs from myInput
YY  = uq_evalModel(myPCE,XX);    % evaluate the PCE on the XX sample
hist(YY)


Best regards
Bruno

“”"
myPCE = uq_createModel(MetaOpts);

X = uq_getSample(1e6,‘MC’);
Y = uq_evalModel(myPCE,X);

uq_figure
uq_histogram(Y)
xlabel(’\mathrm Y’)
ylabel(‘Frequency’)
“”"

Pardon,I get the Frequency histogram, but the vertical axis is not decimal.
Why?

Dear AmosJoseph,

You simply have to normalize your histogram as explained and demonstrated here:

https://ch.mathworks.com/help/matlab/ref/matlab.graphics.chart.primitive.histogram.html

h = histogram(x,'Normalization','probability')


Best regards,
Styfen