تبلیغات
نکته های کلیدی در آب و هواشناسی سینوپتیک - مطالب بهمن 1393
 
نکته های کلیدی در آب و هواشناسی سینوپتیک
خدایا! کمکم کن؛ پیمانی را که در طوفان با تو بستم در آرامش فراموش نکنم
درباره وبلاگ


خدایا !
از این ناراحتم كه روزی بسیاری از درهای علوم را بر روی خود بگشاییم و هنوز شناختمان از تو تنها در همین حد باشد.


مدیر وبلاگ : mehdi doostkamian
مطالب اخیر
نویسندگان
نظرسنجی
مطالبی را که در وب گذاشته می شود چگونه ارزیابی می کنید:؟







پیوندها
آمار وبلاگ
  • کل بازدید :
  • بازدید امروز :
  • بازدید دیروز :
  • بازدید این ماه :
  • بازدید ماه قبل :
  • تعداد نویسندگان :
  • تعداد کل پست ها :
  • آخرین بازدید :
  • آخرین بروز رسانی :





برای نمایش تصاویر گالری كلیك كنید


دریافت كد گالری عكس در وب

محاسبه دمای نقطه شبنم به روش های مختلف:

Dewpoint calculated from:    Dry Bulb Temperature 
                               Relative Humidity
-----------------------------------------------------------------------------

     B = (ln(RH / 100) + ((17.27 * T) / (237.3 + T))) / 17.27

     D = (237.3 * B) / (1 - B)

       where:
               T = Air Temperature (Dry Bulb) in Centigrade (C) degrees
              RH = Relative Humidity in percent (%)
               B = intermediate value (no units) 
               D = Dewpoint in Centigrade (C) degrees



    Here is the same formula, but broken down into smaller pieces:

          L = ln(RH / 100)
          M = 17.27 * T
          N = 237.3 + T

          B = (L + (M / N)) / 17.27

          D = (237.3 * B) / (1 - B)

            where:
                    T = Air Temperature (Dry Bulb) in Centigrade (C) degrees
                   RH = Relative Humidity in percent (%)
                    L = intermediate value (no units) 
                    N = intermediate value (no units) 
                    M = intermediate value (no units) 
                    B = intermediate value (no units) 
                    D = Dewpoint in Centigrade (C) degrees

                    * = multiply by...
                   e^ = natural log (e to the power of...)




  Dewpoint calculated from:  Dry Bulb Temperature 
                             Wet Bulb Temperature
                             Barometric Pressure
------------------------------------------------------------------------------

     Es = 6.108 * (e^((17.27 * T) / (237.3 + T)))

     Ew = 6.108 * (e^((17.27 * W) / (237.3 + W)))

      E = Ew - (0.00066 * (1 + 0.00115 * W) * (T - W) * P)

     RH = 100 * (E / Es)

      B = (ln(E / 6.108)) / 17.27

      D = (237.3 * B) / (1 - B)


           where:
                    W = Wet Bulb Temperature in Centigrade (C) degrees
                    P = Barometric Pressure in millibars (mb) 
                        (See site pressure table below)
                   Es = Saturation Vapor Pressure at Dry Bulb (mb)
                   Ew = Saturation Vapor Pressure at Wet Bulb (mb)
                    E = Actual Vapor Pressure (mb)
                    B = intermediate value (no units) 
                   RH = Relative Humidity in percent (%)
                    D = Dewpoint in Centigrade (C) degrees

                    * = multiply by...
                   e^ = natural log (e to the power of...)


                 ELE(ft)   P(mb)                        ELE(ft)   P(mb)   
                 ======   ======                        ======   ======  
   Tucson         2340      932           Yuma Valley     114     1009  
   Yuma Mesa       191     1006           Safford        2955      912  
   Coolidge       1385      965           Maricopa       1185      972  
   Agulia         2150      939           Parker          307     1002  
   Bonita         4415      864           Citrus Farm    1335      967  
   Litchfield     1014      978           Phx Greenway   1315      968  
   Marana         1973      945           Yuma N.Gila     145     1008  
   Phx Encanto    1100      975           Eloy           1513      961  
   Dateland        533      995           Scottsdale     1540      960  
   Paloma          720      988           Mohave          480      996  
   Laveen         1020      978           Queen Creek    1420      964 
   Harquahala     1180      972
 



   Barometric Pressure calculated from  Elevation
--------------------------------------------------------------------------

   P = 101.3 * ((( 293 - ( 0.0065 * Z )) / 293 ) ^ 5.26 )

     where: 
       E = Elevation in meters (m)
       P = Barometric Pressure in millibars (mb)
  
       * = multiply by...
       ^ = to the power of


 To Convert Feet (f) to Meters (m) :
-----------------------------------------------

   m = f * 0.3048

   where:
     m = elevation in meters (m)
     f = elevation in feet (f)



 ===========================================================================

   Source: 'Converting Humidity Expressions with Computers and Calculators
            Cooperative Extension Leaflet 21372.  
            University of California - Davis
            Author: R. Snyder and R. Snow





نوع مطلب :
برچسب ها :
لینک های مرتبط :

       نظرات
شنبه 25 بهمن 1393
mehdi doostkamian
در جدول زیر شیوه تبدیلات دما به حالت های مختفلف را بیان می کند: 

FromTo FahrenheitTo CelsiusTo Kelvin
Fahrenheit (F)F(F - 32) * 5/9(F - 32) * 5/9 + 273.15
Celsius (C or o)(C * 9/5) + 32CC + 273.15
Kelvin (K)(K - 273.15) * 9/5 + 32K - 273.15K




نوع مطلب :
برچسب ها :
لینک های مرتبط :

       نظرات
شنبه 25 بهمن 1393
mehdi doostkamian
دقت کنید که اسکریپت زیر همات تابع polyfit هست که در محیط متلب گذاشته شد. بنابراین برای محاسبه رون با استفاده از این تابع کافیست که ابتدا زمان و متغیر وابسته که همان عناصر اقلیمی می باشد را تعریف و برنامه را اجرا کنید در جه چند جمله را هم می توانید به راحتی با این اسکریپت حساب کرد:

function [p,S,mu] = polyfit(x,y,n) 
%   POLYFIT Fit polynomial to data. 
%   POLYFIT(X,Y,N) finds the coefficients of a polynomial P(X) of 
%   degree N that fits the data, P(X(I))~=Y(I), in a least-squares sense. 
%   [P,S] = POLYFIT(X,Y,N) returns the polynomial coefficients P and a 
%   structure S for use with POLYVAL to obtain error estimates on 
%   predictions.  If the errors in the data, Y, are independent normal 
%   with constant variance, POLYVAL will produce error bounds which 
%   contain at least 50% of the predictions. 
%   The structure S contains the Cholesky factor of the Vandermonde 
%   matrix (R), the degrees of freedom (df), and the norm of the 
%   residuals (normr) as fields.    
%   [P,S,MU] = POLYFIT(X,Y,N) finds the coefficients of a polynomial 
%   in XHAT = (X-MU(1))/MU(2) where MU(1) = mean(X) and MU(2) = std(X). 
%   This centering and scaling transformation improves the numerical 
%   properties of both the polynomial and the fitting algorithm. 
%   Warning messages result if N is >= length(X), if X has repeated, or 
%   nearly repeated, points, or if X might need centering and scaling. 
%   See also POLY, POLYVAL, ROOTS. 
 
%   Copyright 1984-2002 The MathWorks, Inc. 
%   $Revision: 5.17 $  $Date: 2002/04/09 00:14:25 $ 
 
% The regression problem is formulated in matrix format as: 
%    y = V*p    or 
%          3  2 
%    y = [x  x  x  1] [p3 
%                      p2 
%                      p1 
%                      p0] 
% where the vector p contains the coefficients to be found.  For a 
% 7th order polynomial, matrix V would be: 
% V = [x.^7 x.^6 x.^5 x.^4 x.^3 x.^2 x ones(size(x))]; 
 
if ~isequal(size(x),size(y)) 
    error('X and Y vectors must be the same size.') 
end 
 
x = x(:); 
y = y(:); 
 
if nargout > 2 
   mu = [mean(x); std(x)]; 
   x = (x - mu(1))/mu(2); 
end 
 
% Construct Vandermonde matrix. 
V(:,n+1) = ones(length(x),1); 
for j = n:-1:1 
   V(:,j) = x.*V(:,j+1); 
end 
 
% Solve least squares problem, and save the Cholesky factor. 
[Q,R] = qr(V,0); 
ws = warning('off','all');  
p = R\(Q'*y);    % Same as p = V\y; 
warning(ws); 
if size(R,2) > size(R,1) 
   warning('MATLAB:polyfit:PolyNotUnique', ... 
       'Polynomial is not unique; degree >= number of data points.') 
elseif condest(R) > 1.0e10 
    if nargout > 2 
        warning('MATLAB:polyfit:RepeatedPoints', ... 
            'Polynomial is badly conditioned. Remove repeated data points.') 
    else 
        warning('MATLAB:polyfit:RepeatedPointsOrRescale', ... 
            ['Polynomial is badly conditioned. Remove repeated data points\n' ... 
            '         or try centering and scaling as described in HELP POLYFIT.']) 
    end 
end 
r = y - V*p; 
p = p.';          % Polynomial coefficients are row vectors by convention. 
 
% S is a structure containing three elements: the Cholesky factor of the 
% Vandermonde matrix, the degrees of freedom and the norm of the residuals. 
 
S.R = R; 
S.df = length(y) - (n+1); 
S.normr = norm(r);





نوع مطلب :
برچسب ها :
لینک های مرتبط :

       نظرات
سه شنبه 21 بهمن 1393
mehdi doostkamian

Syntax

lambda = factoran(X,m)
[lambda,psi] = factoran(X,m)
[lambda,psi,T] = factoran(X,m)
[lambda,psi,T,stats] = factoran(X,m)
[lambda,psi,T,stats,F] = factoran(X,m)
[...] = factoran(...,param1,val1,param2,val2,...)

Definitions

factoran computes the maximum likelihood estimate (MLE) of the factor loadings matrix Λ in the factor analysis model

where x is a vector of observed variables, μ is a constant vector of means, Λ is a constant d-by-m matrix of factor loadings, f is a vector of independent, standardized common factors, and e is a vector of independent specific factors. xμ, and e are of length d. f is of length m.

Alternatively, the factor analysis model can be specified as

whereis a d-by-d diagonal matrix of specific variances.

Description

lambda = factoran(X,m) returns the maximum likelihood estimate, lambda, of the factor loadings matrix, in a common factor analysis model with m common factors. X is an n-by-d matrix where each row is an observation of d variables. The (i,j)th element of the d-by-m matrix lambda is the coefficient, or loading, of the jth factor for the ith variable. By default, factoran calls the function rotatefactors to rotate the estimated factor loadings using the 'varimax' option.

[lambda,psi] = factoran(X,m) also returns maximum likelihood estimates of the specific variances as a column vector psi of length d.

[lambda,psi,T] = factoran(X,m) also returns the m-by-m factor loadings rotation matrix T.

[lambda,psi,T,stats] = factoran(X,m) also returns a structure stats containing information relating to the null hypothesis, H0, that the number of common factors is mstats includes the following fields:

FieldDescription
loglike

Maximized log-likelihood value

dfe

Error degrees of freedom = ((d-m)^2 - (d+m))/2

chisq

Approximate chi-squared statistic for the null hypothesis

p

Right-tail significance level for the null hypothesis

factoran does not compute the chisq and p fields unless dfe is positive and all the specific variance estimates in psi are positive (see Heywood Case below). If X is a covariance matrix, then you must also specify the 'nobs' parameter if you want factoran to compute the chisq and p fields.

[lambda,psi,T,stats,F] = factoran(X,m) also returns, in F, predictions of the common factors, known as factor scores. F is an n-by-m matrix where each row is a prediction of m common factors. If X is a covariance matrix, factoran cannot compute Ffactoran rotates F using the same criterion as for lambda.

[...] = factoran(...,param1,val1,param2,val2,...) enables you to specify optional parameter name/value pairs to control the model fit and the outputs. The following are the valid parameter/value pairs.

ParameterValue
'xtype'

Type of input in the matrix X'xtype' can be one of:

'data'

Raw data (default)

'covariance'

Positive definite covariance or correlation matrix

'scores'

Method for predicting factor scores. 'scores' is ignored if X is not raw data.

'wls' 
'Bartlett'

Synonyms for a weighted least-squares estimate that treats F as fixed (default)

'regression' 
'Thomson'

Synonyms for a minimum mean squared error prediction that is equivalent to a ridge regression

'start'

Starting point for the specific variances psi in the maximum likelihood optimization. Can be specified as:

'random'

Chooses d uniformly distributed values on the interval [0,1].

'Rsquared'

Chooses the starting vector as a scale factor times diag(inv(corrcoef(X))) (default). For examples, see Jöreskog [2].

Positive integer

Performs the given number of maximum likelihood fits, each initialized as with 'random'factoran returns the fit with the highest likelihood.

Matrix

Performs one maximum likelihood fit for each column of the specified matrix. The ith optimization is initialized with the values from the ith column. The matrix must have d rows.

'rotate'

Method used to rotate factor loadings and scores. 'rotate' can have the same values as the 'Method' parameter of rotatefactors. See the reference page for rotatefactors for a full description of the available methods.

 

'none'

Performs no rotation.

 

'equamax'

Special case of the orthomax rotation. Use the 'normalize''reltol', and 'maxit' parameters to control the details of the rotation.

 

'orthomax'

Orthogonal rotation that maximizes a criterion based on the variance of the loadings.

Use the 'coeff''normalize''reltol', and 'maxit' parameters to control the details of the rotation.

 

'parsimax'

Special case of the orthomax rotation (default). Use the 'normalize''reltol', and 'maxit' parameters to control the details of the rotation.

 

'pattern'

Performs either an oblique rotation (the default) or an orthogonal rotation to best match a specified pattern matrix. Use the 'type' parameter to choose the type of rotation. Use the 'target' parameter to specify the pattern matrix.

 

'procrustes'

Performs either an oblique (the default) or an orthogonal rotation to best match a specified target matrix in the least squares sense.

Use the 'type' parameter to choose the type of rotation. Use 'target' to specify the target matrix.

 

'promax'

Performs an oblique procrustes rotation to a target matrix determined by factoran as a function of an orthomax solution.

Use the 'power' parameter to specify the exponent for creating the target matrix. Because 'promax' uses'orthomax' internally, you can also specify the parameters that apply to 'orthomax'.

 

'quartimax'

Special case of the orthomax rotation (default). Use the 'normalize''reltol', and 'maxit' parameters to control the details of the rotation.

 

'varimax'

Special case of the orthomax rotation (default). Use the 'normalize''reltol', and 'maxit' parameters to control the details of the rotation.

 

Function

Function handle to rotation function of the form

[B,T] = 
myrotation(A,...)

where A is a d-by-m matrix of unrotated factor loadings, B is a d-by-m matrix of rotated loadings, and T is the corresponding m-by-m rotation matrix.

Use the factoran parameter 'userargs' to pass additional arguments to this rotation function. See User-Defined Rotation Function.

'coeff'

Coefficient, often denoted as γ, defining the specific 'orthomax' criterion. Must be from 0 to 1. The value 0 corresponds to quartimax, and 1corresponds to varimax. Default is 1.

'normalize'

Flag indicating whether the loading matrix should be row-normalized (1) or left unnormalized (0) for 'orthomax' or 'varimax' rotation. Default is 1.

'reltol'

Relative convergence tolerance for 'orthomax' or 'varimax' rotation. Default is sqrt(eps).

'maxit'

Iteration limit for 'orthomax' or 'varimax' rotation. Default is 250.

'target'

Target factor loading matrix for 'procrustes' rotation. Required for 'procrustes' rotation. No default value.

'type'

Type of 'procrustes' rotation. Can be 'oblique' (default) or 'orthogonal'.

'power'

Exponent for creating the target matrix in the 'promax' rotation. Must be ≥ 1. Default is 4.

'userargs'

Denotes the beginning of additional input values for a user-defined rotation function. factoran appends all subsequent values, in order and without processing, to the rotation function argument list, following the unrotated factor loadings matrix A. See User-Defined Rotation Function.

'nobs'

If X is a covariance or correlation matrix, indicates the number of observations that were used in its estimation. This allows calculation of significance for the null hypothesis even when the original data are not available. There is no default. 'nobs' is ignored if X is raw data.

'delta'

Lower bound for the specific variances psi during the maximum likelihood optimization. Default is 0.005.

'optimopts'

Structure that specifies control parameters for the iterative algorithm the function uses to compute maximum likelihood estimates. Create this structure with the function statset. Enter statset('factoran') to see the names and default values of the parameters that factoran accepts in the optionsstructure. See the reference page for statset for more information about these options.

Examples

expand all

Estimate and Plot Factor Loadings

Load the sample data.

load carbig

Define the variable matrix.

X = [Acceleration Displacement Horsepower MPG Weight];
X = X(all(~isnan(X),2),:);

Estimate the factor loadings using a minimum mean squared error prediction for a factor analysis with two common factors.

[Lambda,Psi,T,stats,F] = factoran(X,2,'scores','regression');
inv(T'*T);   % Estimated correlation matrix of F, == eye(2)
Lambda*Lambda' + diag(Psi); % Estimated correlation matrix
Lambda*inv(T);              % Unrotate the loadings
F*T';                       % Unrotate the factor scores

Create biplot of two factors.

biplot(Lambda,'LineWidth',2,'MarkerSize',20)

Estimate the factor loadings using the covariance (or correlation) matrix.

[Lambda,Psi,T] = factoran(cov(X),2,'xtype','cov')
% [Lambda,Psi,T] = factoran(corrcoef(X),2,'xtype','cov')
Lambda =

   -0.2432   -0.8500
    0.8773    0.3871
    0.7618    0.5930
   -0.7978   -0.2786
    0.9692    0.2129


Psi =

    0.2184
    0.0804
    0.0680
    0.2859
    0.0152


T =

    0.9476    0.3195
    0.3195   -0.9476

Although the estimates are the same, the use of a covariance matrix rather than raw data doesn't let you request scores or significance level.

Use promax rotation.

[Lambda,Psi,T,stats,F] = factoran(X,2,'rotate','promax',...
                                      'powerpm',4);
inv(T'*T)                            % Estimated correlation of F,
                                     % no longer eye(2)
Lambda*inv(T'*T)*Lambda'+diag(Psi)   % Estimated correlation of X
ans =

    1.0000   -0.6391
   -0.6391    1.0000


ans =

    1.0000   -0.5424   -0.6893    0.4309   -0.4167
   -0.5424    1.0000    0.8979   -0.8078    0.9328
   -0.6893    0.8979    1.0000   -0.7730    0.8647
    0.4309   -0.8078   -0.7730    1.0000   -0.8326
   -0.4167    0.9328    0.8647   -0.8326    1.0000

For example factor analysis 2  

Over the course of 100 weeks, the percent change in stock prices for ten companies has been recorded. Of the ten companies, the first four can be classified as primarily technology, the next three as financial, and last three as retail. It seems reasonable that the stock prices for companies that are in the same sector might vary together as economic conditions change. Factor Analysis can provide quantitative evidence that companies within each sector do experience similar week to-week changes in stock price.

First load the data, then call factoran and specify a model fit with three common factors. By default, factoran would compute rotated estimates of the loadings to try and make their interpretation simpler, but for the moment, specify an unrelated solution.

 load stockreturns

[Loadings,specificVar,T,stats] = factoran(stocks,3,'rotate','none');

 

The first two factoran return arguments are the estimated loadings and the estimated specific variances. Each row of the loadings matrix represents one of the ten stocks, and each column corresponds to a common factor. With unrotated estimates, interpretation of the factors in this fit is difficult because most of the stocks contain fairly large coefficients for two or more factors.

Loadings

Loadings =

       0.8885    0.2367   -0.2354

       0.7126    0.3862    0.0034

       0.3351    0.2784   -0.0211

       0.3088    0.1113   -0.1905

       0.6277   -0.6643    0.1478

       0.4726   -0.6383    0.0133

       0.1133   -0.5416    0.0322

       0.6403    0.1669    0.4960

       0.2363    0.5293    0.5770

       0.1105    0.1680    0.5524

From the estimated specific variances, we can see that the model indicates that a particular stock price varies quite a lot beyond the variation due to the Common factors.

specificVar

specificVar =

       0.0991

       0.3431

       0.8097

       0.8559

       0.1429

       0.3691

       0.6928

       0.3162

       0.3311

       0.6544

A specific variance of 1 would indicate that there is no common factor component in that variable, while a specific variance of 0 would indicate that the variable is entirely determined by common factors. These data seem to fall somewhere in between.

The p-value returned in the stats structure fails to reject the null hypothesis of three common factors, suggesting that this model provides a satisfactory explanation of the covariation in these data.

stats.p

ans =

       0.8144

To determine if fewer than three factors can provide an acceptable fit, you can try a model with two common factors. The p-value for this second fit is highly significant, and rejects the hypothesis of two factors, indicating that the simpler model is not sufficient to explain the pattern in these data.

 

[Loadings2, specificVar2, T2, stats2] = factoran (stocks, 2,'rotate','none');

stats2.p

ans =

      3.5610e-006

Factor Rotation

As the results above illustrate, the estimated loadings from an unrotated

Factor Analysis fit can have a complicated structure. The goal of factor rotation is to find a parameterization in which each variable has only a small number of large loadings, i.e., is affected by a small number of factors, preferably only one. This can often make it easier to interpret what the factors represent.  If you think of each row of the loadings matrix as coordinates of a point in M-dimensional space, then each factor corresponds to a coordinate axis. Factor rotation is equivalent to rotating those axes, and computing new loadings in the rotated coordinate system. There are various ways to do this. Some methods leave the axes orthogonal, while others are oblique methods that change the angles between them. For this example, rotate the estimated loadings by using the promax criterion, a common oblique method.

[LoadingsPM,specVarPM] = factoran (stocks,3,'rotate','promax');

LoadingsPM

LoadingsPM =

       0.9452    0.1214   -0.0617

       0.7064   -0.0178    0.2058

       0.3885   -0.0994    0.0975

       0.4162   -0.0148   -0.1298

       0.1021    0.9019    0.0768

       0.0873    0.7709   -0.0821

      -0.1616    0.5320   -0.0888

       0.2169    0.2844    0.6635

       0.0016   -0.1881    0.7849

      -0.2289    0.0636    0.6475

Promax rotation has created a simpler structure in the loadings, one in which most of the stocks have a large loading on only one factor. To see this more clearly, you can plot each stock using the factor loadings as coordinates. "Simple" structure in the loadings appears in this plot as stocks that fall along one of the factor axes. Because there are three factors, it's easier to see the loadings if you make a pair of two-dimensional plots

 

subplot(1,2,1);

plot(LoadingsPM(:,1),LoadingsPM(:,2),'b.');

text(LoadingsPM(:,1),LoadingsPM(:,2), num2str((1:10)'));

line([-1 1 NaN 0 0 NaN 0 0],[0 0 NaN -1 1 NaN 0 0],...

     'Color','black');

xlabel('Factor 1');

ylabel('Factor 2');

axis square;

subplot(1,2,2);

plot(LoadingsPM(:,1),LoadingsPM(:,3),'b.');

text(LoadingsPM(:,1),LoadingsPM(:,3), num2str((1:10)'));

line([-1 1 NaN 0 0 NaN 0 0],[0 0 NaN -1 1 NaN 0 0],...

     'Color', 'black');

xlabel('Factor 1');

ylabel('Factor 3');

axis square;





نوع مطلب :
برچسب ها :
لینک های مرتبط :

       نظرات
یکشنبه 19 بهمن 1393
mehdi doostkamian

یکی از گله های دائمی کاربران متلب، سرعت بسیار پایین اجرای برنامه ها در متلب است. زبان متلب، یک زبان مفسری است و برنامه های نوشته شده در آن، کامپایل نمی شوند. بنابراین طبیعی است که سرعت اجرای برنامه های متلب، در مقایسه با زبان های کامپایلری، مانند C، پایین باشد. اما آیا واقعا، همه تقصیرها متوجه متلب است؟ در این مقاله آموزشی کوچک، می خواهیم نشان دهیم که چگونه می توان با رعایت اصول ساده، حداکثر سرعت قابل دسترسی در متلب را، برای برنامه ها به دست آوریم.

یکی از اشتباه هایی که بسیاری از برنامه نویسان متلب مرتکب می شوند، عدم تخصیص فضای مناسب برای آرایه ها و ماتریس ها، قبل از مقدار دهی است. زبان هایی مانند C یا #C (بخوانید سی شارپ)، در هنگام تعریف آرایه ها، اندازه آرایه ها را به صورت اجباری از برنامه نویس می خواهند و هر گاه در طول اجرای برنامه، بخواهیم که مقدار آرایه را در جایی که بیش از طول آرایه است، تغییر دهیم، برنامه خطا می دهد. اما متلب، از آن جا که سادگی را به عنوان محور اولیه در نظر گرفته است، چنین ضرورت هایی را به برنامه نویسی تحمیل نمی کند. اما مشکل دقیقا از همین جا شروع می شود. برای آرایه های کوچک، همه چیز به خوبی و خوشی تمام می شود. اما وقتی آرایه ها، از یک حد بزرگ تر می شوند، ایم مسأله واقعا دردسر ساز می شود.

در متلب، برای تخصیص فضای اولیه (Pre-Allocation)، از توابع مختلفی استفاده می شود. ازمیان این توابع، پر کاربردترین آن ها، تابع zeros است. این تابع ابعاد ماتریس مورد نظر را می گیرید، و بخشی از حافظه را به همان اندازه، برای آرایه موزذ نظر تخصیص می دهد. این کار، در زبان C، با تابع malloc انجام می شود. برای آگاهی بیشتر از چگونگی کارکرد این تابع، به راهنمای آن در هلپ متلب، مراجعه کنید.

دو برنامه زیر را در نظر بگیرید. این برنامه ها برای محاسبه تعداد زیادی از جملات سری فیبوناچی (Fibonacci)، نوشته شده است. در سری فیبوناچی، هر جمله با مجموع دو جمله قبل از خودش برابر است. جمله اول و دوم نیز، طبق قرارداد برابر با صفر و یک در نظر گرفته می شوند.

 

 

 

برنامه اول:

clear;
n=300000;
x(1)=0;
x(2)=1;
for k=3:n
x(k)=x(k-1)+x(k-2);
end

برنامه دوم:

clear;
n=300000;
x=zeros(1,n);     % Pre-Allocation
x(1)=0;
x(2)=1;
for k=3:n
x(k)=x(k-1)+x(k-2);
end

این دو برنامه، فقط در مورد تخصیص اولیه (خط سوم از برنامه دوم)، با هم اختلاف دارند. اما جالب است بدانید که مدت اجرای برنامه اول، بر روی کامپیوتر من، در حدود 4 دقیقه بود. در حالی برنامه دوم، در کمتر از یک ثانیه اجرا می شود. حال فرض کنید که در یک برنامه بزرگ، این مشکلات چقدر می تواند حادتر و شدیدتر باشد.

منبع: farshadsoft.blogfa.com





نوع مطلب :
برچسب ها :
لینک های مرتبط :

       نظرات
سه شنبه 7 بهمن 1393
mehdi doostkamian

Important Statistics Formulas

This web page presents statistics formulas described in the Stat Trek tutorials. Each formula links to a web page that explains how to use the formula.

Parameters

Statistics

Unless otherwise noted, these formulas assume simple random sampling.

Correlation

Simple Linear Regression

Counting

Probability

Random Variables

In the following formulas, X and Y are random variables, and a and b are constants.

Sampling Distributions

Standard Error

Discrete Probability Distributions

Linear Transformations

For the following formulas, assume that Y is a linear transformation of the random variable X, defined by the equation: Y = aX + b.

Estimation

Hypothesis Testing

Degrees of Freedom

The correct formula for degrees of freedom (DF) depends on the situation (the nature of the test statistic, the number of samples, underlying assumptions, etc.).

Sample Size

Below, the first two formulas find the smallest sample sizes required to achieve a fixed margin of error, using simple random sampling. The third formula assigns sample to strata, based on a proportionate design. The fourth formula, Neyman allocation, uses stratified sampling to minimize variance, given a fixed sample size. And the last formula, optimum allocation, uses stratified sampling to minimize variance, given a fixed budget.





نوع مطلب :
برچسب ها :
لینک های مرتبط :

       نظرات
شنبه 4 بهمن 1393
mehdi doostkamian