22 views

Uploaded by jc224

Fortran 1 Overview. Computational Economics. Matlab.

- Thermosys_422_UserGuide
- UG
- Matlab 2004
- Christoper Fernando
- Control Simulink Tutorial PART A
- scilab
- Automatically Converting Matlab Code to c Code
- Xcilab
- Chapter 01
- Simulink Release Notes
- Elastic Stiffness of Straight-sided Triangular Finite Elements by Analytical and Numerical Integration
- Using Matlab From a C#
- scilab
- Assignment1_EG168MATLAB(1)
- Apple II FORTRAN
- 1037703
- MPLAB_Blockset_Simulink
- MATLAB Skill Book May 9
- para 36
- Compulsive Buying Among College Students

You are on page 1of 24

Grey Gordon

Indiana University

Fall 2014

Origins

I

I

FORTRAN 77 (F77)

I

I

I

Matlab written in F77 originally (later translated to C).

Built to run on punchcards (fixed-source format).

FIND THE LARGEST NUMBER IN ABSOLUTE VALUE

IX = 1

DMAX = DABS ( DX (1))

IX = IX + INCX

DO 10 I = 2 , N

IF ( DABS ( DX ( IX )). LE . DMAX ) GO TO 5

IDAMAX = I

DMAX = DABS ( DX ( IX ))

5

IX = IX + INCX

10 CONTINUE

RETURN

I

object-oriented programming.

Supports all F77 features but some are obsoleted like GOTO.

dmax = maxval ( abs ( x ))

I

I

coarrays (a simple way to do distributed parallel computing).

I

cs201/NOTES/fortran.html

You may use codes written by others if you cite their code.

I

I

If you begin with their code as a base, modify it, and do not

cite their code, this is plagiarism.

exception to copyright laws (that is, they probably wont sue you).

In general, later in life you need to be concerned with licenses.

Code is released under various licenses. Examples:

I

I

I

I

I

I

BSD License

GNU GPL License

Public domain

Custom

Unspecified

Original code:

function [Z , Zprob ] = tauchen (N , mu , rho , sigma , m )

% Function TAUCHEN

%

% Purpose :

Finds a Markov chain whose sample paths

%

approximate those of the AR (1) process

%

z ( t +1) = (1 - rho )* mu + rho * z ( t ) + eps ( t +1)

%

where eps are normal with stddev sigma

%

% Format :

{Z , Zprob } = Tauchen (N , mu , rho , sigma , m )

%

% Input :

N

scalar , number of nodes for Z

%

mu

scalar , unconditional mean of process

%

rho

scalar

%

sigma

scalar , std . dev . of epsilons

%

m

max + - std . devs .

%

% Output :

Z

N *1 vector , nodes for Z

%

Zprob

N * N matrix , transition probabilities

%

%

Martin Floden

%

Fall 1996

%

%

This procedure is an implementation of George Tauchen ' s algorithm

%

described in Ec . Letters 20 (1986) 177 -181.

Z

Zprob

a

Z(N)

Z (1)

zstep

[...]

=

=

=

=

=

=

zeros (N ,1);

zeros (N , N );

(1 - rho )* mu ;

m * sqrt ( sigma ^2 / (1 - rho ^2));

-Z ( N );

( Z ( N ) - Z (1)) / ( N - 1);

New code with proper citation (fine):

function [Z , Zprob ] = tauchen (N , mu , rho , sigma , m )

% Function TAUCHEN

%

% Input :

N

scalar , number of nodes for Z

%

mu

scalar , unconditional mean of process

%

rho

scalar

%

sigma

scalar , std . dev . of epsilons

%

m

max + - std . devs .

%

% Output :

Z

N *1 vector , nodes for Z

%

Zprob

N * N matrix , transition probabilities

%

%

Originally by Martin Floden

%

Modified slightly by Grey Gordon

Z

Zprob

a

Z(N)

Z (1)

zstep

[...]

=

=

=

=

=

=

zeros (N ,1);

zeros (N , N );

(1 - rho )* mu ;

m * sqrt ( sigma ^2 / (1 - rho ^2));

-Z ( N );

( Z ( N ) - Z (1)) / ( N - 1);

Since this acknowledges the original author, even though there are

few modifications, this is fine.

New code without proper citation (VERY BAD):

function [Z , Zprob ] = tauchen (N , mu , rho , sigma , m )

% Function TAUCHEN

%

