필터 지우기
필터 지우기

How to implement density function

조회 수: 2 (최근 30일)
Brave A
Brave A 2019년 4월 25일
댓글: Brave A 2019년 4월 25일
I would like to implemnet this "sampling algorithm for the following density function".
I tried with this code.Any help I will appricated.
% Example Monte Carlo Simulation in Matlab
%
% Generate n samples from a normal distribution
% r = ( randn(n,1) * sd ) + mu
% mu : mean
% sd : standard deviation
%
% Generate n samples from a uniform distribution
n = 100000; % The number of function evaluations
% --- Generate vectors of random inputs
% x1 ~ Normal distribution N(mean=100,sd=5)
% x2 ~ Uniform distribution U(a=5,b=15)
x = 5 + rand(0,1) * ( 15 - 5 );
% --- Run the simulation
% Note the use of element-wise multiplication
y = x.^2+(2/3x)+1/3;
% --- Create a histogram of the results (50 bins)
hist(y,50);
% --- Calculate summary statistics
y_mean = mean(y)
y_std = std(y)
y_median = median(y)
  댓글 수: 7
KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 4월 25일
code is running, result I didnot check
n=100000; % The number of function evaluations
x=5+rand(n,1)*(15-5);
y=x.^2+(2/3)*x+1/3;
hist(y,50);
y_mean=mean(y)
y_std=std(y)
y_median=median(y)
Brave A
Brave A 2019년 4월 25일
worked thanks

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by