Introduction to Engineering MATLAB – 7 Script Files - 2 Agenda Script files continued.
-
Upload
easter-curtis -
Category
Documents
-
view
219 -
download
1
Transcript of Introduction to Engineering MATLAB – 7 Script Files - 2 Agenda Script files continued.
Introduction to EngineeringMATLAB – 7Script Files - 2
Agenda Script files continued
EXAMPLE
Write a script file that determines the balance in a saving account at
the end of every year for the first 10 years. Initial investment of
$1,000 and interest rate of 6.5% compounded annually.
Display the information in a table.
For an initial investment of A, and interest rate of r, the balance B
after n years is given by:
nrAB 1
format bank
yr = [1:10];
% Creating a vector of year numbers.
balance = 1000*1.065.^yr;
% Creating a vector of the balance.
table_yr_blnc(:,1)=yr';
% Substituting the yr vector in the first column of the table matrix.
table_yr_blnc(:,2)=balance';
% Substituting the balance vector in the second column of the table matrix.
disp(' YEAR ACCOUNT') % Display titles.
disp(' BALANCE ($)') % Display titles.
disp(' ') % Display an empty line.
disp(table_yr_blnc) % Display the table.
SOLUTIONReferenced in first MATLAB lecture
>> Lecture4Example4
YEAR ACCOUNT
BALANCE ($)
1.00 1065.00
2.00 1134.22
3.00 1207.95
4.00 1286.47
5.00 1370.09
6.00 1459.14
7.00 1553.99
8.00 1655.00
9.00 1762.57
10.00 1877.14
SOLUTIONExecuting the script file in the command window gives:
ASSIGNMENT 5:
1. Problem 32 page 61 in the textbook.
2. Problem 33 page 61 in the textbook.
3. Problem 4 page 161 in the textbook.
For each problem write a script file and execute it in the command window.For each problem, the first two lines of the script file are:% Assignment 5, Problem (write the number of the problem)% Name: (first name, last name)
Submit a printout of the script file, and a printout of the command window.