Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2021 Update #1

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions Lesson1/Lesson 1 Wrap-up.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
hundred=0.1/(9.58/(60*60))
marathon=42.195/(2+(1/60)+(39/(60*60)))
7 changes: 7 additions & 0 deletions Lesson1/MATLAB Calculation.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
borrowed = 1000

rate = 0.1

first_year_debt=borrowed*rate+borrowed

debt=first_year_debt+first_year_debt*rate
2 changes: 2 additions & 0 deletions Lesson2/Colon Operator.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
odds=1:2:100
evens=100:-2:1
5 changes: 5 additions & 0 deletions Lesson2/Matrix Arithmetic.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
A = [1:5; 6:10; 11:15; 16:20];

b=[1 1 1 1]
c=[1;1;1;1;1]
result=b*A*c
3 changes: 3 additions & 0 deletions Lesson2/Matrix Indexing.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
A = [1:5; 6:10; 11:15; 16:20];
v=A(:,2)
A(end,:)=0
3 changes: 3 additions & 0 deletions Lesson3/A Simple Function.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function a= tri_area(base,hight)
a=0.5*base*hight;
end
2 changes: 2 additions & 0 deletions Lesson3/Lesson 3 Wrap-up.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
function fare= taxi_fare(dist_km,time_min)
fare=5+(2*(ceil(dist_km)-1))+(0.25*ceil(time_min));
5 changes: 5 additions & 0 deletions Lesson3/Multiple Outputs.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function [tl,tr,bl,br]= corners(ip)
tl=ip(1,1);
tr=ip(1,end);
bl=ip(end,1);
br=ip(end,end);
3 changes: 3 additions & 0 deletions Lesson4/Built-in functions.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function [mmr,mmm] = minimax(M)
mmr=abs(max(M,[],2)-min(M,[],2))';
mmm=(max(M,[],'all')-min(M,[],'all'));
5 changes: 5 additions & 0 deletions Lesson4/Lesson 4 Wrap-up.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function T=trio(m,n)
a=ones(m,n);
b=2*ones(m,n);
c=3*ones(m,n);
T=[a;b;c]
10 changes: 10 additions & 0 deletions lesson5/If-statement practice.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function out= picker(condition, in1, in2)
if condition
out= in1;
else
out= in2;

end

out = picker(true,1,2)
out = picker(false,1,2)
31 changes: 31 additions & 0 deletions lesson5/Lesson 5 Wrap-up.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
function isvalid = valid_date(y, m, d)
% Check if the inputs are valid
% Check that they are scalars
if ~(isscalar(y) && isscalar(m) && isscalar(d))
isvalid = false;
% Check that inputs are positive
elseif ~all([y, m, d] > 0)
isvalid = false;
% Check that inputs are integers (not the data type)
elseif any(rem([y, m, d], 1))
isvalid = false;
% Check that m and d are below the max possible
elseif (m > 12) || (d > 31)
isvalid = false;
% The inputs could be a valid date, let's see if they actually are
else
% Vector of the number of days for each month
daysInMonth = [31 28 31 30 31 30 31 31 30 31 30 31];
% If leap year, change days in Feb
if isequal(rem(y, 4), 0) && (~isequal(rem(y, 100), 0) || isequal(rem(y, 400), 0))
daysInMonth(2) = 29;
end
maxDay = daysInMonth(m);
if d > maxDay
isvalid = false;
else
isvalid = true;
end

end
end
7 changes: 7 additions & 0 deletions lesson5/More practice.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function admit= eligible(v,q)
if (((v+q)/2) >=92 && ((q>88) && (v>88)))
admit= true ;
else
admit = false;
end

6 changes: 6 additions & 0 deletions lesson5/nargin.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function too_young = under_age (age,limit)
if nargin==1
too_young= age<21;
else
too_young= age<limit;
end