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

5.24 The derivative of a continuous function f(x) in a sampled function is f \'

ID: 2991717 • Letter: 5

Question

5.24

The derivative of a continuous function f(x) in a sampled function is
f ' (xi) = f(xi+1 ) - f(xi)
?x
where ?x = xi+1 - xi. Assume that a vector vect contains nsamp samples of a function taken at a spacing of dx per sample. Write a function that will calculate the derivative of this vector from the given equation. the function should check to make sure that dx is greather than zero to prevent divide by zero errors in the function.
To check your function, you should generate a data set whose derivative is known and compare the result of the function with the known correct answer. A good choice for a test function is sin(x). From elementary calculus we know that dsin(x)/dx = cos(x). Generate an input vector containing 100 values of the function sin(x) starting at x = 0 and using a step size ?x of 0.05. Take the derivative of the vector with your function and then compare the resulting answers to the known correct answer. How close did your function come to calculating the correct value for the dervative.

5.28

The birthday problem is stated as follows: if there is a group of n people in a room, what is the probability that two or more of them have the same birthday? It is possible to determine the answer to this question by simulation. Write a function that calculates the probability that two or more of n people will have the same birthday, where n is the calling argument. Hint: to do this the function should create an array of size n and generate n birthdays in the range 1 to 365 randomly. It should then check to see if any of the n birthdays are identical. The function should perform this experiment at least 5000 times and calculate the fraction of those times in which two or more people had the same birthday.

Explanation / Answer

N = 40;

a = 0;

b= 0;

for d = 1:5000

z = floor (365 * rand (N, 1));

l = 0;

for i = 2:N

for j = 2:N

if z (i) == z (j) && i ~= j

l = l + 1;

end

end

end

if l > 0

b = b + 1;

end

end

probability = b/5000;

disp ((probability));

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