uploaded all materials

This commit is contained in:
2025-03-24 00:43:09 -04:00
commit f2fb36f646
78 changed files with 15606 additions and 0 deletions

221
hw4/Ryan_HW4_022124.m Normal file
View File

@ -0,0 +1,221 @@
%%%% ECE-210-B HW 4 - Functions and Objects
% James Ryan, 02/21/24
% preamble
close all; clear; clc;
%% My Sinc Is Broken
% (1)
% see deriv.m
x = linspace(-5, 5, 1e3);
sinc_x = sinc(x);
deriv_sinc = deriv(sinc_x, x);
% see antideriv.m
% approximates an integral of a given function using `cumtrapz`
int_sinc = antideriv(sinc_x, x);
% (2)
% see switchsign.m
% (3)
[extrema_sinc_x, extrema_x] = extrema(sinc_x, x);
[inflect_sinc_x, inflect_x] = inflections(sinc_x, x);
% (4)
figure;
plot(x, sinc_x, x, int_sinc, x, deriv_sinc, ...
extrema_x, extrema_sinc_x, 'r*', ...
inflect_x, inflect_sinc_x, 'bo');
ylim([-2 2.45]);
xlim([-5, 5]);
ylabel("y-axis");
xlabel("x-axis");
grid on;
title( {'y = sinc(x) plotted over 1000 evenly spaced pts between x \epsilon [-5,5]', ...
'Plotted alongside its first derivative and antiderivative.'});
legend( 'y = sinc(x)',"$\int [sinc(x)] dx$",'$\frac{d}{dx} [sinc(x)]$', ...
'Points of Extrema', 'Inflection Points', ...
"Interpreter","latex");
%% Objectification
% (1)
% Matlab Classic Noteworthy Logo (TM) (C) (Not-for-individual-sale)
L = 160*membrane(1,100);
f = figure;
ax = axes;
s = surface(L);
s.EdgeColor = 'none';
view(3)
ax.XLim = [1 201];
ax.YLim = [1 201];
ax.ZLim = [-53.4 160];
ax.CameraPosition = [-145.5 -229.7 283.6];
ax.CameraTarget = [77.4 60.2 63.9];
ax.CameraUpVector = [0 0 1];
ax.CameraViewAngle = 36.7;
ax.Position = [0 0 1 1];
ax.DataAspectRatio = [1 1 .9];
l1 = light;
l1.Position = [160 400 80];
l1.Style = 'local';
l1.Color = [0 0.8 0.8];
l2 = light; % l2 = l1;
l2.Position = [.5 -1 .4];
l2.Color = [0.8 0.8 0];
s.FaceColor = [0.9 0.2 0.2];
s.FaceLighting = 'gouraud';
s.AmbientStrength = 0.3;
s.DiffuseStrength = 0.6;
s.BackFaceLighting = 'lit';
s.SpecularStrength = 1;
s.SpecularColorReflectance = 1;
s.SpecularExponent = 7;
axis off
f.Color = 'black';
% (2)
% Copyobj is not cooperating. Time to be lazy!
% Matlab Classic Noteworthy Logo (TM) (C) (Not-for-individual-sale)
f_dupe = figure;
ax_dupe = axes;
s_dupe = surface(L);
s_dupe.EdgeColor = 'none';
view(3)
ax_dupe.XLim = [1 201];
ax_dupe.YLim = [1 201];
ax_dupe.ZLim = [-53.4 160];
ax_dupe.CameraPosition = [-145.5 -229.7 283.6];
ax_dupe.CameraTarget = [77.4 60.2 63.9];
ax_dupe.CameraUpVector = [0 0 1];
ax_dupe.CameraViewAngle = 36.7;
ax_dupe.Position = [0 0 1 1];
ax_dupe.DataAspectRatio = [1 1 .9];
l3 = light;
l3.Position = [160 400 80];
l3.Style = 'local';
l3.Color = [0 0.8 0.8];
l4 = light; % l2 = l1;
l4.Position = [.5 -1 .4];
l4.Color = [0.8 0.8 0];
s_dupe.FaceColor = [0.9 0.2 0.2];
s_dupe.FaceLighting = 'gouraud';
s_dupe.AmbientStrength = 0.3;
s_dupe.DiffuseStrength = 0.6;
s_dupe.BackFaceLighting = 'lit';
s_dupe.SpecularStrength = 1;
s_dupe.SpecularColorReflectance = 1;
s_dupe.SpecularExponent = 7;
axis off
f_dupe.Color = 'black';
% James's Changes
% Change one - light at the origin!
l4.Position = [0 0 0];
l4.Color = [1 1 1];
% This made the logo significantly more purple!
% Change two - colormap
colormap winter;
% I didnt really notice a change with this one.
% Change three - function
s_dupe.FaceLighting = 'flat';
% I changed the surface! It has different face lighting. Thats changing
% the function, right?
% It helped emphasize the purple-maroon which possesses the shape at the moment
% Change four - backround
f_dupe.Color = 'red';
% Hard to miss - the entire background is now red!
% (3)
figure;
% Matlab <TM>
ax_former = subplot(2,1,1);
copyobj(ax.Children, ax_former);
title('Matlab <TM>');
ax_former.XLim = [1 201];
ax_former.YLim = [1 201];
ax_former.ZLim = [-53.4 160];
ax_former.XTick = [];
ax_former.YTick = [];
ax_former.ZTick = [];
ax_former.CameraPosition = [-145.5 -229.7 283.6];
ax_former.CameraTarget = [77.4 60.2 63.9];
ax_former.CameraUpVector = [0 0 1];
ax_former.CameraViewAngle = 36.7;
l5 = light;
l5.Position = [160 400 80];
l5.Style = 'local';
l5.Color = [0 0.8 0.8];
l6 = light; % l2 = l1;
l6.Position = [.5 -1 .4];
l6.Color = [0.8 0.8 0];
% James Plot
ax_latter = subplot(2,1,2);
copyobj(ax_dupe.Children, ax_latter);
title('Conspicuous Copycat');
ax_latter.XLim = [1 201];
ax_latter.YLim = [1 201];
ax_latter.ZLim = [-53.4 160];
ax_latter.XTick = [];
ax_latter.YTick = [];
ax_latter.ZTick = [];
ax_latter.CameraPosition = [-145.5 -229.7 283.6];
ax_latter.CameraTarget = [77.4 60.2 63.9];
ax_latter.CameraUpVector = [0 0 1];
ax_latter.CameraViewAngle = 36.7;
l7 = light;
l7.Position = [160 400 80];
l7.Style = 'local';
l7.Color = [0 0.8 0.8];
l8 = light; % l2 = l1;
l8.Position = [.5 -1 .4];
l8.Color = [0.8 0.8 0];
% James's Changes
% Change one - light at the origin!
l8.Position = [0 0 0];
l8.Color = [1 1 1];
% This made the logo significantly more purple!
% (4)
get(f)
f.PaperOrientation = 'landscape';
f.PaperType = 'a4';
f.PaperUnits = 'centimeters';
% My figure now is configured to print in Europe! And its sideways.

