Do it using matlab program 1. Perform the operations outlined below using Logica
ID: 2248639 • Letter: D
Question
Do it using matlab program
1. Perform the operations outlined below using Logical Vectors when appropriate.
Program Description:
This program creates 10,000 random resistors with a normal distribution
and mean of 100 ohms and standard deviation of 15 ohms.
Perform the following operations with the resistor data using logical
vectors where appropriate.
1. Output the total number of resistors created along with their actual
mean and standard deviation as they will differ slightly from the
values given.
2. Output the percentage of resistor with values > mean and < mean
3. Output the percentage of resistors within +/- 1 Standard Deviation
of the mean.
4. Repeat step 3 for +/- 2 Standard Deviations and +/- 3 Standard
Deviations.
5. Output the resistor position numbers and the corresponding resistor
values for all resistors outside of +/- 3 standard deviations of the mean
2. A sample of the output is shown below. Keep in mind that the results will vary for each run of your code.
Explanation / Answer
Solution :
Part 1 needs some clarification. Please update in comment section more about "Output the total number of resistors created along with their actual mean and standard deviation as they will differ slightly from the values given."
Rest of the parts are coded here :
%******
clc;
clear all;
mu = 100;
sig = 15;
num_of_samples = 10000;
ll1 = mu -1*sig;
ll2 = mu -2*sig;
ll3 = mu -3*sig;
ul1 = mu +1*sig;
ul2 = mu +2*sig;
ul3 = mu +3*sig;
data = normrnd(mu,sig,1,num_of_samples);
%qs1
actual_mean = mean(data);
slight_differ_parameter = 0.01;
%rest of the body
%qs2 : less and greater % wrt mean
ans2 = (sum(logical(data<mu))/(num_of_samples))*100;
printf(' %% of resistor less than mean : %d ' ,ans2);
ans3 = (sum(logical(data>mu))/(num_of_samples))*100;
printf(' %% of resistor greater than mean : %d ' ,ans3);
%qs3 lying in +/- 1 sigma
ans4 = (sum(logical(((data>ll1) + (data<ul1))-(data<ul1)))/(num_of_samples))*100;
printf(' %% of resistor lying in +/- 1sigma range : %d ' ,ans4);
%qs4 lying in +/- 2 sigma
ans5 = (sum(logical(((data>ll2) + (data<ul2))-(data<ul2)))/(num_of_samples))*100;
printf(' %% of resistor lying in +/- 2sigma range : %d ' ,ans5);
%qs4 lying in +/- 3 sigma
ans6 = (sum(logical(((data>ll3) + (data<ul3))-(data<ul3)))/(num_of_samples))*100;
printf(' %% of resistor lying in +/- 3sigma range : %d ' ,ans6);
temp = logical(((data>ll3) + (data<ul3))-(data<ul3)) ;
%qs5 output the outliers after +/- 3 sigma
if ans6 ~=100
printf(' Following resistors are lying after the +/- 3sigma range: ' ,ans6);
printf(' >>>INFO : Lower limit for 3 sigma :%d , Upper limit for 3 sigma : %d ' ,ll3,ul3);
for i=1:length(temp)
if temp(i)==0
printf(' Resistor Value :%d , At Index :%d ',data(i),i);
endif
end
else
printf(' NO resistors are lying after the +/- 3sigma range ');
endif
%******
Sample run :
% of resistor less than mean : 49.73
% of resistor greater than mean : 50.27
% of resistor lying in +/- 1sigma range : 84.13
% of resistor lying in +/- 2sigma range : 97.66
% of resistor lying in +/- 3sigma range : 99.87
Following resistors are lying after the +/- 3sigma range:
>>>INFO : Lower limit for 3 sigma :55 , Upper limit for 3 sigma : 145
Resistor Value :52.9607 , At Index :43
Resistor Value :54.9963 , At Index :736
Resistor Value :50.2619 , At Index :1088
Resistor Value :49.2073 , At Index :2423
Resistor Value :52.7398 , At Index :3665
Resistor Value :49.3455 , At Index :4417
Resistor Value :50.1469 , At Index :4651
Resistor Value :54.8453 , At Index :4954
Resistor Value :46.1585 , At Index :6822
Resistor Value :52.6956 , At Index :7977
Resistor Value :46.9616 , At Index :8775
Resistor Value :52.4444 , At Index :8851
Resistor Value :53.0788 , At Index :9699
Or running it again gives different set of data as expected :
% of resistor less than mean : 49.58
% of resistor greater than mean : 50.42
% of resistor lying in +/- 1sigma range : 84.02
% of resistor lying in +/- 2sigma range : 97.83
% of resistor lying in +/- 3sigma range : 99.92
Following resistors are lying after the +/- 3sigma range:
>>>INFO : Lower limit for 3 sigma :55 , Upper limit for 3 sigma : 145
Resistor Value :44.7165 , At Index :1282
Resistor Value :53.2463 , At Index :1319
Resistor Value :24.5849 , At Index :4861
Resistor Value :48.923 , At Index :5315
Resistor Value :53.0966 , At Index :6438
Resistor Value :47.8665 , At Index :6485
Resistor Value :54.2454 , At Index :7463
Resistor Value :47.9425 , At Index :9985
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.