% Input :

N

number of points

%

mu

mean

%

rho

persistence

%

sigma

conditional stdev

%

m

coverage

%

% Output :

Z

nodes

%

Zprob

transition matrix

%

Z

= zeros (N ,1);

Zprob = zeros (N , N );

a

= (1 - rho )* mu ;

Z = linspace ( - m * sqrt ( sigma ^2 / (1 - rho ^2)) , ...

m * sqrt ( sigma ^2 / (1 - rho ^2)) , N );

[...]

modified, even though it improves on the original code, this is

plagiarism.

Youll probably want to use the code you develop in this class later

in life. In that case, you need to be concerned about licenses.

Example of a nice license (LAPACK, emphasis added):

Copyright (c) 1992-2008 The University of Tennessee. All rights reserved.

COPYRIGHT

Additional copyrights may follow

HEADER

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the

following conditions are met:

- Redistributions of source code must retain the above copyright notice, this list of conditions and the following

disclaimer.

- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following

disclaimer listed in this license in the documentation and/or other materials provided with the distribution.

- Neither the name of the copyright holders nor the names of its contributors may be used to endorse or promote

products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY

EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES

OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT

SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ... [truncated]

You can use LAPACK as much as you want (if you meet the

conditions).

The worst license I have ever seen (really a FAQ about the

Numerical Recipes license, emphasis added) :

When Do I Need a License? The Numerical Recipes book, and its electronic subscription version Numerical Recipes

Electronic, are sold as text and reference works, for reading and educational purposes. If you intend to use

Numerical Recipes code on a computer, you need a separate license. What Kinds of Licenses Are There? There are

two kinds of licenses. 1. With the purchase of a Numerical Recipes Code product, either a code download or a

Numerical Recipes Code CD-ROM, you automatically get a non-expiring Numerical Recipes Personal, Single-User

License that allows one individual to use the code on any number of computers.

2. With the purchase of a Numerical Recipes institutional subscription, you get a Numerical Recipes Institutional

Subscriber License that allows use of the code by any number of individuals on computers within a subscribers

fixed IP address range, during the term of the subscription.

See complete license terms for both license types here.

Can I Distribute Numerical Recipes Routines with My Application Bound invisibly into your executable .exe file?

Generally yes. As source code, linkable object libraries, or DLLs? Generally no. See more details here. Can a

Business Use Personal, Single-User Licenses? Yes, if each such license purchased is permanently assigned to a

specific individual before it is first used. Note, however, that the Personal, Single-User License may be assigned

only once, to a single individual. Thereafter it stays with that individual, whether or not he/she continues as an

employee. The single-user license is not a floating licenses or a license by the seat. Businesses needing greater

flexibility should purchase institutional subscriptions. What Else Comes with an Institutional Subscriber License?

For machines in the subscribers IP address range, institutional subscriptions include both unlimited access to

Numerical Recipes Code (and the license for its use), and also unlimited access to Numerical Recipes Electronic,

the electronic form of the Numerical Recipes book. The institutional subscription is generally the most

cost-effective way to make Numerical Recipes available to work groups, companies, and universities.

You should never use Numerical Recipes. Dont even look at it.

Programming

Case sensitivity

1. Fortran is not case-sensitive: foo==FOO==fOo

2. Matlab is case-sensitive: foo/=FOO/=fOo

I

I

I

The interpreter has to

I

I

I

I

Check what A is currently (scalar? ND-array?).

Determine what sum() does for this type of argument.

Create space for B on the LHS.

I

I

I

The compiler determines before the program is run

I

I

I

What sum() does.

Whether B is the right shape to fit sum(A).

I

I

I

Compiled is much better at error-checking before the program

is run.

Interpreted is much more flexible.

I

line of code.

Fortran).

I

I

I

I

I

I

Could mean A is a matrix and B is a vector.

Could also mean A is a vector and B is a scalar.

Moreover, A could be integers, or A could be decimals.

Implication: Matlab must check each time the line is reached.

I

I

I

The programmer must declare A and B beforehand.

The compiler then knows before runtime, e.g. that A is an

integer matrix and B is an integer vector.

I

I

Advantages and Disadvantages

I

I

I

Typed is much faster and safer better error-checking.

Untyped is slower, but more flexible and less verbose.

Object-oriented programming is easy.

I

by a factor of 10 or even 100)

verbose, better debugging)

I

If speed is critical.

I

I

I

