0% found this document useful (0 votes)
5 views13 pages

Final Lab 01 Report

Lab report

Uploaded by

mirzaebad088
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views13 pages

Final Lab 01 Report

Lab report

Uploaded by

mirzaebad088
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Exercise: 01

Code :
% Generate 10 random numbers between 0 and 1
random_uniform_shifted=5+(10-5)*rand(1,10);
figure;
plot (random_uniform_shifted,'o-');
title ('Uniformly Distributed random numbers Shifted between 5
and 10');
xlabel('Sample Number');
ylabel('Random Value');
output :
Exercise: 02
Code :
% Generate and plot histogram of 1000 random numbers

random_uniform_large=rand(1,1000);

figure;

histogram (random_uniform_large,20);

title ('Histogram of Uniforml Random numbers');

output :
2. Generating Normally Distributed (Gaussian) Random Numbers
EXAMPLE :
OUTPUT:

Exercise: 01
CODE :
% Generate and plot histogram of 1000 Gaussian random numbers

random_gaussian_large= randn(1, 1000);

figure;

histogram(random_gaussian_large, 20);

title('Histogram of Gaussian Random Numbers');


output :
Exercise: 02
CODE :
% Generate 1000 Gaussian random numbers and shift their mean
and std deviation
% Mean = 5, Standard Deviation = 2
mu = 5;
sigma = 2;
random_gaussian_shifted = mu + sigma * randn(1, 1000);
% Plot the Gaussian random numbers
figure;
histogram(random_gaussian_shifted, 20);
title('Normally Distributed Random Numbers Shifted');
output :

3- Generating Exponentially Distributed Random Numbers


EXAMPLE :
Output

Exercise: 1
Code : hi
% Generate and plot histogram of 1000 exponential random
numbers with rate parameter lambda
lambda=0.5;
random_exponential_large= -log(rand(1, 1000))/lambda;
figure;
histogram(random_exponential_large,20);
title('Histogram of Exponential Random Numbers (lambda=0.5');

output ;

4. Random Integer Generation


Example:
Output

Exercise:
Code :
% Generate a 5×5 matrix of random integers between 10 and 50
random_integers_matrix= randi([10, 50], 5, 5);
% Display random integers
disp(random_integers_matrix);

Output :
5. Seeding Random Numbers
EXAMPLE :

Exercise 01 :
Program
% Program to generate random numbers with different seeds
% Seed 1
rng(1); % Set the seed to 1
random_seeded_1 = rand(1, 5); % Generate 5 random numbers
disp('Random numbers with seed 1:');
disp(random_seeded_1);
% Seed 2
rng(2); % Set the seed to 2
random_seeded_2 = rand(1, 5); % Generate 5 random numbers
disp('Random numbers with seed 2:');
disp(random_seeded_2);
% Seed 3
rng(3); % Set the seed to 3
random_seeded_3 = rand(1, 5); % Generate 5 random numbers
disp('Random numbers with seed 3:');
disp(random_seeded_3);
% Seed 4
rng(4); % Set the seed to 4
random_seeded_4 = rand(1, 5); % Generate 5 random numbers
disp('Random numbers with seed 4:');
disp(random_seeded_4);
% Compare the outputs
disp('Comparison of random numbers generated with different seeds:');
comparison_matrix = [random_seeded_1; random_seeded_2;
random_seeded_3; random_seeded_4];
disp(comparison_matrix);

Output :

Exercise 02 :
Program:
% Number of samples
n = 10;
% Seed
seed = 42; % Use a single seed for demonstration
% Preallocate a matrix to store results
random_numbers1 = zeros(1, n);
random_numbers2 = zeros(1, n);
% First run
rng(seed); % Set the random seed
random_numbers1 = 5 + 2 * randn(1, n); % Mean = 5, Std = 2
% Second run (with the same seed)
rng(seed); % Reset the seed to the same value
random_numbers2 = 5 + 2 * randn(1, n); % Mean = 5, Std = 2
% Display the results
disp('First Run:');
disp(random_numbers1);
disp('Second Run:');
disp(random_numbers2);
% Check if they are the same
if isequal(random_numbers1, random_numbers2)
disp('The random numbers generated are the same for the same seed.');
else
disp('The random numbers generated are different.');
end

Output :

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy