# Transitioning from Excel to MATLAB Diffusion Models

## Summary

This activity is part of a larger module that introduces students to two different ways to model chemical diffusion in minerals: 1) 1D diffusion in Excel using finite differences and 2) 1D diffusion in MATLAB using the same equations. It is designed to help students apply diffusion equations derived previously in class to understand natural zonation of elements in minerals. The students build the model first in Excel, and then in MATLAB to obtain the timescales of diffusive re-equilibration related to magma storage and transport at KÄ«lauea Volcano, Hawai'i. The major goals are to help students transition from visual platforms (e.g., Excel) to writing computer code (e.g., in MATLAB), implementing for loops for iterative calculations, and thinking about how the geologic parameters (temperature, pressure, fO2) affect the model results.

## Learning Goals

Upon completion of this assignment students should:

- have the ability to transfer work from a visual-based program (Excel) to a computational program (MATLAB)

- regularly comment their code to describe the purpose of each line or each section and the relevant references for given values (T, P, fO2, diffusion coefficients)

- be able to implement a for loop to run calculations that iterate through time (e.g., time steps)

- be able to quantify the effects of variations in the geological parameters implemented in the model (e.g., temperature, crystal orientation) on the retrieved timescale

## Context for Use

I use this activity in a course for graduate and upper level undergraduate students focused on applying diffusion kinetics to geochemical zoning in minerals. The activity is part of a series of tasks assigned to students that gradually advance their modeling from 1D modeling in Excel to 3D models built in MATLAB.

Students should have some background in igneous and metamorphic petrology/geochemistry, and some familiarity with the basics of MATLAB. Earlier in this course I provide a lab session "Intro to MATLAB Crash Course" to introduce basic functions and program features. I use this activity around weeks 4-5 as the first model development for fitting natural data. A key skill introduced in this exercise is the implementation of a for loop for iterative calculations.

## Description and Teaching Materials

This activity is self-contained within the guided assignment and the provided analytical data. Students must have computers with Excel and MATLAB programs.

x.mat (Matlab .MAT File 260bytes Nov6 19)

Fo_initial.mat (Matlab .MAT File 205bytes Nov6 19)

x_EPMA.mat (Matlab .MAT File 224bytes Nov6 19)

Fo_EPMA.mat (Matlab .MAT File 444bytes Nov6 19)

DiffusionPractical_Data.xlsx (Excel 2007 (.xlsx) 368kB Aug9 19)

Student Handout for Diffusion Practical (Microsoft Word 25kB Oct14 19)

Instructor Example Script (Matlab File 2kB Nov6 19)

AssessmentRubric.docx (Microsoft Word 2007 (.docx) 13kB Nov6 19)

## Teaching Notes and Tips

Throughout this exercise, it is useful for the instructor to show small sections of code on the projector, especially if several groups of students are struggling with how to implement the equations. As an example, for loops can be a challenge if students have not used them before.

## Assessment

The students will be graded based on their completed MATLAB code, detail of comments describing each line of code (including literature references for input values), and their thoughtfulness of short answer questions. A basic rubric is attached to guide grading but other assessments of student progress can be used.

## References and Resources

Useful references, which are included in the assignment materials, include:

References:

Crank, J. (1975). The Mathematics of Diffusion, 2nd ed. Oxford Science Publications, Oxford.

Dohmen, R. and Chakraborty, S. (2007a). Fe-Mg diffusion in olivine II: point defect chemistry, change of diffusion mechanisms and a model for calculation of diffusion coefficients in natural olivine. Physics and Chemistry of Minerals, 34, 409-430. doi: 10.1007/s00269-007-0158-6.

Dohmen, R., and Chakraborty, S. (2007b). Erratum to: Fe-Mg diffusion in olivine II: point defect chemistry, change of diffusion mechanisms and a model for calculation of diffusion coefficients in natural olivine. Physics and Chemistry of Minerals, 34, 597-598. doi: 10.1007/s00269-007-0185-3.

Helz, R., and Thornber, T. (1987) Geothermometry of Kilauea Iki lava lake, Hawaii. Bulletin of Volcanology, 49, 651-668. doi: 10.1007/BF01080357.

Lynn, K.J., Garcia, M.O., Shea, T., Costa, F., and Swanson, D.A. (2017). Timescales of mixing and storage for KeanakÄko'i Tephra magmas (1500-1820 C.E.), KÄ«lauea Volcano, Hawai'i. Contributions to Mineralogy and Petrology, 172, 76. doi: 10.1007/s00410-017-1395-4.