Docsity

ME 2004: Assignment 1 - Numerical Methods with MATLAB - Prof. Brian Vick, Assignments of Mechanical Engineering

Toggle sidebar
bg1
Fall 2007
ME 2004: Assignment 1
Solve problems 2.1, 2.3, 2.13, and 2.17 from “Numerical Methods with MATLAB” by Gerald
Recktenwald.
Problem 2.1
The objective is to use the ‘lookfor’ command to discover how to find the maximum value in a
matrix.
Matlab Script File
The following script m-file was created for this problem.
% "Numerical Methods with MatLab", Gerald Recktenwald
% Problem 2.1
A = [ 1 -5 -2 ; 3 4 -9 ; -7 2 6 ]
B = sin(A)
Amax = max(max(A))
Bmax = max(max(B))
MATLAB Output
>> lookfor max
>> Pr_2_1
A =
1 -5 -2
3 4 -9
-7 2 6
B =
0.8415 0.9589 -0.9093
0.1411 -0.7568 -0.4121
-0.6570 0.9093 -0.2794
Amax =
6
Bmax =
0.9589
Note that the ‘lookfor max’ found a large number of files on my computer and I did not
print them all out.
1
pf3

Partial preview of the text

Download ME 2004: Assignment 1 - Numerical Methods with MATLAB - Prof. Brian Vick and more Assignments Mechanical Engineering in PDF only on Docsity!

Fall 2007

ME 2004: Assignment 1

Solve problems 2.1, 2.3, 2.13, and 2.17 from “ Numerical Methods with MATLAB” by Gerald Recktenwald.

Problem 2.

The objective is to use the ‘lookfor’ command to discover how to find the maximum value in a matrix. Matlab Script File The following script m-file was created for this problem. % "Numerical Methods with MatLab", Gerald Recktenwald % Problem 2. A = [ 1 -5 -2 ; 3 4 -9 ; -7 2 6 ] B = sin(A) Amax = max(max(A)) Bmax = max(max(B)) MATLAB Output

lookfor max Pr_2_ A = 1 -5 - 3 4 - -7 2 6 B = 0.8415 0.9589 -0. 0.1411 -0.7568 -0. -0.6570 0.9093 -0. Amax = 6 Bmax =

Note that the ‘lookfor max’ found a large number of files on my computer and I did not print them all out.

Chapter 2, Problem 3

The objective is to use the colon notation to create vectors identical to ones created using ‘linspace’ and ‘logspace’. (a)

x = linspace(0,10,5) x = 0 2.5000 5.0000 7.5000 10. y = 0:2.5: y = 0 2.5000 5.0000 7.5000 10. norm(x-y) ans = 0 (b) x = linspace(-5,5); y = -5:10/99:5; norm(x-y) ans = 3.2935e- (c) x = logspace(1,3,3) x = 10 100 1000 p = 1: p = 1 2 3 y = 10.^p y = 10 100 1000 norm(x-y) ans = 0 (d) x = logspace(1,3,5); p = 1:0.5:3; y = 10.^p; norm(x-y) ans = 0