%%%% ECE210-B Matlab Seminar, Homework 1. % james ryan, 1/24/24 % <-.0> style point: please ensure files are named so that % MATLAB (sorry, i'd rather grade in Octave, but this is not % Octave seminar...) can run them! this one had a space in it. % preamble close all; clear; clc; %% Scale-'ers % (1) % Takes the absolute value of % sin(pi/3) % PLUS % j divided by secant of (-5/3)*pi a = abs(sin(pi ./ 3) ... + ((1 * j) ./ (sec((-5 * pi) / 3))) ... ); % MATLAB interptes complex literals, so you could also write % `1j`. % (2) % n = 3, cubic root l = nthroot(8, 3); % could also do `8^(1/3)`, if you're mathematically inclined. % (3) % [1, 2, 3, ..., 79, 80] u_mat = 1:80; % Sums all the terms from u_mat, scales by 2 / 6!, and takes the square root u = sqrt((2 / factorial(6)) * sum(u_mat)); % q4 % takes the square % of imaginary value % of the floor % of the log % of the square root of 66 % taken to the power of 7j m = (imag(floor(log(sqrt(66).^(7 * j))))).^2; % since these are scalars, the `.^` is not strictly necessary, % but i see you have a vector bent... %% Mother...? % (1) % Makes a 1x4 matrix from a l u & m, % and transposes the formed matrix into a 4x1 matrix A = [a; l; u; m]; % (2) % makes a 2x2 matrix using a l u & m. F = [a l; u m]; % (3) % takes the non-conjugate transpose of F T = F.'; % (4) % takes the inverse of the matrix product of T * F B = inv(T * F); check = B * (T * F) % aaaaaaa no semicolon % (5) % Makes a square matrix comprised of T and F C = [T F; F T]; %% Cruelty meanB = mean(B, "all"); % sums "all" values in matrix B into one scalar % squashes every row down into the sum of all elements % in a given row meanC = mean(C, 2); % ... or takes the mean of every value along a % dimension (the 2nd dimension), and squashes % the matrix down into one dimension. %% Odd Types % eval one evalOne = T + F; %{ comments: evalOne = 2 5 5 8 This makes sense, considering T was [1 3; 2 4] and F was [1 2; 3 4] It seems like, at the same index on both matrices, the value occupying that spot was taken from both and summed. %} % eval 2 evalTwo = T + 1; %{ comments: evalTwo = 2 4 3 5 This makes sense, since it seems like 1 was interpreted as a 2x2 matrix occupied only by 1's. The same summing algorithm was applied, and every value occupying T was incremented by 1. This could be confusing if we were multiplying instead of dividing, since it would make more intuitive sense to be referring to the identity matrix as 1, rather than a matrix filled wuth 1's. %} % eval kicks evalKicks = A + C; %{ comments: evalKicks = 2 5 4 6 3 6 6 8 2 4 4 7 4 6 5 8 A and C are not the same dimensions. A is 1x4 while C is 4x4. It seems that C was sliced by rows in order to let this operation make sense. so for every Row in C, the value corresponding to the matching column in A was added to that value in C. Put nicely: Every row in C (a 1x4 matrix) was summed with A, and then returned to the row index it previously occupied in C proper. %} % <+.06> love the extensive commentary. %% Not What it Seems... for k = [3 5 10 300 1e6] % sets up a 1xk matrix of `k` evenly spaced vals that are [0, 1] genericMatrix = linspace(0, 1, k); % squares every val in the matrix, sums all squared vals together, and divs % every element by k. % Essentially -- average value of x^2 from 0 to 1 % Also known as power, according to fred genericScalar = sum(genericMatrix.^2) ./ k; end % right, and what *is* that average, in terms of math objects?