Introduction to Programming and Computation for Engineers
BE 1500

Fall 2013
1A) Script:
v=textread('code_letters.txt',''); %inputs a file, breaks it up at every
space, and names it with the variable v.
m=length(v); %this is finding the length of v, or how many words are in v
Introduction to Programming and Computation for Engineers
BE 1500

Fall 2013
Ali Rajab
BE1500
While Loops
A while loop will continue to be repeated until some condition is satisfied.
Example: Consider an amount of money deposited in an interestbearing account. If we want to
d
Introduction to Programming and Computation for Engineers
BE 1500

Fall 2013
BE 1500 Homework #3
Submit this assignment as a PDF to the link on Blackboard
Copy and paste your MATLAB commands and final answers for each problem into a word document. For
excel portions, copy the
Introduction to Programming and Computation for Engineers
BE 1500

Fall 2013
BE 1500 Quiz 1
Submit this assignment as a PDF to the link on Blackboard
Copy and paste your MATLAB commands and final answers for each problem into a word document.
Introduction to Programming and Computation for Engineers
BE 1500

Fall 2013
BE 1500091 Homework #5
Zip your submission files into a compressed folder. Your folder should contain the necessary
script files (.m files) and figure files as (.jpg) file types to answer the questio
Introduction to Programming and Computation for Engineers
BE 1500

Fall 2013
BE 1500 Lecture 4 and 5 Exercises
1. Plot the following time and acceleration data on one graph. Remember to include a title, axes
labels, and a properly labeled legend. Model a1 as a solid red line,
Introduction to Programming and Computation for Engineers
BE 1500

Fall 2013
Matrix Element Search
function matrixElementSearch(elementSearch, matrixTest)
%MatrixElementSearch.m: Function that searches for an element
%'elementSearch', in the inputted matrix, 'matrixTest'.
[num
Introduction to Programming and Computation for Engineers
BE 1500

Fall 2013
BE 1500 Lecture 4 Exercises
1. Plot the following time and acceleration data on one graph. Remember to include a title, axes
labels, and a properly labeled legend. Model a1 as a solid red line, a2 as
Introduction to Programming and Computation for Engineers
BE 1500

Fall 2013
Lecture 7 Exercises Using Function Files and Scripts
1. The figure below is a diagram of the cross section of an irrigation channel. The crosssectional area of the channel should be 100 ft2 to carry t
Introduction to Programming and Computation for Engineers
BE 1500

Fall 2013
> clear
A = 2;
while A < 10
A = 2*A;
end
A
A=
16
%Exercise_2
A = 2;
i=0
while A < 10
i=i+1;
A = 2*A;
end
A
i
i =
0
A =
16
i =
3
%Exercise_3_a
i=0;
A= 2;
while A <= 32
i=i+1;
A = 2*A;
end
A
A =
64
%Exe
Introduction to Programming and Computation for Engineers
BE 1500

Fall 2013
BE 1500:091 Homework 2
Copy and paste your MATLAB commands and final answers into a Word document for each problem.
Upload the assignment to Blackboard by September 19th before class.
1. Use MATLAB to
Introduction to Programming and Computation for Engineers
BE 1500

Fall 2013
BE 1500091 Homework 4
Submit a zipped folder (compressed folder) containing .m files for each of the following problems. The
folder should be named with the format accessID_BE1500_HW4. Remember, if y
Introduction to Programming and Computation for Engineers
BE 1500

Fall 2013
BE 1500 Lecture 3 Exercises
1. Without typing the following commands into MATLAB, determine what the output would be. Then
check your answers.
a. >a=1:2:9
b. >b=13:2:28
c. >c=linspace(13,28,8)
d. >d=l
Introduction to Programming and Computation for Engineers
BE 1500

Fall 2013
%Exercise_1a
format short
a = 4*5*cos(pi/3)(log(1.24)^(1/3)*tan(pi/3)
%Exercise_1b
b = (2*tand(30)^2)/15)(log10(14)*(exp(1/8)/12)(25/
(12+sind(30)
%Exercise_2
format long
c1 = 17^(1/2)
c2 = sqrt(17
Introduction to Programming and Computation for Engineers
BE 1500

Fall 2013
BE 1500 Lecture 2, Exercises
1. Type the following equation into MATLAB:
=
2
6 19
4 + 5
3
7 11
2. The following equation is typed into MATLAB:
= 3
25 16
3
+
7 22
3
19
13
The following are two M
Introduction to Programming and Computation for Engineers
BE 1500

Fall 2013
BE 1500091 Homework 3
1. Plot the following data. Remember, two plots on the same graph need to be represented differently
(suggestions are given below); you need a graph title, axes labels, and a pr
Introduction to Programming and Computation for Engineers
BE 1500

Fall 2013
BE 1500 Fall 2016
HW 4
Due: 9/29/16 (1:30 P.M.)
1. Write a function file that determines the following sum (for all odd n from 1 to 11) using a for
loop. The starting point, ending point, and incremen
Introduction to Programming and Computation for Engineers
BE 1500

Fall 2013
BE 1500 Fall 2016
Homework 1
Solutions
1.
Solution
> format short
> a=4*5*cos(pi/3)(log(1.24)^(1/3)*tan(pi/3)
a = 8.9622
1/2
2. Solution
> b=(2*tand(30)^2/15log10(14)*exp(1/8)/1225/(12+sind(30)
b =
Introduction to Programming and Computation for Engineers
BE 1500

Fall 2013
BE 1500 Fall 2016
Quiz 5
1. Write a script that produces the following output. The script should iterate from 1 to 9 to
produce the expressions on the left, perform the operation to get the results sh
Introduction to Programming and Computation for Engineers
BE 1500

Fall 2013
1. The nth Fibonacci number is defined by the following recursive equations:
f(1) = 1
f(2) = 2
f(n) = f(n1) + f(n2)
Therefore, f(3)=f(2)+f(1)=2+1=3, and so forth for higher numbers. Write a function
Introduction to Programming and Computation for Engineers
BE 1500

Fall 2013
BE 1500 Fall 2016
HW 5
Due: October 13, 2016 (1:30 P.M.)
1. Write a code for repmat; the only builtin commands you are allowed to use are input, size, and
disp.
A=input('matrix ');
[m,n]=size(A);
z=i