How to write a Monte Carlo Simulation Code?
이전 댓글 표시
I want to start writing a code in Matlab in order to determine structural reliability of a bridge. The code is based on Monte Carlo Simulation. It would be very helpful if anyone helps me how to start with a * pattern of Monte Carlo Simulation * .
댓글 수: 1
hos shoj
2016년 4월 21일
salam peyda kardi be manam bede mrc
답변 (3개)
Adam Wyatt
2015년 3월 31일
Your question is ill-defined.
Monte-Carlo simulations simply mean perform your simulation with varying inputs such that the inputs are chosen randomly. Better MC simulations use prior information / simulations to pick the next iteration.
Here is an example - given an input, the method passes if it is greater than 0.5, fails if it is less than or equal to 0.5.
function out = Test(in)
out = (in>0.5);
end
And to test it:
MCSim = arrayfun(@(inputs) Test(inputs), rand(100,1));
댓글 수: 2
Reza
2015년 4월 1일
Adam Wyatt
2015년 4월 1일
Your question is far too vague - you're basically saying solve my problem, but haven't actually said what the problem is.
Lets assume that you have a set of variables (load, material etc.) and you want to test the performance of your system for different variable values. The first question that arises is what distribution are your variables, are the uniformly distributed or normally distributed say. Lets assume you have 2 variables, var1 is uniformly randomly distributed and var2 is normally distributed, and you want to perform N tests.
Lets say you want to run N tests, set up N vectors for your variable values:
N = 1000;
var1 = var1_min + (var1_max-var1_min)*rand(N, 1);
var2 = var2_mean + var2_std*randn(N, 1);
result = arrayfun(MyTestFunction, var1, var2);
% Where
function ScalarResult = MyTestFunction(Scalar_Var1, Scalar_Var2)
...
end
Hope this helps, but if you're not more specific then we cannot help you much more than that.
You could for example use the parallel toolbox with parfor to help speed up your testing:
N = 1000;
var1 = ...
var2 = ...
result = zeros(N, 1);
parfor n=1:N
result(n) = MyTestFun(var1(n), var2(n));
end
Image Analyst
2015년 3월 31일
1 개 추천
댓글 수: 2
NURSAFIKA BAHIRA JULI
2020년 1월 21일
Hi, can i ask can Monte carlo simulation run for langmuir isotherm. I just don't know how to begin the simulation
Image Analyst
2020년 1월 21일
You just did.
But I have no idea what langmuir isotherm is, so I can't help you with that.
John D'Errico
2015년 3월 31일
Most simply:
rand(1000,1)
What is the problem?
댓글 수: 6
Reza
2015년 4월 1일
John D'Errico
2015년 4월 1일
The point is, you have provided no information to help you, just the very general question about a simulation.
If you understand Monte Carlo, then what is the problem?
My guess is you don't really understand Monte Carlo, certainly not as it applies to your problem. If you do a simulation, the probability of failure is simply the number of times your system fails, divided by the total number of events in the simulation. Or you can use tools of statistical tolerancing to estimate things like this too. Regardless, your question is not a MATLAB one as far as I can see, but a very generic one about how does one perform Monte Carlo on a complex system.
The only answer we can give to a question as vague as is yours, is that you will need a tool that can predict failure for a given set of parameters, and then simply pass it the parameters that define your system. Then just count the failures.
vamsi krishna
2017년 11월 9일
sir i am doing montecarlo simulation for load forecasting as well as to know the uncertainities of the renewable energy for that where can i get the code
Image Analyst
2017년 11월 9일
You most likely will have to write it.
Edmar Adem
2018년 1월 17일
Hi Ma'am/Sir, A Monte Carlo sampling technique combined with a minimum cost assessment model is used to conduct the simulation of generation and risk costs. Do you have a code this problem? Please send me a code e93adem@gmail.com thank you and God bless..
John D'Errico
2018년 1월 17일
Sorry, but Answers is not a forum where we provide code written to your specs, and then sent to your e-mail address. In fact, I don't know of any sites that provide a free service like that.
카테고리
도움말 센터 및 File Exchange에서 Monte-Carlo에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!