Create a MATLAB *.m script file that will solve the following 2 problems. Use MA
ID: 3817373 • Letter: C
Question
Create a MATLAB *.m script file that will solve the following 2 problems. Use MATLAB array operations to solve the problems.
Problem 1: When cars burn one gallon of gasoline, 19.4 pounds of CO2 (carbon dioxide) is produced. Suppose you have a group of cars that have the following fuel efficiencies (miles per gallon): 117 mpg, 42 mpg, 38 mpg, 33.3 mpg, 31 mpg, 28 mpg, 23 mpg and 18 mpg. Create a row vector containing the fuel efficiencies. Use the appropriate array operations to calculate the amount of CO2 produced for each car if the cars were driven for the following distances given in miles: 15000 miles for the car with 117 mpg, 13500 miles for the car with 42 mpg, 14000 miles for the car with 38 mpg, 11000 miles for the car with 33.3 mpg, 12500 miles for the car with 31 mpg, 8000 miles for the car with 28 mpg, 9500 miles for the car with 23 mpg, and 4000 miles with the car with 18 mpg. The amounts of CO2 should be stored in a row vector.
Problem 2: The distance a free-falling object falls is given by the equation D = 12 gt2
where D is the distance, g is the constant 9.8 meters per second, and t is time in seconds. Using either the colon operator or the linspace function create a row vector for times from 0 to 3 minutes in 5 second intervals (increments). (The row vector should include 0 and 180). Using MATLAB array operations, calculate another row vector that contains the distance the object fell for each time.
Make sure that you script file contains the clear and clc MATLAB commands and includes comments that describe the problem, input (even if it has been given), ouput, and processing.
Explanation / Answer
problem1:
please refer below code
close all
clc
clear all
format long;
fuel_effi = ones(1,8); %create row vector with 8 columns and set each location with 1
fuel_effi = [117 42 38 33.3 31 28 23 18];
dist = ones(1,8);
dist = [15000 13500 14000 11000 12500 8000 9500 4000];
amount_co2 = ones(1,8);
amount_co2 = fuel_effi .* dist * 19.4; %calculating amount of CO2 for each car
fprintf('below are the amount of CO2 produced ');
fprintf(1,'%f ', [amount_co2]');
please refer below output
below are the amount of CO2 produced
34047000.000000
10999800.000000
10320800.000000
7106220.000000
7517500.000000
4345600.000000
4238900.000000
1396800.000000
>>
Problem 2:
please refer below code
close all
clc
clear all
g = 9.8;
t = 0:5:180; %creating time vector with increment of 5 sec
D = g .* t.^2; %calculating D vector
fprintf('below are the distances ');
fprintf(1,'%f ',D);
please refer below output
below are the distances
0.000000
245.000000
980.000000
2205.000000
3920.000000
6125.000000
8820.000000
12005.000000
15680.000000
19845.000000
24500.000000
29645.000000
35280.000000
41405.000000
48020.000000
55125.000000
62720.000000
70805.000000
79380.000000
88445.000000
98000.000000
108045.000000
118580.000000
129605.000000
141120.000000
153125.000000
165620.000000
178605.000000
192080.000000
206045.000000
220500.000000
235445.000000
250880.000000
266805.000000
283220.000000
300125.000000
317520.000000
>>