-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHussain_HW3_Feb_17.m
92 lines (85 loc) · 2.41 KB
/
Hussain_HW3_Feb_17.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
%Ridwan Hussain - CatLab Assignment #3
%This homework was far more reasonable but I struggled uncessarily on
%question number 3 (mostly due to my lack of how MatLab works), but
%question #2 was a lot of fun and most people agree with that.
clear; clc; close all;
%% Space Between
Aold = reshape(exp(0:63), 8, []).';
Aold(3:6, 3:6) = zeros(4,4);
geMean = geomean(Aold(Aold>0));
bigSin = sin(linspace(0, 5, 100).*linspace(-5, 0, 100).');
bestMid = min(abs(bigSin(:) - 0.5));
[xvar, yvar] = find(abs (bigSin - 0.5) == bestMid );
fun = @(x,y) exp(-(1-x.*y).^2) - 0.25*sqrt(x.^2+y.^2);
dommy = -10:0.05:10;
fullvol = fun(dommy, dommy.');
positivity = sum(fullvol(fullvol>0))*0.05^2;
%% I Need a Vacation
domain = 1:256;
a_entry = @(a, b) sqrt( (a-99).^2 + (b-99).^2 );
A = (a_entry(domain, domain.')) < 29;
figure;
imshow(A);
title("Ayy");
b_entry = @(a, b) sqrt( (a-62).^2 + (b-62).^2 );
B = (b_entry(domain, domain.')) < 58;
figure;
imshow(B);
title("Bee");
c_entry = @(a,b) a - 4 * sin(b/10);
C = (c_entry(domain, domain.')) > 200;
figure;
imshow(C);
title("See");
S = rand(256, 256, 3);
S(:, :, [2,3]) = [];
figure;
imshow(S);
title("Ess");
M = A & ~B;
figure;
imshow(M);
title("Emm");
Z = C.*S + M;
figure;
imshow(Z)
title("Zee");
%% My Sinc is Broken
y = @(x) sinc(x);
x = -2*pi:0.05*pi:2*pi;
derivative = deriv(y(x), x);
antiderivative = antideriv(y(x), x);
[y_extrema, x_extrema] = extrema(y(x), x);
[y_inflections, x_inflections] = inflections(y(x), x);
figure;
plot(x, y(x), x, antiderivative, x, derivative, ...
x_extrema, y_extrema, 'r*', x_inflections, y_inflections, 'bo');
title("Plotting the Fun Sinc");
%% Functions
function answer = deriv(y, x)
answer = [0 diff(y)./diff(x)];
end
function answer = antideriv(y, x)
answer = cumtrapz(x, y);
end
function answer = switchsign(x)
%One if current index is a different sign from previous index, 0
%otherwise
signx = sign(x);
intermediate = [0 signx(1:end-1)];
answer = (abs(sign(x) - intermediate) == 2);
end
function [answer, x] = extrema(y, x)
%Find these values using 1st and 2nd derivative test
%Return y and x values as vectors
ssi = switchsign(y);
answer = deriv(y, x) .* ssi;
x = x .* ssi;
end
function [answer, x] = inflections(y,x)
%Find these values using 1st and 2nd derivative test
%Return y and x values as vectors
ssi = switchsign(deriv(deriv(y, x), x));
answer = deriv(deriv(y,x), x) .* ssi;
x = x .* ssi;
end