sensitivity analysis from monte carlo
25 ビュー (過去 30 日間)
古いコメントを表示
Hi, i'm trying to reach out for help from anyone expert here. I'm having trouble to run a sensitivity analysis. I have write a script to generate monte carlo uncertainty propogation for 2 paramaters. So, i want to run sensitity analysis from the script. But, i dont know how.
Here is the script. Can anyone help me to generate sensitivity analysis please?
PoissonRatio = 0.348;
diameter = 100;
pi = 3.142;
nsamples = 100000;
for i=1 : nsamples
modulus = 191.6e3+rand(1)*10.1e3;
thickness = 0.5+0.5*rand(1);
Po (i) = (2*pi*50*210.8);
pcr (i) = (2*pi*modulus*thickness^2)/(3*(1-PoissonRatio^2)*0.5);
pRankine (i) = (Po(i)/((Po(i)/pcr(i))+1))/1000;
end
min(pRankine);
max(pRankine);
mean(pRankine);
std(pRankine);
hist(pRankine,100);
% Calculate the mean and standard deviation of the output samples
sample_mean = mean(pRankine);
sample_std = std(pRankine);
% Plot a vertical line at the mean of the output samples
line([sample_mean sample_mean], ylim, 'LineWidth', 2, 'Color', 'r');
% Plot a shaded region around the mean representing one standard deviation
shaded_region = [sample_mean - sample_std, sample_mean + sample_std];
patch([shaded_region(1) shaded_region(1) shaded_region(2) shaded_region(2)], ...
[0 max(ylim) max(ylim) 0], 'r', 'FaceAlpha', 0.2, 'EdgeColor', 'none');
% Label the plot
xlabel('pRankine (kN)');
ylabel('Probability Density');
title('Monte Carlo Uncertainty Propagation');
0 件のコメント
回答 (1 件)
Abhimenyu
2024 年 6 月 14 日
Hello,
The sensitivity analysis is a method used to determine how different values of an input variable will impact a particular output variable under a given set of assumptions. To perform a sensitivity analysis in MATLAB, especially following a Monte Carlo simulation, you can analyze the correlation between the input parameters ('modulus' and 'thickness') and the output ('pRankine').
Please follow this MATLAB R2024 example code that has the code from the query shared and the example code for sensitivity analysis:
% Constants
PoissonRatio = 0.348;
diameter = 100;
pi = 3.142;
nsamples = 100000;
Preallocating the arrays and converting 'modulus' and 'thickness' to vectors for correlation.
% Preallocate arrays
modulus_samples = zeros(nsamples, 1);
thickness_samples = zeros(nsamples, 1);
Po = zeros(nsamples, 1);
pcr = zeros(nsamples, 1);
pRankine = zeros(nsamples, 1);
% Monte Carlo Simulation
for i = 1:nsamples
modulus_samples(i) = 191.6e3 + rand * 10.1e3;
thickness_samples(i) = 0.5 + 0.5 * rand;
Po(i) = 2 * pi * 50 * 210.8;
pcr(i) = (2 * pi * modulus_samples(i) * thickness_samples(i)^2) / (3 * (1 - PoissonRatio^2) * 0.5);
pRankine(i) = (Po(i) / ((Po(i) / pcr(i)) + 1)) / 1000;
end
min(pRankine);
max(pRankine);
mean(pRankine);
std(pRankine);
hist(pRankine,100);
% Calculate the mean and standard deviation of the output samples
sample_mean = mean(pRankine);
sample_std = std(pRankine);
% Plot a vertical line at the mean of the output samples
line([sample_mean sample_mean], ylim, 'LineWidth', 2, 'Color', 'r');
% Plot a shaded region around the mean representing one standard deviation
shaded_region = [sample_mean - sample_std, sample_mean + sample_std];
patch([shaded_region(1) shaded_region(1) shaded_region(2) shaded_region(2)], ...
[0 max(ylim) max(ylim) 0], 'r', 'FaceAlpha', 0.2, 'EdgeColor', 'none');
% Label the plot
xlabel('pRankine (kN)');
ylabel('Probability Density');
title('Monte Carlo Uncertainty Propagation');
The sensitivity analysis using the corr function of the MATLAB:
% Sensitivity Analysis using correlation coefficients
correlation_modulus = corr(modulus_samples, pRankine);
correlation_thickness = corr(thickness_samples, pRankine);
These coefficients indicate how sensitive 'pRankine' is to changes in each input parameter. Values close to ±1 indicate a strong linear relationship, while values close to 0 indicate a weak relationship.
% Display correlation coefficients
fprintf('Correlation between modulus and pRankine: %f\n', correlation_modulus);
fprintf('Correlation between thickness and pRankine: %f\n', correlation_thickness);
The scatter plot helps visualize the data and the strength of the relationship between inputs and output.
% Plot scatter plots to visualize sensitivity
figure;
subplot(1, 2, 1);
scatter(modulus_samples, pRankine, '.');
xlabel('Modulus (MPa)');
ylabel('pRankine (kN)');
title(sprintf('Correlation: %f', correlation_modulus));
subplot(1, 2, 2);
scatter(thickness_samples, pRankine, '.');
xlabel('Thickness (m)');
ylabel('pRankine (kN)');
title(sprintf('Correlation: %f', correlation_thickness));
Please follow this R2024a MATLAB documentation link to learn more about the corr function: https://www.mathworks.com/help/stats/corr.html
I hope this answers your query!
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Polar Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!