The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 304 Weeks Ago, 6 Days Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
These are Matlab program problems. Please help. Please run files to make sure they work thank you.
ENGR1140: COMPUTATIONAL ENGINEERING METHODS. Spring 2017
PROJECT 3.
For all problems
1. Write a MATLAB script and name it appropriately. For instance you can name the first file Proj1_1 (representing project 1 problem 1.). Make sure your script has enough comments to bring the meaning of the code out.
2. Save your file
3. Clear your workspace
4. Run the file in the MATLAB command window
5. Copy your script and paste it as specified in page 3 below.
6. Copy all your outputs (exactly as displayed) and paste them as specified in page 3 below.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Problem 1: DRAWING BUTTERFLIES
This problem requires you to use a combination of the while loop, the for loop and the if statement to generate a figure that looks just like this.

These are butterflies.
Write a function called butterfly that returns the x and y values that can be used to plot a single butterfly. The equations to draw a butterfly with x and y points are:
![]()
?=??+?∗?∗???(?)
?=??+?∗?∗???(?)
Â
??,??, ?? ?ℎ? ?????? ?? ?ℎ? ????????? ??? ? ?????? ?ℎ? ℎ???ℎ? ?? ?ℎ? ?????????.
Use 0≤ t ≤ 40*pi with and increment of 0.1.
Use a while loop to allow the user to continuously input the center coordinates, the height scale and the color of the butterfly. Use an if statement to terminate the loop once the user is done imputing the properties of all the four butterflies. For each set of inputs, use a for loop to compute x and y values that will plot a butterfly and plot it with the assigned color. Use the following butterfly properties.
Â

Problem 2: LOAN AMORTIZATION TABLE
When you borrow money from a bank to buy a house, the loan generally comes with the loan amount and the interest rate that is quoted annually. If the loan is paid monthly, then the interest on the loan is calculated monthly. The monthly payment is calculated by using the equation below.
![]()
where:
M is the monthly payment, P is the principal left to be paid at any given time, i is the monthly interest rate calculated by dividing the annual interest rate by 12, n is the term of the loan or number of payments (the number of months you will be paying the loan).
The interesting thing about mortgage payment is that the monthly interest payment changes every month and it is calculated on a monthly basis based on the principal left.
Example calculation: Suppose the initial loan is $200,000, the annual interest rate is 5%, the term of the loan is 30 years (n = 30*12 = 360 payments). Here the monthly interest rate is calculated as i = 0.05/12 = 0.0041666667. Using the formula above, the monthly payment is $1073.64. The interest on the loan is calculated always on the balance left to pay on the loan. For the first month, the interest component of the monthly payment is calculated as: interest = balance left * 0.0041666667= 200000*0.0041666667=833.33. This means the principal component for the first monthly payment will be: Principal paid = monthly payment -interest= 1073.64-833.33 = 240.31. The balance left on the loan after the first payment will then be calculated as: balance left = 200000-240.31 = 199759.69. This new balance is used to start the process for the next payment. This is done until the loan is fully paid for at the end of the term of the loan. The table that shows the payment plan is called a loan amortization table. An example is shown below:
Â
i.                    Write a function called amorttablethat asks the user to input the following: the loan amount, the interest rate, and the term of the loan in years.
Â
a.      Use a for loop in your function to develop the loan amortization table similar to the one below. Note that the table shows the total interest paid on the loan. Use a loan amount of $250,000. a 30 year loan term, and an interest rate of 5%. Use an if statement to force a negative balance to zero.
b.     Repeat the process using a while loop. The two tables should be exactly the same.
Â
ii.                  Run your code again except that in this case use 15 years as the term of the loan.

Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Problem 3: SUMMER TRAVEL
Every summer, many people travel by road to various locations across the country. With low fuel prices this summer, there will be lots of travel. The purpose of this program is to determine the total miles of travel and also compute the cost of travel using various travel route options. The excel sheet named project3.xlsx has data for this work. The table represents 55 families travel plans. Each family is identified by a family ID. Each travel plan consists of 10 road segments whose distances are given in miles. Column 11 is the average speed of the family and column 12 is the fuel efficiency of the family’s vehicle. For example, for family 1, the average speed is 65mph and they have a vehicle that does 35 miles per gallon. Write a function called summetravelthat uses a for loop to generate the table below. Your table should show all the outputs from 1 to 55. Use $2/gallon as the average fuel cost.

| Â |
SEGMENT (MILES) |
|||||||||||
|
FAMILY |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
|
1 |
40 |
150 |
70 |
100 |
140 |
202 |
51 |
44 |
12 |
95 |
65 |
35 |
|
2 |
100 |
121 |
57 |
105 |
66 |
182 |
54 |
87 |
8 |
141 |
75 |
20 |
|
3 |
66 |
147 |
64 |
115 |
206 |
100 |
57 |
78 |
45 |
135 |
68 |
25 |
|
4 |
89 |
88 |
67 |
130 |
25 |
99 |
60 |
98 |
120 |
158 |
65 |
26 |
|
5 |
90 |
125 |
68 |
150 |
58 |
68 |
63 |
78 |
145 |
141 |
70 |
25 |
|
6 |
45 |
102 |
78 |
175 |
157 |
159 |
66 |
41 |
22 |
107 |
75 |
33 |
|
7 |
60 |
99 |
77 |
205 |
149 |
171 |
69 |
15 |
23 |
84 |
77 |
30 |
|
8 |
91 |
218 |
81 |
140 |
204 |
21 |
72 |
25 |
36 |
108 |
79 |
32 |
|
9 |
24 |
192 |
79 |
140 |
116 |
228 |
75 |
47 |
99 |
87 |
49 |
28 |
|
10 |
57 |
188 |
82 |
150 |
150 |
57 |
78 |
102 |
97 |
88 |
66 |
29 |
|
11 |
89 |
140 |
75 |
160 |
139 |
140 |
81 |
55 |
72 |
45 |
60 |
20 |
|
12 |
97 |
167 |
76 |
170 |
179 |
125 |
84 |
48 |
42 |
77 |
75 |
19 |
|
13 |
67 |
183 |
119 |
180 |
170 |
122 |
87 |
77 |
20 |
98 |
76 |
60 |
|
14 |
54 |
125 |
113 |
190 |
104 |
109 |
90 |
99 |
5 |
45 |
58 |
52 |
|
15 |
100 |
98 |
85 |
200 |
128 |
210 |
93 |
87 |
55 |
23 |
63 |
22 |
|
16 |
120 |
82 |
86 |
210 |
137 |
214 |
91 |
78 |
88 |
12 |
65 |
21 |
|
17 |
96 |
75 |
87 |
220 |
111 |
183 |
94 |
79 |
48 |
10 |
60 |
20 |
|
18 |
201 |
69 |
87 |
230 |
215 |
122 |
97 |
69 |
78 |
9 |
55 |
18 |
|
19 |
77 |
132 |
90 |
55 |
159 |
221 |
100 |
63 |
74 |
77 |
58 |
19 |
|
20 |
123 |
59 |
139 |
50 |
137 |
194 |
103 |
158 |
41 |
9 |
59 |
66 |
|
21 |
143 |
57 |
100 |
60 |
160 |
212 |
106 |
45 |
40 |
12 |
76 |
25 |
|
22 |
119 |
160 |
131 |
108 |
44 |
91 |
109 |
60 |
145 |
120 |
77 |
54 |
|
23 |
102 |
123 |
104 |
112 |
17 |
59 |
112 |
91 |
22 |
88 |
74 |
25 |
|
24 |
70 |
75 |
105 |
116 |
120 |
157 |
115 |
24 |
23 |
45 |
71 |
24 |
|
25 |
72 |
123 |
109 |
120 |
175 |
207 |
113 |
57 |
36 |
98 |
70 |
26 |
|
26 |
74 |
52 |
112 |
124 |
111 |
138 |
116 |
89 |
99 |
32 |
69 |
27 |
|
27 |
76 |
93 |
116 |
128 |
159 |
181 |
119 |
97 |
97 |
78 |
66 |
29 |
|
28 |
78 |
89 |
119 |
132 |
162 |
179 |
122 |
67 |
72 |
79 |
58 |
30 |
|
29 |
80 |
74 |
122 |
136 |
154 |
166 |
125 |
54 |
42 |
69 |
59 |
31 |
|
30 |
82 |
63 |
128 |
140 |
44 |
157 |
128 |
100 |
20 |
63 |
63 |
35 |
|
31 |
84 |
339 |
127 |
144 |
45 |
14 |
131 |
120 |
5 |
158 |
60 |
32 |
|
32 |
86 |
227 |
133 |
148 |
66 |
87 |
134 |
96 |
55 |
45 |
58 |
36 |
|
33 |
88 |
243 |
133 |
152 |
36 |
88 |
137 |
105 |
22 |
60 |
55 |
34 |
|
34 |
44 |
78 |
142 |
156 |
30 |
47 |
140 |
93 |
45 |
91 |
54 |
41 |
|
35 |
92 |
209 |
125 |
160 |
28 |
45 |
143 |
89 |
78 |
24 |
71 |
22 |
|
36 |
94 |
125 |
125 |
58 |
156 |
50 |
141 |
45 |
98 |
57 |
72 |
20 |
|
37 |
96 |
144 |
75 |
154 |
90 |
84 |
102 |
113 |
12 |
89 |
65 |
18 |
|
38 |
98 |
158 |
52 |
172 |
200 |
55 |
147 |
33 |
100 |
97 |
69 |
17 |
|
39 |
100 |
56 |
44 |
176 |
172 |
68 |
150 |
77 |
78 |
67 |
66 |
19 |
|
40 |
102 |
90 |
25 |
180 |
207 |
4 |
153 |
47 |
79 |
100 |
67 |
32 |
|
41 |
104 |
78 |
134 |
92 |
96 |
75 |
156 |
128 |
98 |
87 |
55 |
19 |
|
42 |
106 |
144 |
58 |
94 |
163 |
62 |
159 |
59 |
78 |
52 |
55 |
22 |
|
43 |
108 |
258 |
144 |
96 |
178 |
87 |
162 |
389 |
45 |
65 |
58 |
25 |
|
44 |
110 |
243 |
87 |
98 |
164 |
9 |
121 |
58 |
52 |
49 |
59 |
24 |
|
45 |
55 |
243 |
90 |
100 |
108 |
98 |
123 |
45 |
47 |
48 |
63 |
21 |
|
46 |
47 |
58 |
99 |
87 |
95 |
117 |
125 |
54 |
22 |
43 |
60 |
20 |
|
47 |
116 |
100 |
150 |
11 |
171 |
69 |
127 |
78 |
111 |
50 |
58 |
23 |
|
48 |
118 |
22 |
47 |
106 |
189 |
87 |
129 |
89 |
20 |
66 |
55 |
33 |
|
49 |
120 |
58 |
87 |
108 |
194 |
77 |
131 |
65 |
69 |
69 |
54 |
35 |
|
50 |
22 |
25 |
8 |
60 |
45 |
59 |
133 |
47 |
86 |
61 |
71 |
30 |
|
51 |
48 |
78 |
165 |
10 |
116 |
45 |
135 |
102 |
38 |
63 |
72 |
30 |
|
52 |
20 |
98 |
17 |
114 |
88 |
130 |
87 |
12 |
72 |
48 |
65 |
36 |
|
53 |
102 |
78 |
158 |
87 |
195 |
192 |
77 |
201 |
55 |
88 |
69 |
19 |
|
54 |
66 |
44 |
163 |
48 |
144 |
122 |
141 |
125 |
65 |
73 |
70 |
22 |
|
55 |
132 |
89 |
171 |
120 |
207 |
47 |
44 |
88 |
60 |
70 |
69 |
28 |
----------- Â ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly