Skip to content

Commit 54f51e3

Browse files
author
TRex22
committed
Added The tutorial files
1 parent 8917409 commit 54f51e3

File tree

14 files changed

+142
-15
lines changed

14 files changed

+142
-15
lines changed

Code Scripts/AddMultiply.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function [a,m] = AddMultiply(x)
2+
%Show difference between
3+
%addition and multiplication
4+
a = x+x;
5+
m = x*x;
6+
end

Code Scripts/CalcExp.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function out = CalcExp(in, exp)
2+
if (y=1)
3+
out = in;
4+
elseif(y ~= 0)
5+
out = CalcExp(in*in, exp-1);
6+
else
7+
out = 1;
8+
end
9+
end

Code Scripts/ExpIteration.m

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
%x is the number, y is the exponent
2+
%i is the counter
3+
x = 5;
4+
y = 2;
5+
if (y=1)
6+
ans = x
7+
elseif (y ~= 0)
8+
for i = 1:y
9+
x*x;
10+
end
11+
ans = x
12+
else
13+
ans = 1
14+
end

Code Scripts/ExpRecursionScript.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
x = 5;
2+
y = 2;
3+
ans = CalcExp(x,y)

Code Scripts/FibonacciIteration.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
m = 0;
2+
n = 1;
3+
count = 5;
4+
for i = 1:count
5+
ans = n+m;
6+
m = n;
7+
n = ans;
8+
end
9+
ans

Code Scripts/FibonacciRecursive.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
count = 5;
2+
ans = fib_recur(count);

Code Scripts/Script1.m

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
%Hello I am a comment
2+
%A lot of output will be supressed by using a semi-colon (;)
3+
4+
%clear memory and the Command Window
5+
clear all
6+
clc
7+
8+
%Some Matrices
9+
A = [1 0 0; 0 1 0; 0 0 1];
10+
B = [2 30 60; 56 3 45; 1024 4 88];
11+
12+
C = A*B;
13+
14+
%A Switch-case example
15+
variable = 'hello';
16+
switch (variable)
17+
case 'goodbye'
18+
fprintf('cheers\n');
19+
case 'hello'
20+
fprintf('hello world\n');
21+
otherwise
22+
fprintf('why you say no hello?\n');
23+
end
24+
25+
%use a terminating factor with a while loop
26+
count = 0;
27+
while (count ~= 5)
28+
count = count + 1
29+
end
30+
31+
%if-statements
32+
A=2;
33+
if (A == 1)
34+
fprintf('hello');
35+
elseif (A == 10)
36+
fprintf('goodbye');
37+
else
38+
A = 1;
39+
end
40+
41+
%for-loop
42+
A = zeros(5,100);
43+
fprintf('A before:');
44+
A
45+
for m = 1:5
46+
for n = 1:100
47+
A(m, n) = 1/(m + n - 1);
48+
end
49+
end
50+
fprintf('A after:');
51+
A
52+

Code Scripts/average.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function y = average(x, z)
2+
if isvector(x)
3+
error('Input must not be a vector')
4+
end
5+
y = (x+z)/2;
6+
end

Code Scripts/fib_recur.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function y = fib_recur(n)
2+
if n == 0
3+
y = 0;
4+
else
5+
y = [fib_recur(n-1) fib(n)]
6+
end

Code Scripts/myScript.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function [] = myScript()
2+
y = 1:10;
3+
out1 = myfunc(y);
4+
end
5+
6+
function [out1] = myfunc( x )
7+
out1 = sqrt( 1 + (cos(x))^2 );
8+
end

0 commit comments

Comments
 (0)