3
hw4/antideriv.m Normal file
View File

@ -0,0 +1,3 @@
function int_Y_dx = antideriv(y, x)
int_Y_dx = ( cumtrapz(y) .* (x(2) - x(1)) );
end

4
hw4/deriv.m Normal file
View File

@ -0,0 +1,4 @@
function dy = deriv(y, x)
dy = diff(y) ./ (x(2) - x(1));
dy = dy([1 1:end]);
end

5
hw4/extrema.m Normal file
View File

@ -0,0 +1,5 @@
function [y_ext, x_ext] = extrema(y, x)
y_switch = switchsign( deriv(y, x) );
y_ext = nonzeros(y_switch .* y);
x_ext = nonzeros(y_switch .* x);
end

View File

@ -0,0 +1,231 @@
%%%% ECE-210-B HW 4 - Functions and Objects
% James Ryan, 02/21/24
% preamble
close all; clear; clc;
%% My Sinc Is Broken
% (1)
% see deriv.m
x = linspace(-5, 5, 1e3);
sinc_x = sinc(x);
deriv_sinc = deriv(sinc_x, x);
% see antideriv.m
% approximates an integral of a given function using `cumtrapz`
int_sinc = antideriv(sinc_x, x);
% (2)
% see switchsign.m
% (3)
[extrema_sinc_x, extrema_x] = extrema(sinc_x, x);
[inflect_sinc_x, inflect_x] = inflections(sinc_x, x);
% (4)
figure;
plot(x, sinc_x, x, int_sinc, x, deriv_sinc, ...
extrema_x, extrema_sinc_x, 'r*', ...
inflect_x, inflect_sinc_x, 'bo');
ylim([-2 2.45]);
xlim([-5, 5]);
ylabel("y-axis");
xlabel("x-axis");
grid on;
title( {'y = sinc(x) plotted over 1000 evenly spaced pts between x \epsilon [-5,5]', ...
'Plotted alongside its first derivative and antiderivative.'});
legend( 'y = sinc(x)',"$\int [sinc(x)] dx$",'$\frac{d}{dx} [sinc(x)]$', ...
'Points of Extrema', 'Inflection Points', ...
"Interpreter","latex");
% <+.02> this is a very pretty legend.
%% Objectification
% (1)
% Matlab Classic Noteworthy Logo (TM) (C) (Not-for-individual-sale)
L = 160*membrane(1,100);
f = figure;
ax = axes;
s = surface(L);
s.EdgeColor = 'none';
view(3)
ax.XLim = [1 201];
ax.YLim = [1 201];
ax.ZLim = [-53.4 160];
ax.CameraPosition = [-145.5 -229.7 283.6];
ax.CameraTarget = [77.4 60.2 63.9];
ax.CameraUpVector = [0 0 1];
ax.CameraViewAngle = 36.7;
ax.Position = [0 0 1 1];
ax.DataAspectRatio = [1 1 .9];
l1 = light;
l1.Position = [160 400 80];
l1.Style = 'local';
l1.Color = [0 0.8 0.8];
l2 = light; % l2 = l1;
l2.Position = [.5 -1 .4];
l2.Color = [0.8 0.8 0];
s.FaceColor = [0.9 0.2 0.2];
s.FaceLighting = 'gouraud';
s.AmbientStrength = 0.3;
s.DiffuseStrength = 0.6;
s.BackFaceLighting = 'lit';
s.SpecularStrength = 1;
s.SpecularColorReflectance = 1;
s.SpecularExponent = 7;
axis off
f.Color = 'black';
% (2)
% Copyobj is not cooperating. Time to be lazy!
% Matlab FOR MS-DOS! Noteworthy Logo (TM) (C) (Not-for-individual-sale)
disk_operating_system = 2;
L_disk_operating_system = disk_operating_system .* L;
f_dupe = figure;
ax_dupe = axes;
s_dupe = surface(L_disk_operating_system);
s_dupe.EdgeColor = 'none';
view(3)
ax_dupe.XLim = disk_operating_system .* [1 201];
ax_dupe.YLim = disk_operating_system .* [1 201];
ax_dupe.ZLim = disk_operating_system .* [-53.4 160];
ax_dupe.CameraPosition = disk_operating_system .* [-145.5 -229.7 283.6];
ax_dupe.CameraTarget = disk_operating_system .* [77.4 60.2 63.9];
ax_dupe.CameraUpVector = [0 0 1];
ax_dupe.CameraViewAngle = 36.7;
ax_dupe.Position = [0 0 1 1];
ax_dupe.DataAspectRatio = [1 1 .9];
l3 = light;
l3.Position = [160 400 80];
l3.Style = 'local';
l3.Color = [0 0.8 0.8];
l4 = light; % l2 = l1;
l4.Position = [.5 -1 .4];
l4.Color = [0.8 0.8 0];
s_dupe.FaceColor = [0.9 0.2 0.2];
s_dupe.FaceLighting = 'gouraud';
s_dupe.AmbientStrength = 0.3;
s_dupe.DiffuseStrength = 0.6;
s_dupe.BackFaceLighting = 'lit';
s_dupe.SpecularStrength = 1;
s_dupe.SpecularColorReflectance = 1;
s_dupe.SpecularExponent = 7;
axis off
f_dupe.Color = 'black';
% James's Changes
% Change one - light at the origin!
l4.Position = [0 0 0];
l4.Color = [1 1 1];
% This made the logo significantly more purple!
% Change two - colormap
colormap winter;
% I didnt really notice a change with this one.
% Change three - function
s_dupe.FaceLighting = 'flat';
% I changed the surface! It has different face lighting. Thats changing
% the function, right?
% It helped emphasize the purple-maroon which possesses the shape at the moment
% Change four - backround
f_dupe.Color = 'red';
% Hard to miss - the entire background is now red!
% (3)
f_both = figure;
% Matlab <TM>
ax_former = subplot(1,2,1);
copyobj(ax.Children, ax_former);
title('Matlab <TM>');
ax_former.XLim = [1 201];
ax_former.YLim = [1 201];
ax_former.ZLim = [-53.4 160];
ax_former.XTick = [];
ax_former.YTick = [];
ax_former.ZTick = [];
ax_former.CameraPosition = [-145.5 -229.7 283.6];
ax_former.CameraTarget = [77.4 60.2 63.9];
ax_former.CameraUpVector = [0 0 1];
ax_former.CameraViewAngle = 36.7;
l5 = light;
l5.Position = [160 400 80];
l5.Style = 'local';
l5.Color = [0 0.8 0.8];
l6 = light; % l2 = l1;
l6.Position = [.5 -1 .4];
l6.Color = [0.8 0.8 0];
% James Plot Matlab for DOS
ax_latter = subplot(1,2,2);
copyobj(ax_dupe.Children, ax_latter);
title('Conspicuous Copycat');
% <+.02> MATLAB for DOS lol
% disk operating system, or DOS, is 2 for short :)
ax_latter.XLim = disk_operating_system .* [1 201];
ax_latter.YLim = disk_operating_system .* [1 201];
ax_latter.ZLim = disk_operating_system .* [-53.4 160];
ax_latter.XTick = [];
ax_latter.YTick = [];
ax_latter.ZTick = [];
ax_latter.CameraPosition = disk_operating_system .* [-145.5 -229.7 283.6];
ax_latter.CameraTarget = disk_operating_system .* [77.4 60.2 63.9];
ax_latter.CameraUpVector = [0 0 1];
ax_latter.CameraViewAngle = 36.7;
l7 = light;
l7.Position = [160 400 80];
l7.Style = 'local';
l7.Color = [0 0.8 0.8];
l8 = light; % l2 = l1;
l8.Position = [.5 -1 .4];
l8.Color = [0.8 0.8 0];
f_both.Color = 'green';
% James's Changes
% Change one - light at the origin!
l8.Position = [0 0 0];
l8.Color = [1 1 1];
% This made the logo significantly more purple!
% (4)
%get(f)
f.PaperOrientation = 'landscape';
f.PaperType = 'a4';
f.PaperUnits = 'centimeters';
% My figure now is configured to print in Europe! And its sideways.
% <+.01> lmao, incredible