Rough categorization of types of problems:

I

I

Linearization Matlab

Estimation Fortran or Matlab

I

and then generate Fortran code from it.

Matlab

- Thermosys_422_UserGuideUploaded byDamrongritSiriwutwiwat
- UGUploaded byMariaUrtubi
- Matlab 2004Uploaded byAbhishek Kunal
- Christoper FernandoUploaded byDanilo Veroy
- Control Simulink Tutorial PART AUploaded byHansraj Rahul
- scilabUploaded bysarathpara
- Automatically Converting Matlab Code to c CodeUploaded bytyanfeng
- XcilabUploaded bySkye Jaba
- Chapter 01Uploaded byJiyn Suliman Al Suleivani
- Simulink Release NotesUploaded byelhenshire_h
- Elastic Stiffness of Straight-sided Triangular Finite Elements by Analytical and Numerical IntegrationUploaded byjoeldallpai
- Using Matlab From a C#Uploaded bySaurav Keshri
- scilabUploaded byRelvin Colón
- Assignment1_EG168MATLAB(1)Uploaded bymoose187
- Apple II FORTRANUploaded byremow
- 1037703Uploaded byMd.Arifur Rahman
- MPLAB_Blockset_SimulinkUploaded bygem1144aa
- MATLAB Skill Book May 9Uploaded byjaishankar1977
- para 36Uploaded byLavkesh Bhambhani
- Compulsive Buying Among College StudentsUploaded bytheanuuradha1993gmai
- MatlabUploaded bycherif0
- UnknownUploaded byDeepu Nuniwal
- Visual Analytics Using Tableau-Class 3Uploaded bySayantan Mukherjee
- Matlab Concise NotesUploaded bynorthorsouth
- Sim u Link TutorialUploaded byTai Shan
- UploadUploaded bySalmaAn Malik
- ZWF21!01!004 NAS Message TransferUploaded byAnonymous cvA0Qw
- matlablect2_winter2009Uploaded bygundulp
- DRAFT Materials 07Apr2012Uploaded byDeepto Banerjee
- copyrightact.docUploaded bySubodh Subodh

- Snacking Startups 2.0 - CB Insights 2017Uploaded byjc224
- Convex Analsis ExerciseUploaded byjc224
- Corchon - Una Vision Panoramica de La Teoria de Las ContiendasUploaded byjc224
- Econometrics and Machine LearningUploaded byjc224
- WAIMLAp2017-OverviewProgram.pdfUploaded byjc224
- WAIMLAp2017-OverviewProgram.pdfUploaded byjc224
- Entrevista a ROmer - Enfoque Narrativo FMIUploaded byjc224
- Intro Input Output Analysis at the Regional LevelUploaded byjc224
- Tema 1 Risk Management - A Helicopter ViewUploaded byjc224
- Gauss Tutorial for Simulation MethodsUploaded byjc224
- Stock Watson 20 Years of Time Series Econometrics in 10 PicturesUploaded byjc224
- Feature Engineering.pdfUploaded byjc224
- Tesis Riesgos Financieros Colombia.pdfUploaded byjc224
- Calculo Del Valor en Riesgo y Perdida Esperada MedUploaded byjc224
- Heckman LectureUploaded byNikola Krivokapić
- peng-matlabparallel.pdfUploaded byjc224
- Comando XtprobitUploaded byjc224
- Analisis MultivariableUploaded byFernando Pezo Fonseca
- 01-IntroduccionALaComputacionDistribuidaUploaded byNibla Osnofla OvaCefe
- Weekly Sales Forecasting - Factorization MachinesUploaded byjc224
- Paper 2016 - Explaining Predictions of Non-Linear Classifiers in NLPUploaded byjc224
- Kuhn - Machine Learning With Class ImbalancesUploaded byjc224
- TD 2014.04_versão FinalUploaded byjc224
- TD 2014.04_versão FinalUploaded byjc224
- Call_for_Proposals_Gender_Gaps_CTIUploaded byjc224
- Syllabus AndroidUploaded byjc224
- Máxima Verosimilitud y Estimación Bayesiana de Parámetros (7).pdfUploaded byTONY
- SAS - Cool Maps With Customized AreasUploaded byjc224
- (10) What Are Kernels in Machine Learning and SVM_ - QuoraUploaded byjc224
- LOS ORIGENES DEL ANALISIS FUNCIONAL.pdfUploaded byjc224