Question

2. Suppose the probability density function for American male height is roughly (in inches x) h(x)e-a-69)2/5.6 2.8V2 a) Write

0 0
Add a comment Improve this question Transcribed image text
Answer #1


Matlab code for finding integration using different method clear all close all %Probability distribution function h-e (x) (1.%integration using Simpson 1/3 and Simpson 3/8 method val simp 13-Simp13_int(h, a,b,n); val-simp 38-sinp38-int (h , a,b, n) ;end %%Matlab function forsimpson 3/8 Method function val-Simp38_int(f,a,b,n) f is the function for integration % a is the low

%Matlab code for finding integration using different method
clear all
close all
%Probability distribution function
h=@(x) (1./(2.8.*sqrt(2*pi)))*exp((-(x-69).^2)/5.6);
%height between 65 to 70
a=65; b=70; n=2;
%Function for which integration have to do
fprintf('\nProbability distribution function h(x)=\n')
disp(h)
fprintf('Height between [%2.2f to %2.2f] is \n',a,b)

%Integration using Simpson 1/3 and Simpson 3/8 method
    val_simp13=Simp13_int(h,a,b,n);
    val_simp38=Simp38_int(h,a,b,n);
    val_trap =trap_int(h,a,b,n);
fprintf('\tIntegration using Simpson 1/3 for 2 interval is %f.\n',val_simp13)

fprintf('\tIntegration using Simpson 3/8 for 2 interval is %f.\n',val_simp38)

fprintf('\tIntegration using Trapizoidal method for 2 interval is %f.\n',val_trap)

%height between 65 to 70
a=65; b=70; n=4;
%Function for which integration have to do
fprintf('\nProbability distribution function h(x)=\n')
disp(h)
fprintf('Height between [%2.2f to %2.2f] is \n',a,b)

%Integration using Simpson 1/3 and Simpson 3/8 method
    val_simp13=Simp13_int(h,a,b,n);
    val_simp38=Simp38_int(h,a,b,n);
    val_trap =trap_int(h,a,b,n);
fprintf('\tIntegration using Simpson 1/3 for 4 interval is %f.\n',val_simp13)

fprintf('\tIntegration using Simpson 3/8 for 4 interval is %f.\n',val_simp38)

fprintf('\tIntegration using Trapizoidal method for 4 interval is %f.\n',val_trap)

%height between 65 to 70
a=65; b=1000; n=4000;
%Function for which integration have to do
fprintf('\nProbability distribution function h(x)=\n')
disp(h)
fprintf('Height greater than %d is \n',a)

%Integration using Simpson 1/3 and Simpson 3/8 method
    val_simp13=Simp13_int(h,a,b,n);
    val_simp38=Simp38_int(h,a,b,n);
    val_trap =trap_int(h,a,b,n);
fprintf('\tIntegration using Simpson 1/3 for 4 interval is %f.\n',val_simp13)

fprintf('\tIntegration using Simpson 3/8 for 4 interval is %f.\n',val_simp38)

fprintf('\tIntegration using Trapizoidal method for 4 interval is %f.\n',val_trap)

     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%Matlab function for mid point integration
function val=trap_int(f,a,b,N)
    % func is the function for integration
    % a is the lower limit of integration
    % b is the upper limit of integration
    % N number of rectangles to be used
    val=0;
    %splits interval a to b into N+1 subintervals
    xx=linspace(a,b,N+1);
    dx=xx(2)-xx(1); %x interval
    %loop for Riemann integration
        for i=2:length(xx)-1
            xx1=xx(i);
            val=val+dx*double(f(xx1));
        end
       val=val+dx*(0.5*double(f(xx(1)))+0.5*double(f(xx(end))));
end

%%Matlab function for Simpson 1/3 Method
function val=Simp13_int(f,a,b,n)
%f=function for which integration have to do
%a=upper limit of integration
%b=lower limit of integration
%n=number of subintervals

    zs=f(a)+f(b);   %simpson integration
    %all x values for given subinterval
    xx=linspace(a,b,n+1);
    dx=(xx(2)-xx(1)); %x interval
    %Simpson Algorithm for n equally spaced interval
    for i=2:n
        if mod(i,2)==0
            zs=zs+4*f(xx(i));
        else
            zs=zs+2*f(xx(i));
        end
    end
    %result using Simpson rule
    val=double((dx/3)*zs);
end

%%Matlab function forSimpson 3/8 Method
function val=Simp38_int(f,a,b,n)
    % f is the function for integration
    % a is the lower limit of integration
    % b is the upper limit of integration
    % n is the number of trapizoidal interval in [a,b]
  
    %splits interval a to b into n+1 subintervals
    xx=linspace(a,b,n+1);
    dx=(xx(2)-xx(1)); %x interval
    val=f(a)+f(b);
    %loop for trapizoidal integration
        for i=2:n
            if mod(i-1,3)==0
                val=val+2*double(f(xx(i)));
            else
                val=val+3*double(f(xx(i)));
            end
        end
    %result using midpoint integration method
    val=(3/8)*dx*val;
end
  
%%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%%

Add a comment
Know the answer?
Add Answer to:
2. Suppose the probability density function for American male height is roughly (in inches x) h(x)e-a-69)2/5.6 2.8V2 a) Write a code to estimate the probability that an American male is between 65 an...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT