01_ME3255_repo
HW Assignment #1
Answer to Homework Question 1
This semester I hope to become comfortable with Matlab to the point where I will be able to use it as a tool to solve engineering problems.
Problem 3 (2?)
A_66 = zeros(6,6);
for i = 1:6;
for j = 1:6;
A_66(i,j)=i*j;
end
end
fprintf('mean of A_66 = %1.2f\nstdev of A_66= %1.2f\n', mean(A_66(:)), std(A_66(:)))
output:
- mean of A_66 = 12.25
- stdev of A_66 = 9.07
Problem 4
Part A
set(0,'defaultAxesFontSize',16)
set(0,'defaultTextFontSize',16)
set(0,'defaultLineLineWidth',3)
data = dlmread('US_energy_by_sector.csv',',',2,0);
plot(data(:,1),data(:,3),data(:,1),data(:,9))
xlabel('Year')
ylabel('Total Energy Consumption (Trillion BTU)')
title('Annual US Energy Consumption by Sector')
legend('Residential','Transportation','Location','Northwest')
Part B
set(0,'defaultAxesFontSize',16)
set(0,'defaultTextFontSize',16)
set(0,'defaultLineLineWidth',3)
data = dlmread('US_energy_by_sector.csv',',',2,0);
x = cumtrapz(data(:,3))/(10^6)
y = cumtrapz(data(:,9))/(10^6)
plot(x)
hold on
plot(y)
hold off
xlabel('Year')
ylabel('Cumulative Energy Consumption (Quintillion BTU)')
title('Cumulative US Energy Consumption by Sector')
legend('Residential','Transportation','Location','Northwest')
![Cumulative Energy Use from 1949-2016](./figures/figure02.png)
Problem 5
Part A
Problem 6
Part A
function [vx,vy,vz] = Hw1_Prob6a(x,y,z,t)
%Function used to calculate velocity in 3D
vx=diff(x)./diff(t)
%velocity is change in x vector divided by change in t. The dot indicates
%term by term division, rather than matrix by matrix
vy=diff(y)./diff(t)
%velocity is change in y vector divided by change in t. The dot indicates
%term by term division, rather than matrix by matrix
vz=diff(z)./diff(t)
%velocity is change in z vector divided by change in t. The dot indicates
%term by term division, rather than matrix by matrix
end
Part B
function [ax,ay,az] = Hw1_Prob6b(x,y,z,t)
%Function used to calculate velocity in 3D
vx=diff(x)./diff(t);
%velocity is change in x vector divided by change in t. The dot indicates
%term by term division, rather than matrix by matrix
vx=[vx(1),vx];
%Diff function makes matrix one column shorter, need to do this to
%calculate ax
vy=diff(y)./diff(t);
%velocity is change in y vector divided by change in t. The dot indicates
%term by term division, rather than matrix by matrix
vy=[vy(1),vy];
%Diff function makes matrix one column shorter, need to do this to
%calculate ay
vz=diff(z)./diff(t);
%velocity is change in z vector divided by change in t. The dot indicates
%term by term division, rather than matrix by matrix
vz=[vz(1),vz];
%Diff function makes matrix one column shorter, need to do this to
%calculate az
ax=diff(vx)./diff(t)
%acceleration is change in velocity in x direction divided by change in t.
%The dot indicates term by term division, rather than matrix by matrix
ay=diff(vy)./diff(t)
%acceleration is change in velocity in y direction divided by change in t.
%The dot indicates term by term division, rather than matrix by matrix
az =diff(vz)./diff(t)
%acceleration is change in velocity in z direction divided by change in t.
%The dot indicates term by term division, rather than matrix by matrix
end