This page gives recommendations for setting up MATLAB to use the finite-difference and finite-volume codes for the course. The main goals are to create a library folder for storing the codes after downloading them, and setting up MATLAB so that code library is always included in the search path.
As a result of working with MATLAB in the first weeks of the class you should be able to
In this tutorial, we will work with one set of the course codes – the finite-difference schemes for solving the 1D heat equation. You will repeat these steps for the other sets of course codes. I strongly recommend that you store each set in a separate folder. For now, just follow the steps for the one set of codes.
Download mfiles for the 1D Heat Equation Models:
home\class\ME448\mfiles
__MACOSX
folder. It contains metadata for the Macintosh OS, which was used to create the zip archive.heat1D
folder. Using this shorter name is convenient, but not necessary.homework
, for storing files that you create.The goal is to create a library of files that you don’t change, and also create at least one folder of files that you create for homework or research.
Click Add with Subfolders …
Navigate to the folder you created for storing mfiles. Click Select Folder.
Click Save to save the path
If you are working on the computers in the CECS network (e.g. in the EB 420 lab), MATLAB will give you an error message because you don’t have permission to save the pathdef.m
in the directory used by the system-wide MATLAB installation.
NOTE: You will not see this error if you are working on a computer where you have administrator privileges. For example, if you are using a student version of MATLAB installed on your personal computer, and if you are logged onto an account that allows you to install software, you will not see this error message.
Don’t panic. Click Yes. Save the pathdef.m
file in your local MATLAB folder, i.e. in \Documents\MATLAB
.
Now that the pathdef.m
file is saved, you can close the Path Tool
I recommend that you create other folders for MATLAB codes that you create. For example, a homework
folder (or folders, one for each assignment) can store mfiles created for homework assignments. Another folder, practice
could store temporary mfiles used to explore new ideas or follow along on tutorials.
The preceding steps have completed two main tasks. First, you created a folder in your account where the heat1D
mfiles are stored. These mfiles are MATLAB functions that implement three different schemes for solving the one-dimensional heat equation. We will work with these codes for the first two weeks of the course.
The second main task was to configure MATLAB so that the files in the heat1D
folder will always be available when you run MATLAB. The “always available” means that the heat1D
folder is always in your MATLAB path, no matter what other folder you happen to be running MATLAB in.
In computer programming terms, the heat1D
codes are a library that you use without changing the contents. To take advantage of this setup, you should never (or rarely ever) change the functions in the heat1D
folder. Instead, you write your own MATLAB functions that use the functions in the heat1D
folder.
I strongly recommend that you create separate folders for each set of mfiles I have provided in the course. Those mfiles sets include almost 90 files and are organized into four groups
heat1D
– numerical solutions to the one-dimensional heat equationconvection1D
– numerical solution to the one-dimensional advection-diffusion equationpipeflow1D
– finite volume solution to fully-developed flow in a pipeCVFD2D
– codes implementing the finite volume method on a 2D cartesian meshEach time you download one of the zip archives, create a new folder (in your \class\ME448\mfiles
folder) for the files in that zip archive.
Furthermore, create a separate folder (or more!) for your own homework and post-processing codes.