%Class for CO907, Fri, Week 1. %__________________________________________ %Author: Jiarui Cao %Date: 8 Nov 2013 %Purpose: Sheet1. Queation 1.7b close all; clear all; clc; clf; %% We only do the simulation for one fixed n here. m=10000; n=100; %% Generate data. %Data=rand(m,n); title('Uniform maximum'); %Data=exprnd(1,m,n); title('Exponential maximum'); Data=gprnd(0.1,1,1,[m,n]); title('Pareto maximum'); %% Take the max of each row. maxData=zeros(m,1); for i=1:m maxData(i)=max(Data(i,:)); end hold on; %% Plot [f,xi]=ksdensity(maxData); plot(xi,f,'om','Markersize',15); paramhat=gevfit(maxData); %'gevfit' fits data by generalized extreme value distribution and returns 3 paramters stored in paramhat(1),paramhat(2) and paramhat(3). y=gevpdf(xi,paramhat(1),paramhat(2),paramhat(3));%Use the parameters we fitted from data to generate the corresponding theoratical curve. plot(xi,y,'k','linewidth',2); hold off xlabel('x'); ylabel('PDF'); legend('Data','Theory');