3
hw4/feedback/antideriv.m Normal file
View File

@ -0,0 +1,3 @@
function int_Y_dx = antideriv(y, x)
int_Y_dx = ( cumtrapz(y) .* (x(2) - x(1)) );
end

4
hw4/feedback/deriv.m Normal file
View File

@ -0,0 +1,4 @@
function dy = deriv(y, x)
dy = diff(y) ./ (x(2) - x(1));
dy = dy([1 1:end]);
end

5
hw4/feedback/extrema.m Normal file
View File

@ -0,0 +1,5 @@
function [y_ext, x_ext] = extrema(y, x)
y_switch = switchsign( deriv(y, x) );
y_ext = nonzeros(y_switch .* y);
x_ext = nonzeros(y_switch .* x);
end

View File

@ -0,0 +1,5 @@
function [y_inf, x_inf] = inflections(y, x)
y_switch = switchsign( deriv(deriv(y, x), x) );
y_inf = nonzeros(y_switch .* y);
x_inf = nonzeros(y_switch .* x);
end

17
hw4/feedback/switchsign.m Normal file
View File

@ -0,0 +1,17 @@
% cursed
% lmao
% basically - I take pairs of adjacent values on the vector `x` and add them
% together. These sums are then checked against both members of the pair,
% and if either member is *larger* than the sum, that indicates a sign change
% since one of the values acted as a subtractor.
% "Glue" is added in the comparison stage, to skew ONLY on cases where
% we are comparing zero to zero (origin case). Its really a rounding error otherwise. lol
% The front is padded w/ a zero.
function ret = switchsign(x)
sum_check = x(1:end-1) + x(2:end);
ret = [0, ( abs(sum_check) < abs(x(1:end-1)+1e-7) ) | ( abs(sum_check) < abs(x(2:end)+1e-7) ) ];
end
% <-.01> works here (this is insane), but technically has an
% error: calling `switchsign([-1 2 1 0 1 -3])` (the example i
% gave) returns `[0 1 0 1 1 1]` rather than `[0 1 0 0 0 1]`.
% not that that really matters. sorry...

5
hw4/inflections.m Normal file
View File

@ -0,0 +1,5 @@
function [y_inf, x_inf] = inflections(y, x)
y_switch = switchsign( deriv(deriv(y, x), x) );
y_inf = nonzeros(y_switch .* y);
x_inf = nonzeros(y_switch .* x);
end

12
hw4/switchsign.m Normal file
View File

@ -0,0 +1,12 @@
% cursed
% basically - I take pairs of adjacent values on the vector `x` and add them
% together. These sums are then checked against both members of the pair,
% and if either member is *larger* than the sum, that indicates a sign change
% since one of the values acted as a subtractor.
% "Glue" is added in the comparison stage, to skew ONLY on cases where
% we are comparing zero to zero (origin case). Its really a rounding error otherwise. lol
% The front is padded w/ a zero.
function ret = switchsign(x)
sum_check = x(1:end-1) + x(2:end);
ret = [0, ( abs(sum_check) < abs(x(1:end-1)+1e-7) ) | ( abs(sum_check) < abs(x(2:end)+1e-7) ) ];
end