Física Computacional Conceptos de programación.



Similar documents
Práctica 1: PL 1a: Entorno de programación MathWorks: Simulink

Curriculum Reform in Computing in Spain

Propiedades del esquema del Documento XML de envío:

A simple application of the implicit function theorem

Software. Programming Language. Software. Instructor Özgür ZEYDAN. Bülent Ecevit University Department of Environmental Engineering

Bucle for_in. Sintaxis: Bucles for_in con listas. def assessment(grade_list): """ Computes the average of a list of grades

CONCEPTS OF INDUSTRIAL AUTOMATION. By: Juan Carlos Mena Adolfo Ortiz Rosas Juan Camilo Acosta

Computational Mathematics with Python

Tema: Encriptación por Transposición

Computational Mathematics with Python

Guidelines for Designing Web Maps - An Academic Experience

WESTMORELAND COUNTY PUBLIC SCHOOLS Integrated Instructional Pacing Guide and Checklist Computer Math

DIPLOMADO DE JAVA - OCA

Computational Mathematics with Python

manual de programacion en java para principiantes

manual de programacion en java para principiantes

Fedora 14 & Red Hat. Descripción del curso:

Algoritmo de PRIM para la implementación de laberintos aleatorios en videojuegos

Visión general de la integración con asanetwork

3. Operating Systems

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

Manejo Basico del Servidor de Aplicaciones WebSphere Application Server 6.0

Ecuador Official visa Application

Schema XML_PGE.xsd. element GrupoInformes. attribute XML_PGE.xsd unqualified qualified

Equity and Fixed Income

Ask your child what he or she is learning to say in Spanish at school. Encourage your child to act as if he or she is your teacher.

INTELIGENCIA DE NEGOCIO CON SQL SERVER

Curso SQL Server 2008 for Developers

Sub OPT() j = 1 k = 1 m = 1 n = 1 o = 1 g = 1 h = 1

Dyna ISSN: Universidad Nacional de Colombia Colombia

AV-002: Professional Web Component Development with Java

Introduction to MATLAB for Data Analysis and Visualization

Problem 1 (1.5 points)

CS1112 Spring 2014 Project 4. Objectives. 3 Pixelation for Identity Protection. due Thursday, 3/27, at 11pm

BDL4681XU BDL4675XU. Video Wall Installation Guide

Programming Languages & Tools

Introduction to MATLAB Gergely Somlay Application Engineer

Computación I: intro to Matlab. Francesca Maria Marchetti

Data Analysis with MATLAB The MathWorks, Inc. 1

Heuristic algorithm for a flexible flow shop problem minimizing total weighted completion time (w j. ) constrains with proportional machines (q m

HPN Product Tools. Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

September 20,2011 Clarification of the Functionality for the Service Provider Module Please see at the bottom a summary of these detail.

Please consult the Department of Engineering about the Computer Engineering Emphasis.

IBM PureSystems: Familia de Sistemas Expertos Integrados

MP4, MP7 1.NBT.1 MP4, MP7 1.NBT.1 MP4, MP7 1.MD Collect 20 Together MP4, MP7 1.NBT.1

Estructura de aplicación en PHP para System i

LOS ANGELES UNIFIED SCHOOL DISTRICT POLICY BULLETIN

Numerical Analysis. Professor Donna Calhoun. Fall 2013 Math 465/565. Office : MG241A Office Hours : Wednesday 10:00-12:00 and 1:00-3:00

Apéndice C: Código Fuente del Programa DBConnection.java

EE 1130 Freshman Eng. Design for Electrical and Computer Eng.

CONDITIONAL CLAUSES TIPOS PROP. CON IF / UNLESS. PROPOSICIÓN PRINCIPAL Will + verb ( = ll + verb) Modal (can, may, ) + Verb EJEMPLOS

Migración y Coexistencia desde Notes a Exchange Server 2007

INFORMATIONAL NOTICE

DYNA

Spanish 8695/S Paper 3 Speaking Test Teacher s Booklet Time allowed Instructions one not not Information exactly as they are printed not 8695/S

Monterey County Behavioral Health Policy and Procedure

Albiral 15 Data retractable monitor, brushed stainless steel cabinet Ref: 150EJSMI

PROGRAMA DE GRAFICACIÓN DE VELOCIDADES EN VENTANAS DE MAPINFO

Work Instruction (Instruccion de Trabajo) Wistron InfoComm (Texas) Corp.

Entry to Year 7 - Information for Parents

BALANCE DUE 10/25/2007 $ STATEMENT DATE BALANCE DUE $ PLEASE DETACH AND RETURN TOP PORTION WITH YOUR PAYMENT

MANUAL JAVASCRIPT ESPANOL. The hidden strength of manual javascript espanol online manual

EUROCALCULADORA. Option Compare Database. Private Sub Comando4_Click() [pesetas] = [euros] * End Sub

Inteligencia Artificial Representación del conocimiento a través de restricciones (continuación)

CE 504 Computational Hydrology Computational Environments and Tools Fritz R. Fiedler

YOU CAN COUNT ON NUMBER LINES

OnPremise y en la nube

Didactic training using a CNC lathe designed in a virtual environment

Chapter 7: Additional Topics

Operating System Compiler Bits Part Number CNL 6.0 AMD Opteron (x86-64) Windows XP x64 Intel C Microsoft Platform SDK 64 P10312

manual de visual foxpro 6 PDF

GETTING TO KNOW ARCGIS MODELBUILDER KAMBAMBA.NET 1/7 GETTING-TO-KNOW-ARCGIS-MODELBUILDER.PDF

Credit Number Lecture Lab / Shop Clinic / Co-op Hours. MAC 224 Advanced CNC Milling MAC 229 CNC Programming

ACTIVITY # Dear Parent, Carta a los Padres. pbskids.org

FOR TEACHERS ONLY The University of the State of New York

Tennessee Mathematics Standards Implementation. Grade Six Mathematics. Standard 1 Mathematical Processes

EQUATIONS and INEQUALITIES

McGraw-Hill The McGraw-Hill Companies, Inc.,

NUMERICAL METHODS TOPICS FOR RESEARCH PAPERS

Digital Fundamentals

Automation for the process of the spectral simulations of the light reflection of the human skins

Clovis Community College Core Competencies Assessment Area II: Mathematics Algebra

New Server Installation. Revisión: 13/10/2014

Range of studies: List of Courses Taught in Spanish CURSO

Oracle 11g Administration

GENERAL OVERVIEW STATEMENT OF THE PROBLEM LITERATURE REVIEW METHODOLOGY FINDINGS RESEARCH AND PEDAGOGICAL IMPLICATIONS LIMITATIONS CONCLUSIONS

Transcription:

Física Computacional Conceptos de programación. F. A. Velázquez-Muñoz Departamento de Física CUCEI UdeG 6 de febrero de 2015

Sistemas Operativos ms-dos windows linux suse; redhat; ubuntu; etc. unix Mac OSx

usuario aplicación sistema operativo hardware

Lenguajes de Programacón: Matlab Fortran C++ Pascal Basic Java etc.

MatLab (MATrix LABoratory) The Language of Technical Computing High-level language for numerical computation, visualization, and application development Interactive environment for iterative exploration, design, and problem solving. Mathematical functions for linear algebra, statistics, Fourier analysis, filtering, optimization, numerical integration, and solving ordinary differential equations. Built-in graphics for visualizing data and tools for creating custom plots Development tools for improving code quality and maintainability and maximizing performance Tools for building applications with custom graphical interfaces Functions for integrating MATLAB based algorithms with external applications and languages such as C, Java,.NET, and Microsoft R Excel R

Fortran (Formula Translating System). is a general-purpose, imperative programming language that is especially suited to numeric computation and scientific computing

Declaración y uso de Variables

Tipos de Variables INTEGER: entero REAL: real COMPLEX: complejo LOGICAL: logica (verdadero o falso) CHARACTER: caracter

En un programa de fortran, la forma de escribir la declaración de variables es: program v a r s i n t e g e r : : i r e a l : : a complex : : img l o g i c a l : : i o c h a r a c t e r (10) : : fecha i =1 a =2.33 img=cmplx ( 1, 2 ) i o = t r u e fecha = 2015/01/01 w r i t e ( 6, ) w r i t e ( 6, ) w r i t e ( 6, ) w r i t e ( 6, ) w r i t e ( 6, ) i a img i o f e c h a end program v a r s

El resultado que muestra el programa en pantalla es: compu$./a.out 1 2.330000 (1.000000,2.000000) F 2015/01/01

c l e a r a l l i =1 a =2.33 img=1+2 i i o=f a l s e f e c h a = 2015/01/01

i = a = 1 img = 3 i o = 2.3300 0 f e c h a = 2015/01/01

program prog r e a l : : a, b, c a =1.2 b=3.4 c=a+b w r i t e ( 6, ) c end program prog

program prog r e a l : : a, b, c r e a d (, ) r e a d (, ) a b c=a+b w r i t e ( 6, ) c end program prog

program prog r e a l : : a, b, c open ( u n i t =100, f i l e = d a t o s. dat ) r e a d (100, ) a r e a d (100, ) b c l o s e ( 1 0 0 ) c=a+b w r i t e ( 6, ) c end program prog

program prog r e a l : : a, b, c open ( u n i t =100, f i l e = d a t o s. dat ) r e a d ( 1 0 0, 1 1 0 ) a r e a d ( 1 0 0, 1 1 0 ) b c l o s e ( 1 0 0 ) 110 format ( F7. 2 ) c=a+b w r i t e ( 6, ) a w r i t e ( 6, ) b w r i t e ( 6, ) c open ( u n i t =200, f i l e = d a t o s. out ) w r i t e (200, ) c c l o s e ( 2 0 0 ) end program prog

Formato para datos de entrada y salida en fortran sintaxis: write/read (UNIT,FORMAT) variables (UNIT LABEL,FORMAT LABEL) variables label format (format-code) ejemplo: write(*,900) i,x 900 format(i4,f8.3) write/read

A: text string D: double precision numbers, exponent notation E: real numbers, exponent notation F: real numbers, fixed point format I: integer X: horizontal skip (space) /: vertical skip (new line) n FC w.d

Los indices se usan para identificar a un elemento de un arreglo de variables. por ejemplo: Se se define a(1)=10; a(2)=20; a(3)=30 el arreglo es de dimensión 1 x 3. Si queremos multiplicar el arreglo de numeros a por 2, tenemos que hacer: b(1)=2*a(1) b(2)=2*a(2) b(3)=2*a(3) para n datos, la forma general es: b(j) = 2 a(j) para j = 1, 2, 3,..., n.

Cuando se requiere hacer una tarea de forma repetitiva utilizamos un ciclo. para j=1 hasta n TAREA termina En fortran do j=1,n b(j)=2*a(j) enddo En MatLab foro j=1:n b(j)=2*a(j); end

program prog i n t e g e r : : i r e a l : : a, b, c c h a r a c t e r ( 3 0 ) : : head c h a r a c t e r ( 3 0 ) : : b a s u r a open ( u n i t =100, f i l e = e s t a c i o n. dat ) r e a d ( 1 0 0, 1 0 1 ) head r e a d ( 1 0 0, (A) ) b a s u r a r e a d ( 1 0 0, 1 0 2 ) i, a, b c l o s e ( 1 0 0 ) 101 format (A) 102 format ( I1, F5. 1, F6. 2 ) c=a+b w r i t e ( 6, ) w r i t e ( 6, ) head i, a, b, c open ( u n i t =200, f i l e = e s t a c i o n. out ) w r i t e (200, ) d a t o s de s a l i d a w r i t e ( 2 0 0, ( I1, 3 F6. 2 ) ) i, a, b, c c l o s e ( 2 0 0 ) end program prog

program prog i n t e g e r : : i r e a l : : a, b, c c h a r a c t e r ( 3 0 ) : : head c h a r a c t e r ( 3 0 ) : : b a s u r a d i m e n s i o n i ( 5 ), a ( 5 ), b ( 5 ), c ( j ) open ( u n i t =100, f i l e = e s t a c i o n 1. dat ) r e a d ( 1 0 0, 1 0 1 ) head r e a d ( 1 0 0, (A) ) b a s u r a do j =1,5 r e a d ( 1 0 0, 1 0 2 ) i ( j ), a ( j ), b ( j ) enddo c l o s e ( 1 0 0 ) 101 format (A) 102 format ( I1, F5. 1, F6. 2 ) do j =1,5 c ( j )=a ( j )+b ( j ) enddo w r i t e ( 6, ) head do j =1,5 w r i t e ( 6, ( I1, 3 F6. 2 ) ) i ( j ), a ( j ), b ( j ), c ( j ) enddo open ( u n i t =200, f i l e = e s t a c i o n 1. out ) write (200,201) datos de s a li da do j =1,5 w r i t e ( 2 0 0, 2 0 2 ) i ( j ), a ( j ), b ( j ), c ( j ) enddo c l o s e ( 2 0 0 ) 201 format (A) 202 format ( I3, 3 F8. 4 ) end program prog

Ejemplo. Programa para evaluar y graficar una función

program f u n c i o n i n t e g e r : : i, n r e a l, a, b r e a l, d i m e n s i o n ( 1 0 ) : : x, f a =0. e0 b=2. e0 n=10 dx=(b a )/ n x (1)= a f (1)=x 2. e0 do i =1,n x ( i )=a+i dx f ( i )=x 2 w r i t e ( 6, ) x, f enddo end program f u n c i o n

program f u n c i o n p a r a m e t e r ( n=10) i n t e g e r : : i r e a l, a, b r e a l, d i m e n s i o n ( n ) : : x, f a =0. e0 b=2. e0 dx=(b a )/ n x (1)= a f (1)= x ( 1 ) 2. e0 do i =1,n x ( i )=a+i dx f ( i )=x ( i ) 2 enddo open ( u n i t =100, f i l e = f u n c d a t a. dat ) do i =1,n w r i t e ( 1 0 0, 2 0 0 ) x ( i ), f ( i ) enddo c l o s e ( 1 0 0 ) 200 format (2 f 1 6. 4 ) end program f u n c i o n

program f u n c i o n c l e a r a l l p a r a m e t e r ( n=10) i n t e g e r : : i r e a l, a, b r e a l, d i m e n s i o n ( n ) : : x, f a =0. e0 b=2. e0 dx=(b a )/ n load funcdata. dat x=f u n c d a t a ( :, 1 ) ; f=f u n c d a t a ( :, 2 ) ; c l f p l o t ( x, f, o ) x (1)= a f (1)= x ( 1 ) 2. e0 do i =1,n x ( i )=a+i dx f ( i )=x ( i ) 2 enddo open ( u n i t =100, f i l e = f u n c d a t a. dat ) do i =1,n w r i t e ( 1 0 0, 2 0 0 ) x ( i ), f ( i ) enddo c l o s e ( 1 0 0 ) 200 format (2 f 1 6. 4 ) end program f u n c i o n

program f u n c i o n c l e a r a l l p a r a m e t e r ( n=10) i n t e g e r : : i r e a l, a, b r e a l, d i m e n s i o n ( n ) : : x, f a =0. e0 b=2. e0 dx=(b a )/ n x (1)= a f (1)= x ( 1 ) 2. e0 do i =1,n x ( i )=a+i dx f ( i )=x ( i ) 2 enddo open ( u n i t =100, f i l e = f u n c d a t a. dat ) do i =1,n w r i t e ( 1 0 0, 2 0 0 ) x ( i ), f ( i ) enddo c l o s e ( 1 0 0 ) 200 format (2 f 1 6. 4 ) end program f u n c i o n load funcdata. dat x=f u n c d a t a ( :, 1 ) ; f=f u n c d a t a ( :, 2 ) ; c l f p l o t ( x, f, o ) 4 3.5 3 2.5 2 1.5 1 0.5 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2

sub rutinas

programas: principal.f ; subrutina rutina.f compilacion: pgf90 principal.f rutina.f -o principal.out program p r i n c i p a l s u b r o u t i n e r u t i n a ( x, y, z ) r e a l : : a, b a=3 b=4 c a l l r u t i n a ( a, b ) end program p r i n c i p a l r e a l : : x, y, z z=s q r t ( x 2+y 2) w r i t e ( 6, ) r e t u r n end z

compu$ pgf90 principal.f rutina.f -o prin.out principal.f: rutina.f: compu$./prin.out 5.000000

programas: principal.f ; subrutina rutina.f compilacion: pgf90 principal.f rutina.f -o principal.out program p r i n c i p a l s u b r o u t i n e r u t i n a ( x, y, z ) r e a l : : a, b, c a=3 b=4 c a l l r u t i n a ( a, b, c ) c a l l wrt ( c ) end program p r i n c i p a l c s u b r o u t i n e wrt ( v a r ) r e a l : : x, y, z z=s q r t ( x 2+y 2) w r i t e ( 6, ) r e t u r n end z w r i t e ( 6, ) w r i t e ( 6, ) v a r c end

program p r i n c i p a l program p r i n c i p a l p a r a m e t e r ( n=10) r e a l : : a, b, x, f a =0. e0 b=10. e0 dt =(b a )/ n open ( u n i t =100, f i l e = f u n c d a t a 3. dat ) do i =1,n t=t+dt c a l l e v a l ( t, f ) p a r a m e t e r ( n=10) r e a l dt, a, b r e a l, d i m e n s i o n ( n ) : : t, f a =0. e0 b=10. e0 dt =(b a )/ n do i =1,n t ( i )=( i 1) dt c a l l e v a l ( t ( i ), f ( i ) ) w r i t e (1 0 0,2 00) enddo 200 format (2 F11. 4 ) t, f enddo open ( u n i t =100, f i l e = f u n c d a t a 4. dat ) do i =1,n w r i t e ( 1 0 0, 2 0 0 ) t ( i ), f ( i ) enddo c l o s e ( 1 0 0 ) 200 format (2 F11. 4 ) end program p r i n c i p a l C s u b r o u t i n e e v a l ( t, f ) r e a l : : x, f r e t u r n end C f = 9.81 t 2 end program p r i n c i p a l C s u b r o u t i n e e v a l ( t, f ) r e a l : : x, f r e t u r n end C f = 9.81 t 2

archivo de salida funcdata3.dat c l e a r a l l dat=l o a d ( f u n c d a t a 4. dat ) ; 1.0000 9.8100 2.0000 39.2400 3.0000 88.2900 4.0000 156.9600 5.0000 245.2500 6.0000 353.1600 7.0000 480.6900 8.0000 627.8400 9.0000 794.6100 10.0000 981.0001 t=dat ( :, 1 ) ; f=dat ( :, 2 ) ; c l f p l o t ( t, f,. k, MarkerSize, 2 0, L i n e w i d t h, 2 ) t i t l e ( c a i d a l i b r e, FontSize, 1 8 ) x l a b e l ( tiempo [ s eg ], FontSize, 1 8 ) y l a b e l ( d i s t a n c i a [m], FontSize, 1 8 ) s e t ( gca, FontSize, 1 8 ) g r i d on p r i n t depsc p r i n c i p a l 4

0 caida libre 100 200 distancia [m] 300 400 500 600 700 800 0 2 4 6 8 10 tiempo [seg]