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

Program Must be in Matlab! Write a user-defined function called CDF that take in

ID: 3559999 • Letter: P

Question

Program Must be in Matlab!

Write a user-defined function called CDF that take in two positive constants a and b, and the onedimensional array x and returns the generalized exponential function of the form: Your function should return 0 and the warning "negative parameter!!" if either a or b is negative. Now write a main program that uses the Matlab function rand to randomly choose one value of the parameter a between 0.95 and 1.55. On the other hand, there are four possible values of the parameter b as follows: b = [0.5,1.0.1.5.5.0], Generate 50 values of x in the interval between 0 and 2.5. For the randomly chosen value of a, generate a plot of F(x) versus ,y for the four values of parameter b. Remember to label your graph appropriately and use comments liberally.

Explanation / Answer

Code for function CDF. Save as CDF.m

function f = CDF(a,b,x)
if( (a<=0) | (b<=0))
disp('negative parameter!!');
f=0;
return;
else
for i=1:length(x)
if(x(i)>=0)
f(i)=1-exp(-(x(i)/a).^b);
else
f(i) =0;
end
end
end
end

Code for main

a=(1.55-0.95)*rand()+0.95;
b_vector = [0.5 1.0 1.5 5.0];
x=linspace(0,2.5,50);
for i=1:4
b=b_vector(i);
y=CDF(a,b,x);
if(length(y)==1 & y==0)
continue;
end
figure(i);
plot(x,y);
grid on;
xlabel('x');
ylabel('F(x)');
title(strcat('F(x) vs. x for b= ',num2str(b)));
end

In case of any problem or required modification comment back.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote