Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This question about the matlab. I have created a function on matlab which is mak

ID: 2265982 • Letter: T

Question

This question about the matlab.

I have created a function on matlab which is make a 1xN vector by using the binary numerical system.

"function[out] = generate(N)

out=round(rand(1,N)) % for example N=4

end"

and the result will be like that [1 0 1 0]

my teacher wants to test this function with a function/matlab code.

he says:

Plot the running frequency of 1's in a single generated vector of size N = 100. ("Running frequency" means the frequency of 1's so far, as n ranges from 1 to 100.)

For example, if N = 4, and the vector b = [0 1 0 1], then the running frequency of 1's is runningFrequency = [0 0.5 0.3333 0.5] because the frequency of 1's until (and including) the first bit is 0, the frequency of 1's until the second bit is 1/2, the frequency of 1's until the third bit is 1/3, the frequency of 1's until the fourth bit is 1/2. To what value does the above graph converge? (This is a test of whether your GenerateBits function is working correctly. If it is not converging to the correct value, then you know that your function is not working correctly.)

[You do not need to hand in this: But generate several b vectors, and check that the graph is converging to the correct value.] Note: You must write a function called:

function freq = ComputeRunningFrequency(b)

%This function computes the running frequency of 1's in the input vector b. ...

end

i couldn't do it. can you help me? thanks..

Explanation / Answer

clc;
N=input('enter size of vector');;
b=generate(N);
freq=ComputeRunningFrequency(b);

function[out]=generate(N)
out=round(rand(1,N));
end

function[freq]=ComputeRunningFrequency(b)
c=0;
for a=1:numel(b)
if(b(a)==1)
c=c+1;
end
freq(a)=c/a;
end
end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote