diff --git a/Lesson1/Lesson 1 Wrap-up.m b/Lesson1/Lesson 1 Wrap-up.m new file mode 100644 index 0000000..a59e4da --- /dev/null +++ b/Lesson1/Lesson 1 Wrap-up.m @@ -0,0 +1,2 @@ +hundred=0.1/(9.58/(60*60)) +marathon=42.195/(2+(1/60)+(39/(60*60))) diff --git a/Lesson1/MATLAB Calculation.m b/Lesson1/MATLAB Calculation.m new file mode 100644 index 0000000..0630e29 --- /dev/null +++ b/Lesson1/MATLAB Calculation.m @@ -0,0 +1,7 @@ +borrowed = 1000 + +rate = 0.1 + +first_year_debt=borrowed*rate+borrowed + +debt=first_year_debt+first_year_debt*rate diff --git a/Lesson2/Colon Operator.m b/Lesson2/Colon Operator.m new file mode 100644 index 0000000..a476b79 --- /dev/null +++ b/Lesson2/Colon Operator.m @@ -0,0 +1,2 @@ +odds=1:2:100 +evens=100:-2:1 diff --git a/Lesson2/Matrix Arithmetic.m b/Lesson2/Matrix Arithmetic.m new file mode 100644 index 0000000..730ce2e --- /dev/null +++ b/Lesson2/Matrix Arithmetic.m @@ -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 diff --git a/Lesson2/Matrix Indexing.m b/Lesson2/Matrix Indexing.m new file mode 100644 index 0000000..c083ca8 --- /dev/null +++ b/Lesson2/Matrix Indexing.m @@ -0,0 +1,3 @@ +A = [1:5; 6:10; 11:15; 16:20]; +v=A(:,2) +A(end,:)=0 diff --git a/Lesson3/A Simple Function.m b/Lesson3/A Simple Function.m new file mode 100644 index 0000000..533016e --- /dev/null +++ b/Lesson3/A Simple Function.m @@ -0,0 +1,3 @@ +function a= tri_area(base,hight) +a=0.5*base*hight; +end diff --git a/Lesson3/Lesson 3 Wrap-up.m b/Lesson3/Lesson 3 Wrap-up.m new file mode 100644 index 0000000..01337f9 --- /dev/null +++ b/Lesson3/Lesson 3 Wrap-up.m @@ -0,0 +1,2 @@ +function fare= taxi_fare(dist_km,time_min) +fare=5+(2*(ceil(dist_km)-1))+(0.25*ceil(time_min)); diff --git a/Lesson3/Multiple Outputs.m b/Lesson3/Multiple Outputs.m new file mode 100644 index 0000000..0d614f7 --- /dev/null +++ b/Lesson3/Multiple Outputs.m @@ -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); diff --git a/Lesson4/Built-in functions.m b/Lesson4/Built-in functions.m new file mode 100644 index 0000000..03f561b --- /dev/null +++ b/Lesson4/Built-in functions.m @@ -0,0 +1,3 @@ +function [mmr,mmm] = minimax(M) +mmr=abs(max(M,[],2)-min(M,[],2))'; +mmm=(max(M,[],'all')-min(M,[],'all')); diff --git a/Lesson4/Lesson 4 Wrap-up.m b/Lesson4/Lesson 4 Wrap-up.m new file mode 100644 index 0000000..4f87884 --- /dev/null +++ b/Lesson4/Lesson 4 Wrap-up.m @@ -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] diff --git a/lesson5/If-statement practice.m b/lesson5/If-statement practice.m new file mode 100644 index 0000000..9c36e4e --- /dev/null +++ b/lesson5/If-statement practice.m @@ -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) diff --git a/lesson5/Lesson 5 Wrap-up.m b/lesson5/Lesson 5 Wrap-up.m new file mode 100644 index 0000000..6447b75 --- /dev/null +++ b/lesson5/Lesson 5 Wrap-up.m @@ -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 diff --git a/lesson5/More practice.m b/lesson5/More practice.m new file mode 100644 index 0000000..79b23b8 --- /dev/null +++ b/lesson5/More practice.m @@ -0,0 +1,7 @@ +function admit= eligible(v,q) +if (((v+q)/2) >=92 && ((q>88) && (v>88))) + admit= true ; +else + admit = false; +end + diff --git a/lesson5/nargin.m b/lesson5/nargin.m new file mode 100644 index 0000000..f031945 --- /dev/null +++ b/lesson5/nargin.m @@ -0,0 +1,6 @@ +function too_young = under_age (age,limit) +if nargin==1 + too_young= age<21; +else + too_young= age