ece210/hw4/Ryan_HW4_022124.m

222 lines
4.7 KiB
Matlab

%%%% 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.