We can generate random numbers given as CDF using Inverse Transform Samping:
The inverse transform sampling method works as follows:
Please find required MATLAB code along with necessary details in comments below:
clear all, close all, clc
% Plot the cumulative distribution function over the range
0-20.
syms x
f(x)=-exp(-25.*x./1132);
x1 = 0:20;
distCDF = f(x1);
subplot(2,1,1);
plot(x1, distCDF, 'LineWidth', 3);
title('True CDF');
sample=500; % number of samples to be generated
num_random=10; % number of points generated in each sample
% If you want to see graphically that given CDF of generated
random numbers
% actually approximate true CDF, genrate larger number of random
number in
% each sample by uncommenting lines below
% sample=10;
% num_random=500;
for i=1:sample
% Generate numberOfRandoms uniformly distributed random
numbers.
unif_rn = rand(num_random, 1);
% Invert the CDF of the given CDF to get a function that can
% generate random numbers drawn from a required distribution,
% given numbers drawn from a uniform distribution.
inv_f = finverse(f); % calculate F^-1
X=round(double(inv_f(unif_rn))); % calculate F^-1(u)
Rand_num(:,i)=X; % store random number
% plot the ith sample cdf
subplot(2,1,2);
hold on
pause(0.01)
cdfplot(X)
xlim([0 20])
title('Numerical CDF')
end
---------------------------
To plot the numerical CDF of a data, I have used cdfplot() available at mathworks, which I have included below for your ease of reference:
function cdfplot(X)
% cdfplot(X)
% displays a plot of the Empirical Cumulative Distribution
Function
% (CDF) of the input array X in the current figure. The
empirical
% CDF y=F(x) is defined as the proportion of X values less than or
equal to x.
% If input X is a matrix, then cdfplot(X) parses it to the vector
and
% displays CDF of all values.
%
% EXAMPLE:
% figure;
% cdfplot(randn(1,100));
% hold on;
% cdfplot(-log(1-rand(1,100)));
% cdfplot(sqrt(randn(1,100).^2 + randn(1,100).^2))
% legend('Normal(0,1) CDF', 'Exponential(1) CDF', 'Rayleigh(1)
CDF', 4)
% Version 1.0
% Alex Podgaetsky, September 2003
% [email protected]
%
% Revisions:
% Version 1.0 - initial version
tmp = sort(reshape(X,prod(size(X)),1));
Xplot = reshape([tmp tmp].',2*length(tmp),1);
tmp = [1:length(X)].'/length(X);
Yplot = reshape([tmp tmp].',2*length(tmp),1);
Yplot = [0; Yplot(1:(end-1))];
figure(gcf);
hp = plot(Xplot, Yplot);
ColOrd = get(gca, 'ColorOrder');
ord = mod(length(get(gca,'Children')), size(ColOrd,1));
set(hp, 'Color', ColOrd((ord==0) + (ord>0)*ord, :));
if ~ishold
xlabel('X', 'FontWeight','b','FontSize',12);
ylabel('F(X)', 'FontWeight','b','FontSize',12);
title('Empirical CDF', 'FontWeight','b','FontSize',12);
grid on;
end
----------------------------------------------
--------------------------------------------
You can verify the nature of random numbers by plotting the numerical cdf after generating a lot of random numbers per samples. For 500 points generated in each of the 10 samples, we obtain two cdf as :
---------------------------------------- SCREENSHOT OF CODE
The matrix Rand_num contains the generated 500 samples of 10 random numbers each.
Generate 500 samples of 10 numbers according to the cdf -exp(-25x/1132) using matlab, please include the...
using matlab Perform the following using Matlab For an additive Gaussian noise: a. Generate 4000 samples with mean value of 3 and variance of 9. b. Plot the sample values using two different ways. c. Determine the actual mean, variance, and standard deviation. d. Determine the median, mode, and range. e. Sketch the histogram. tle- enerate and plot the probability density function (pdf) and its corresponding cumulative distribution function (cdf) ror he M For the following two signals: / and...
Using MATLAB, not R codes, I repeat, please, not in R, just MATLAB codes, write the complete code for: 1. Assume Y is an exponential random variable with rate parameter λ=2. (1) Generate 1000 samples from this exponential distribution using inverse transform method (2) Compare the histogram of your samples with the true density of Y.
USING MATLAB PLEASE PROVIDE THE CODE. THANK YOU 1s an exponential random variable with rate parameter 2. 1. Assume (1) Generate 1000 samples from this exponential distribution using inverse transform method (2) Compare the histogram of your samples with the true density of Y 1s an exponential random variable with rate parameter 2. 1. Assume (1) Generate 1000 samples from this exponential distribution using inverse transform method (2) Compare the histogram of your samples with the true density of Y
Please answer this question using Matlab: Write a matlab function to generate and plot a sine wave at a specified frequency having at least 10 cycles, for this case the amplitude will represent voltage. Your sine wave should have a positive going zero crossing at T=0. Make sure your plot has at least 25 samples per cycle. Make sure the plot is with respect to time. Your function needs to return your generated samples and time vector. The frequency will...
Q: please solve using matlab code withe comment 1. Write the Matlab code to generate: x = cos(w1*t) + cos(w2*t); where, w1=7; w2=23; t = [0:0.005:2] 2. Plot the signal using sub plot a. in time domain b. in frequency domain 3) Sample the signal under different sampling conditions: a. Ts<1/2fm b. Ts=1/2fm c. Ts>1/2fm 4). Multiple plot: the signal sampled under sampling condition and the signal x a. in time domain b. in frequency domain c. Label and Title...
Please write and include a matlab code for the following: Given the following differential equation 10?̈+ 20?̇ + 250? = ?(?) a. Plot response to f(t) = 200sin(4t) b. Plot response to a step f(t) = 200 that starts at t = 0 s and stops at t = 2s; note that the response goes past the 2 seconds of input. Part a.) I need matlab code to generate the plot for 10x''+20x'+250x=200sin(4t) Part b.) I need matlab code to...
Using MATLAB 1. Assume Y is an exponential random variable with rate parameter λ=2. (1) Generate 1000 samples from this exponential distribution using inverse transform method (2) Compare the histogram of your samples with the true density of Y.
please do on paper then program 3. Sampling. Write a function to generate samples of the ramp function y 5 (a) Write a mathematical expression for y. Use piece-wise linear notation. Suppose we want to create a plot of the ramp function from t- o to t=2 using a step of 0.1. (b) Write the numbers that need to be created and stored for the t-samples and the y-samples. Note: Write them all out. Don't be lazy! (c) Write a...
Matlab code using heaviside 1. Create an m-file that will generate a rectangular pulse mathematically defined as The user of the m-file can select the parameter # which must be positive and the rectangular pulse must equal 1 all the way to include the end points # and Provide the code of the m- file and provide the code showing that you tested this m-file by generating a CT pulse of width running from -5 to 5 and a DT...
Using the basic developed MATLAB signal functions, generate the following sequences and then plot the signal samples using the stem function. x_1[n] = 3 delta[n + 2] + 2 delta[n] - delta[n - 3] + 5 delta[n - 7], for -5 lessthanorequalto n lessthanorequalto 15. X_2[n] = 10u[n] - 5u[n - 5] - 10u[n - 10] + 5u[n - 15]. Generate the periodic sequence and plot the samples (using the stem function) of cap x[n] = {..., -2, -1, 0,...