PGE 310 Exercise 7: While loops
While loops are another basic structure used to control the flow of operations within a MATLAB algorithm. For loops,
while loops, and if statements can be used in conjunction to handle most of the programming needed for eng

PGE 310 Exercise 1: Introduction to Vectors and Matrices in MATLAB
Material adapted from Meegan, et al., 2011
MATLAB variables can hold more than just a single value. A single variable name can be used to
represent a vector (list of values). A single vari

The University of Texas at Austin
Spring 2013 - PGE 310: Formulation and Solution in Geosystems Engineering
Project #1 (50 points): Root Finding
Due Date: Friday, March 8th 2013
Petroleum Engineering Application: Flash Calculations
In reservoir simulation

Exercise 8: User-defined functions in MATLAB
MATLAB has a lot of built-in functions (sin, cos, exp, log, and hundreds more), but sometimes you need to
repeatedly evaluate a function that is not built-in, or repeat a particular process (like Newton's Metho

PGE 310 Exercise 6: Nested for loops and conditional statements
This exercise continues where exercise 4 left off, expanding on the use of for loops, and introducing
conditional statements (if statements). By the way, for loops are a type of what we call

MATLAB for M151B
c 2008 Peter Howard
1
MATLAB for M151B
P. Howard
Fall 2008
Contents
1 Introduction
1.1 The Origin of MATLAB . . . . . . . . . . . .
1.2 Our Course Goal . . . . . . . . . . . . . . . .
1.3 Starting MATLAB at Texas A&M University
1.4 The MA

Exercise 2: More Matrix and Vector Operations, Basic Plotting
In the last exercise, you learned how to create vectors and matrices, and some techniques for using
vectors and matrices in computations, and for referencing individual elements and subsets of

More Midterm Exam Review Problems
1
Describe what the following function does. In doing so, define each of the input and output
variables, and give a line-by-line description of the code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function [fx,ea,iter] = Iter

PGE 310 Exercise 4: Intro to Programming in MATLAB
This exercise walks you through some of the building blocks of programming in MATLAB: creating script
files, and writing and using for loops.
Review exercises
Problem 1: Let x = [2 5 1 6]. Write the comma

1
Write a MATLAB function called Means that computes the arithmetic and geometric mean of an
input vector (list of values). The input for the function is one variable, the list of values (a
vector), and the two outputs are the arithmetic and geometric mea

PGE 310 Exercise 3: More on Plots in MATLAB
In exercise 2 you learned to make a basic plot in MATLAB using the plot function. This exercise reviews
some of the other plotting commands available in MATLAB, and also describes some of the commands
available

Exercise 10: Other methods for data import in MATLAB
MATLAB supports reading from and writing to Excel files using the xlsread and xlswrite
functions. There is also a data import function called importdata that can be useful. This exercise
demonstrates ho

Exercise 9: Data and file input in MATLAB
There are many ways to provide data to MATLAB operations and files. The most direct method is to
simply define variables in a script file or in the command window. You have also already learned about
the input fun

Problem A (modified from Chapra Problem 3.5)
The sine function can be approximated with the following infinite series
x3 x5
sin x= x +
3! 5 !
Create a script file to implement this formula so that it plots the value of sin x and the relative error as a f

Exercise 5: 3D Plots and Related Functions
MATLAB is capable of producing very high quality 3D surface plots. This module describes some of the
basics of creating and modifying 3D plots. Many of the concepts that applied to 2D plots are still valid,
such

PGE 310 Quiz 2
Name:_
EID:_
Problem 1 (5 points)
Consider the following set of commands:
n = 5;
while n > 0
fprintf('The value of n is %i \n',n)
n = n - 1;
end
Complete the following table to describe what happens during this loop. The number of rows in t