Applied Numerical Methods Using MATLAB. Won Y. Yang

Чтение книги онлайн.

Читать онлайн книгу Applied Numerical Methods Using MATLAB - Won Y. Yang страница 20

Applied Numerical Methods Using MATLAB - Won Y. Yang

Скачать книгу

target="_blank" rel="nofollow" href="#fb3_img_img_3145a29d-eb42-5530-83f1-34e517218185.png" alt="equation"/>

      whose value is 1 over [0,1] and 0 elsewhere. The average of this standard uniform number x is

      (1.1.2)equation

      and its variance or deviation is

      (1.1.3)equation

      (1.1.4)equation

Image described by caption and surrounding text.

      %nm01f05a.m N=1e4; x=rand(N,1); % An Nx1 noise vector with U(0,1) mx=mean(x); sgm2=sum((x-mx).̂2)/(N-1), var(x) subplot(221), M=20; hist(x,M) % Histogram having M=20 bins a=-1; b=1; y=(b-a)*x+a; %Eq.(1.1.4): 1000x1 noise vector with U(-1,1) subplot(222), hist(y,M) % Histogram

       1.1.8.2 Random Number with Normal (Gaussian) Distribution

      The numbers in a matrix generated by the MATLAB function ‘ randn(M,N)’ have normal (Gaussian) distribution with average m = 0 and variance σ2 = 1, as described by N(0,1). The random number x generated by ‘ rand()’ has the probability density function

      (1.1.6)equation

      The probability density function of the new Gaussian number generated by this transformation is obtained by substituting x = (ym)/σ into Eq. (1.1.5) and dividing the result by the scale factor σ (which can be seen in dx = dy/σ) so that the integral of the density function over the whole interval ( ∞,+∞) amounts to 1.

      (1.1.7)equation

      %nm01f05b.m N=1e4; x=randn(N,1); % An Nx1 noise vector with N(0,1) subplot(223), M=20; hist(x,M) % Histogram having M=20 bins f=@(x,m,sgm)exp(-(x-m).̂2/2/sgm̂2)/sqrt(2*pi)/sgm; %Gaussian density ftn [Ns,Cs]=hist(x,20); dx=Cs(2)-Cs(1); % Bin width x_=[-5:0.01:5]; fx=f(x_,0,1); hold on, plot(x_,fx*dx*N,'r:') sgm=1/2; m=1; y=sgm*x+m; % An Nx1 noise vector with N(m,sgm̂2) subplot(224), hist(y,M) % Histogram [Ns,Cs]=hist(y,M); dy=Cs(2)-Cs(1); % Bin width y_=[-5:0.01:5]; fy=f(y_,m,sgm); hold on, plot(y_,fy*dy*N,'r:')

      For practice, we make a vector consisting of 1000 standard Gaussian numbers, transform it to make a vector of numbers having normal distribution N(1,1/4), with mean m = 1 and variance σ2 = 1/4, and then draw the histograms for the two Gaussian number vectors (Figure 1.5b1,b2) by running the above block of MATLAB statements.

      1.1.9.1 if‐end and switch‐case‐end Statements

Relational operator Remark
< Less than
<= Less than or equal to
== Equal
> Greater than
>= Greater than or equal to
∼= Not equal (≠)
& and
| or
not

      1 (Ex. 1) A Simple if‐else‐end Block%nm119_1.m: example of if-end block t=0; if t>0 sgnt= 1; else sgnt= -1; end

      2 (Ex. 2) A Simple if‐elseif‐end Block%nm119_2.m: example of if-elseif-end block if t>0 sgnt= 1 elseif t<0 sgnt= -1 end

      3 (Ex. 3) An if‐elseif‐else‐end Block%nm119_3.m: example of if-elseif-else-end block if t>0, sgnt= 1 elseif t<0, sgnt= -1 else sgnt= 0 end

      4 (Ex. 4) An if‐elseif‐elseif‐..‐else‐end Block%nm119_4.m: example of if-elseif-elseif-else-end block point= 85; if point>=90, grade= 'A' elseif point>=80, grade= 'B' elseif point>=70, grade= 'C' elseif point>=60, grade= 'D' else grade= 'F' end

      5 (Ex.

Скачать книгу