VBA Macros for Solving Problems in Water Chemistry Chad Jafvert Purdue University The Educational Objectives of the Tools: Students will: Design and create.

Slides:



Advertisements
Similar presentations
Intro to modeling April Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.
Advertisements

All rights reserved. Copyright G. Peifer 1 Using Computer Spreadsheets to Solve Equations 1.Log into the Network and open Microsoft Excel. 2.Finding.
Information literacy B Lecture 4 Database and Spreadsheet Takeshi Tokuyama Tohoku University Graduate School of Information Sciences System Information.
ELECTRONIC SPREADSHEATS ELECTRONIC SPREADSHEATS Chapter 14 Dr. Bahaa Al-Sheikh & Eng. Mohammed AlSumady Intoduction to Engineering BME152.
ROOTS OF EQUATIONS Student Notes ENGR 351 Numerical Methods for Engineers Southern Illinois University Carbondale College of Engineering Dr. L.R. Chevalier.
Flow Charts, Loop Structures
MATLAB Presented By: Nathalie Tacconi Presented By: Nathalie Tacconi Originally Prepared By: Sheridan Saint-Michel Originally Prepared By: Sheridan Saint-Michel.
Excel for complex calculations Week 2 John Cubbin City University.
Solving Engineering Problems by Using Computer A Case Study on Fed-Batch Bioreactor.
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 4 Programming and Software EXCEL and MathCAD.
CIS101 Introduction to Computing Week 05. Agenda Your questions Exam next week - Excel Introduction to the Internet & HTML Online HTML Resources Using.
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 20 Solution of Linear System of Equations - Iterative Methods.
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 19 Solution of Linear System of Equations - Iterative Methods.
CHE/ME 109 Heat Transfer in Electronics LECTURE 11 – ONE DIMENSIONAL NUMERICAL MODELS.
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 3 Programming and Software.
Lecture Notes Dr. Rakhmad Arief Siregar Universiti Malaysia Perlis
Professor Walter W. Olson Department of Mechanical, Industrial and Manufacturing Engineering University of Toledo Solving ODE.
CMPSC 200 Spring 2013 Lecture 38 November 18 or 20, 2013 (depending on section)
Spreadsheets and Microsoft Excel. Introduction n A spreadsheet (called a worksheet in Excel) is a two-dimensional array of cells containing data to be.
1 CS101 Introduction to Computing Lecture 22 Spreadsheets.
Foundation Programming Introduction. Aims This course aims to give students a basic understanding of computer programming. On completing this course students.
ME 142 Engineering Computation I Variables, Equations & Functions Introduction to Basic Programming Language.
Introduction to Engineering Computing GEEN 1300 Lecture 7 15 June 2010 Review for midterm.
OpenOffice.org Alternative to Microsoft Office. 06/24/10 Steve Costello - BRCS2 What is OpenOffice.org?  Suite of Programs  Word Processor - Writer.
Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.
Chapter 3 PART 2 - SPREADSHEET CMPF 112 : COMPUTING SKILLS CALC FOR LINUX.
Chapter 1 Computing Tools Analytic and Algorithmic Solutions Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Middle Eastern Women 2005 Optional Business Computer Skills Review Paula Ecklund.
Ms. Abeera Arif Gulshan Jn. G, Level V, All Sections (11) August 2010 to May 2011.
Class 3 Programming in Visual Basic. Class Objectives Learn about input/output Learn about strings Learn about subroutines Learn about arrays Learn about.
Lecture Notes Dr. Rakhmad Arief Siregar Universiti Malaysia Perlis
Start Presentation October 4, 2012 Solution of Non-linear Equation Systems In this lecture, we shall look at the mixed symbolic and numerical solution.
Math 15 Lecture 10 University of California, Merced Scilab Programming – No. 1.
Chapter 11 An Introduction to Visual Basic 2008 Why Windows and Why Visual Basic How You Develop a Visual Basic Application The Different Versions of Visual.
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (1): Introduction.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Chapter 2.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 ~ Roots of Equations ~ Open Methods Chapter 6 Credit:
Using Spreadsheets In Analytical Chemistry Chap 3. Using Spreadsheets in Analytical Chemistry (1) Getting started : Excel (2) The basic usage  basic usage.
30S Applied Math Mr. Knight – Killarney School Slide 1 Unit: Solving Systems Algebraically Lesson: SLE-L3 Using Spreadsheet Analysis to Solve Linear Systems.
Solution of a System of ODEs with POLYMATH and MATLAB, Boundary Value Iterations with MATLAB For a system of n simultaneous first-order ODEs: where x is.
Chapter 3 MATLAB Fundamentals Introduction to MATLAB Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Chapter 1 Computing Tools Analytic and Algorithmic Solutions Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Numerical Solution of the Diffusivity Equation. FAQReferencesSummaryInfo Learning Objectives Introduction Discrete Systems Taylor Series Approximation.
ME 142 Engineering Computation I Exam 2 Review VBA.
Lecture 1: Matlab Universe
Numerical Analysis Intro to Scientific Computing.
Constructing student knowledge of mass transport through interpretation of field data x Jodi Ryder Central Michigan University vs x.
The Bisection Method. Introduction Bisection Method: Bisection Method = a numerical method in Mathematics to find a root of a given function.
Newton’s Method, Root Finding with MATLAB and Excel
Lecture 6 - Single Variable Problems & Systems of Equations CVEN 302 June 14, 2002.
An Introduction to Computational Fluids Dynamics Prapared by: Chudasama Gulambhai H ( ) Azhar Damani ( ) Dave Aman ( )
Online + Math + Solvers = (Happy Students)2 online math problem solver.
Chapter 1 Computing Tools Variables, Scalars, and Arrays Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
SpreadsheetsDatabase Technology Terms Desktop Publishing Word Processing Web Designs Technology.
Lesson 9-2 Direction (Slope) Fields and Euler’s Method.
DYNAMIC BEHAVIOR OF PROCESSES :
Computational Fluid Dynamics Lecture II Numerical Methods and Criteria for CFD Dr. Ugur GUVEN Professor of Aerospace Engineering.
Challenges with simultaneous equilibrium Speciation programs (MINEQL)
Process and System Characterization Describe and characterize transport and transformation phenomena based reactor dynamics ( 반응공학 ) – natural and engineered.
CS101 Introduction to Computing Lecture 22 Spreadsheets
244-1: INTRODUCTION TO PROGRAMMING
Algorithms and Programming
Non-linear Minimization
Using Spreadsheets In Analytical Chemistry
Objective Numerical methods.
Introduction to pseudocode
Objective Numerical methods Finite volume.
Excel Charts and Functions
Chapter 1 Introduction(1.1)
Solving Equations 3x+7 –7 13 –7 =.
Presentation transcript:

VBA Macros for Solving Problems in Water Chemistry Chad Jafvert Purdue University The Educational Objectives of the Tools: Students will: Design and create VBA Macros (i.e., programs) that solve analytical and numerical problems in aquatic chemistry and related fields. (Levels 5 (Synthesis) & 3 (Application) in Bloom’s Taxonomy of Educational Objectives) This computer-based learning tool consists of the instructions and example programs that students can apply and mimic in designing their own solution algorithms. The Ingredients: Excel (Microsoft Office) loaded on any PC

Development Time: ? Development Time (for students): 1 to 2 50-min lectures to convey the tools to the students, 5 min to 40 hrs for students to write a successful VBA macro. Educational Outcomes: The computer skills, program language backgrounds, and programming phobias of students entering graduate environmental engineering and science programs are wide- ranging, yet these students always have in common the ability to perform mathematical operations in spreadsheets like Excel. With very little additional instruction, they are using VBA in Excel as a programming language and solving rather complex mathematical problems with software they are comfortable with, that is ubiquitous in nature (including on their own PCs), and that has immediate graphical output.

Downloads (demos): Instructions: An Acrobat file contains the instructions for writing VBA macros in Excel and further explanations on each of the sample spreadsheets below. (15 pages) Introduction to VBA.xls: An Excel spreadsheet that contains an example VBA macro that shows how to: (i) dimension variables and arrays, (ii) write 'For... Next‘ loops, (iii) read and write to the spreadsheet, (iv) format common mathematical expressions, (v) etc. Functions.xls: A simple spreadsheet than contains some user-defined functions (volume of a cylinder, roots to the quadratic equation, and the sin of an angle measured in degrees). pKa.xls: A spreadsheet that calculates buffer composition and draws the pC-pH diagram of a simple acid. Web Address where Instructions and Examples can be Downloaded:

Downloads (cont.) Case 3 p60 in Morel & Hering.xls: A spreadsheet that solves a system of three equations and three unknowns by Newton-Raphson iterations. The 'recipe' for the problem is the same as 'Case 3' on page in the text "Principles and Applications of Aquatic Chemistry" by Morel and Hering. Stratified Lake.xls: A spreadsheet that solves a system of 2 simultaneous ODE's with Euler's method. The example case is the transport of TCE in a stratified lake - presented on pages in "Environmental Organic Chemistry" by Schwarzenbach, et al. The 2 ODE's are eqs 15-30a and 15-30b (p. 569) in the text. 1D Diffusion.xls: The central difference solution to the 1-D diffusion equation with an impulse input at the center of the media. The numerical solution is calculated with a VBA macro and is compared to the analytical solution calculated directly on the spreadsheet. A second macro calculates the mass under the concentration profile with Simpson's Method.

A Very Simple Example VBA program that reads and writes: In Excel, Type ‘3’ in cell B4, then click on ‘Tools’, ‘Macro’, ‘Macros’. Provide a name for your macro, click on ‘create’ Type the following lines and click on ‘Run’, ‘Run Sub’:

By finding the roots with the Newton-Raphson method: Now you are ready to solve 3 simultaneous equations: Next, replace the old guesses with the new guesses with a simple ‘read and write’ VBA program. Repeat (iterate) until the problem converges. First, solve for the functions and the partial derivatives with initial guesses, invert the matrix, and do the math to solve for the new guesses, all on the spreadsheet.