Example 1
A small object is launched into flight from the ground at a speed of 50
miles/hour at 30 degrees above the horizontal over level ground. Determine the time of flight (in seconds) and the distance traveled (in feet)
when the ball returns to the
Lab 7 Exercises
1.
function [root,iter] = Lab7Q1(x,es)
root = 0;
iter = 0;
while (1)
root_old = root;
root = root + (-1)^iter * (x^(2*iter + 1)/factorial(2*iter + 1);
ea = abs(root-root_old)/root)*100;
iter = iter + 1;
if ea <= es
break
end
end
fprintf('s
ChE 121 Spring 2006 Final
Problem 1
Assume the code block below is within a properly named and error free function. What is printed
when the code block is run?
A = [1 2 3; 4 5 6; 7 8 9];
B = ones(3,3) * 2;
sizeA = size(A);
for pacific = 1:sizeA(1)
for atl
ChE 121 - Practice Problems:
Problem 1
Assume the code block below is within a properly named and error free function. What is printed
when the code block is run?
A = [1 2 3; 4 5 6; 7 8 9];
B = ones(3,3) * 2;
sizeA = size(A);
for pacific = 1:sizeA(1)
for
ChE 121 - Engineering Computation
Lecture 8 - Plotting
1
Two Dimensional Plotting
Learning Objectives
Understand the
anatomy of a 2D plot
How to choose
different plot types for
best effects
2
Topics
Construction of 2D
plots using plot()
Modification a
ChE121
Engineering Computation
Computer Components
1
Learning Objectives
To know the basic components of a computer
and justify the reason behind choosing MATLAB
for
solving
mathematical
models
(i.e.
engineering problems).
2
What is a computer?
3
Computer
CHE 121
Engineering Computation
Algorithms, Flowcharts, Psuedocode
1
Computation Problems
This type of problem will present you with some data
and ask you to compute some result(s).
With simple problems, you may be able to find the
solution directly.
W
Practise Midterm Exam
1. Write the output for the following Matlab command.
> a = [1 2 3];
> b = [2 3 4];
> a * b
The following two questions refer to the matrix given below:
1
K = 2
3
4
5
6
7
8
9
10
11
12
2. Write a single Matlab command to create the ma
ChE121
Engineering Computation
Lecture 4
Matrices and Algebraic Equations
1
Topics
Matrices
Colon Operator
Matrix Operation
Matrix Manipulation In Matlab
Linear Algebraic Equation in Matrix Form
2
Introduction
Linear algebra is at the heart of numer
ChE121
Engineering Computation
Lecture 5
Format, Strings, Predefined
MATLAB functions
1
Topics
Format
Strings
MATLAB predefine functions
2
Format
Output Format:
format options (controls how numeric output is displayed)
Examples- three of the options ar
ChE121
Engineering Computation
MATLAB Script files and
Function files
1
Topics
Script files
Input/Output commands (disp, input, pause, fprintf)
Function files (definition, inline/anonymous functions,
local and global variables)
2
MATLAB Script files
In
ChE 121/CIVE 121 Final Exam Practice Problems:
Problem 1
Assume the code block below is within a properly named and error free function. What is printed
when the code block is run?
A = [1 2 3; 4 5 6; 7 8 9];
B = ones(3,3) * 2;
sizeA = size(A);
for pacific
Array Operations
Using MATLAB as a glorified calculator is OK, but its real strength is in
matrix manipulations
To create a row vector, enclose a list of value in brackets
You may use either a space or a comma as a delimiter in a row
vector
Use a semicol
Why MATLAB?
1) Ease of use
2) Widely used in industry
3) Interpreted language (write, debug, run in same environment)
4) Editor can pass code directly to MATLAB application
5) Graphical interface (2-D, 3-D)
6) Numerical Analysis + toolboxes
7) The program
Saving Your Work
If you save a MATLAB session performed in the command window, all
that is saved are the values of the variables you have named
Variables are saved, not the commands in the command window
Save either by using the file menu or.
Save with a
What is MATLAB?
MATLAB is one of a number of commercially available, sophisticated
mathematical computation tools
Others include
Maple
Mathematica
MathCad
MATLAB excels at:
Numerical calculations
Especially involving matrices
Graphics
MATLAB stan
Figure Window
When Figures are created a new window opens
Its extremely easy to create graphs in
First create a vector of x values then a corresponding vector of
y values
Note: The semicolon suppresses the output from each command
Matlab makes it easy t
MATLAB opens to a default window configuration
MATLAB uses a standard windows menu bar
To exit MATLAB use the close icon
MATLAB Windows
MATLAB uses several different windows to display data, commands and
results.
They are not necessarily all open at o
Number Display
Scientific Notation Although you can enter any number in decimal
notation, it isnt always the best way to represent very large or very small
numbers
In MATLAB, values in scientific notation are designated with an e between the decimal num
Matrices in MATLAB
The basic data type
Group of numbers arranged into rows and columns
Single Value (Scalar) Matrix with one row and one column
Vector (One dimensional matrix) One row or one column
Matrix (Two dimensional)
Scalar Calculations
You can
Mixed calculations between scalars and arrays
Matrices can be used in many calculations with scalars
There is no confusion when we perform addition and subtraction
Multiplication and division are a little different
In matrix mathematics the multiplica
1. i)
function output=nlinear(x,x1,x2,fx1,fx2);
output=fx1+(fx2-fx1)/(x2-x1)*(x-x1);
> nlinear(6,4,8,0.60206,0.90309)
ans =
0.7526
function output=lalinear(x,x1,x2,fx1,fx2);
output=(x-x2)/(x1-x2)*(fx1)+(x-x1)/(x2-x1)*(fx2);
> lalinear(6,4,8,0.60206,0.9030
Lab 6
1.
function x= q1(a,b,c,d,m,n);
if(a*d-b*c)=0
error('The matrix of coefficient is singular')
else
x=[(m*d-b*n)/(a*d-c*b) (n*a-m*c)/(a*d-c*b)]
end
> q1(2,8,3,-3,3,7)
ans =
2.1667 -0.1667
> q1(3,6,1,2,6,3)
Error using q1 (line 3)
The matrix of coeffic
1.
function[root, ea, iter]= newtraph(func,dfunc,xr,es,maxiter)
if nargin<3
error('at least three arguments required')
end
if nargin<4 | isempty(es)
es=0.001;
end
if nargin<5 | isempty (maxiter)
maxiter=50;
end
iter=0;
while (1)
xrold=xr;
xr=xr-(func(xr)/
ChE121
Engineering Computation
Introduction to Matlab
1
Introduction to Matlab
2
Learning
Objectives
Outline
Discover how
Matlab is designed
and what the basic
components do.
Matlab processor
Basic language syntax
Numbers in Matlab
Matlab Desktop
Arithmet