Modify this MatLab code to plot the initials with red squares of size 100, filled with…
- User
Modify this MatLab code to plot the initials with red squares of size 100, filled with color and outlined with black:
% Transform Initials % What this MATLAB script does: % 1) Plots my initials using scatter() in the complex plane. % 2) Transforms initials using addition/multiplication of complex numbers % 3) get creative? %% initialize initials clear all % never not do this! % ----------------------------------------- % x= 012345678901234567890 % y=6 *** *** % 5 * * * % 4 * * * % 3 * *** % 28 pts total (by counting!) % 2 * * * % 1 * * * % 0 *** *** % x= 012345678901234567890 % ----------------------------------------- manually enter the coordinates npts = 6;
Zo = zeros(1,npts); % preallocate the Zo array % ------------------------- Zo( 1) = 3 + 1i0; Zo( 2) = 4 + 1i0; Zo( 3) = 5 + 1i0; Zo( 4) = 11 + 1i0; Zo( 5) = 12 + 1i0; Zo( 6) = 13 + 1i0; % ------------------------- Zo( 7) = 2 + 1i1; Zo( 8) = 11 + 1i1; Zo( 9) = 14 + 1i1; % ------------------------- Zo(10) = 0 + 1i2; Zo(11) = 11 + 1i2; Zo(12) = 14 + 1i2; % ------------------------- Zo(13) = 0 + 1i3; Zo(14) = 11 + 1i3; Zo(15) = 12 + 1i3; Zo(16) = 13 + 1i3; % ------------------------- Zo(17) = 0 + 1i4; Zo(18) = 11 + 1i4; Zo(19) = 14 + 1i4; % ------------------------- Zo(20) = 1 + 1i5; Zo(21) = 11 + 1i5; Zo(22) = 14 + 1i5; % ------------------------- Zo(23) = 2 + 1i6; Zo(24) = 3 + 1i6; Zo(25) = 4 + 1i6; Zo(26) = 11 + 1i6; Zo(27) = 12 + 1i6; Zo(28) = 13 + 1i6; % ---------------------------------------------- check my inputed initials figure(1); clf; scatter(real(Zo),imag(Zo),75,'blue','filled'); figure(1); %error('stop here for now'); %% calculate center of mass and translate initials % ---------------------------- method 1 %xCM = mean(real(Zo)); %yCM = mean(imag(Zo)); %Zo = Zo - (xCM + 1iyCM); % ---------------------------- method 2 zCM = mean(Zo); % <= real & imaginary components act as a 2D vector Zo = Zo - zCM; % --------------------------------------------- check my centered initials figure(1); clf; axis equal % optional scatter(real(Zo),imag(Zo),75,'blue','filled'); figure(1); % --------------------------------------------- setting limits is optional %{ xMIN = min(real(Zo)); xMAX = max(real(Zo)); yMIN = min(imag(Zo)); yMAX = max(imag(Zo)); xMIN = xMIN - 0.5; xMAX = xMAX + 0.5; yMIN = yMIN - 0.5; yMAX = yMAX + 0.5; xlim( [xMIN,xMAX]); ylim( [yMIN,yMAX]); %} %error('stop here for now'); %% do translations % for i=1:5 dZ = input('enter dZ for translation: '); Znew = Zo + dZ; figure(1); clf; scatter(real(Zo),imag(Zo),100,[0.85,0.85,0.85],'filled'); hold on; scatter(real(Znew),imag(Znew),100,'blue','filled'); figure(1); end %} %% do rotations %{ for i=1:5 phi = input('enter phi for rotations (in degrees): '); phi = piphi/180; Zrot = exp(1iphi); Znew = ZrotZo; figure(1); clf; scatter(real(Zo),imag(Zo),100,[0.85,0.85,0.85],'filled'); hold on; scatter(real(Znew),imag(Znew),100,'blue','filled'); figure(1); end %} %% do general Z-multiplication %{ for i=1:5 disp('Enter Z as Rexp(iphi)'); R = input('enter R for magnitude of Z: '); phi = input('enter phi for rotations (in degrees): '); phi = piphi/180; Zmult = Rexp(1iphi); Znew = Zmult*Zo; figure(1); clf; scatter(real(Zo),imag(Zo),100,[0.85,0.85,0.85],'filled'); hold on; scatter(real(Znew),imag(Znew),100,'blue','filled'); figure(1); end %} - Assistant
% Transform Initials % What this MATLAB script does: % 1) Plots my initials using scatter() in the complex plane. % 2) Transforms initials using addition/multiplication of complex numbers % 3) get creative? %% initialize initials clear all % never not do this! % ----------------------------------------- % x= 012345678901234567890 % y=6 *** *** % 5 * * * % 4 * * * % 3 * *** % 28 pts total (by counting!) % 2 * * * % 1 * * * % 0 *** *** % x= 012345678901234567890 % ----------------------------------------- manually enter the coordinates npts = 6;
Zo = zeros(1,npts); % preallocate the Zo array % ------------------------- Zo( 1) = 3 + 1i0; Zo( 2) = 4 + 1i0; Zo( 3) = 5 + 1i0; Zo( 4) = 11 + 1i0; Zo( 5) = 12 + 1i0; Zo( 6) = 13 + 1i0; % ------------------------- Zo( 7) = 2 + 1i1; Zo( 8) = 11 + 1i1; Zo( 9) = 14 + 1i1; % ------------------------- Zo(10) = 0 + 1i2; Zo(11) = 11 + 1i2; Zo(12) = 14 + 1i2; % ------------------------- Zo(13) = 0 + 1i3; Zo(14) = 11 + 1i3; Zo(15) = 12 + 1i3; Zo(16) = 13 + 1i3; % ------------------------- Zo(17) = 0 + 1i4; Zo(18) = 11 + 1i4; Zo(19) = 14 + 1i4; % ------------------------- Zo(20) = 1 + 1i5; Zo(21) = 11 + 1i5; Zo(22) = 14 + 1i5; % ------------------------- Zo(23) = 2 + 1i6; Zo(24) = 3 + 1i6; Zo(25) = 4 + 1i6; Zo(26) = 11 + 1i6; Zo(27) = 12 + 1i6; Zo(28) = 13 + 1i6; % ---------------------------------------------- check my inputed initials figure(1); clf; scatter(real(Zo),imag(Zo),75,'red','square','filled','MarkerEdgeColor','black'); % Modified code figure(1); %error('stop here for now'); %% calculate center of mass and translate initials % ---------------------------- method 1 %xCM = mean(real(Zo)); %yCM = mean(imag(Zo)); %Zo = Zo - (xCM + 1iyCM); % ---------------------------- method 2 zCM = mean(Zo); % <= real & imaginary components act as a 2D vector Zo = Zo - zCM; % --------------------------------------------- check my centered initials figure(1); clf; axis equal % optional scatter(real(Zo),imag(Zo),75,'red','square','filled','MarkerEdgeColor','black'); % Modified code figure(1); % --------------------------------------------- setting limits is optional %{ xMIN = min(real(Zo)); xMAX = max(real(Zo)); yMIN = min(imag(Zo)); yMAX = max(imag(Zo)); xMIN = xMIN - 0.5; xMAX = xMAX + 0.5; yMIN = yMIN - 0.5; yMAX = yMAX + 0.5; xlim( [xMIN,xMAX]); ylim( [yMIN,yMAX]); %} %error('stop here for now'); %% do translations % for i=1:5 dZ = input('enter dZ for translation: '); Znew = Zo + dZ; figure(1); clf; scatter(real(Zo),imag(Zo),100,'red','square','filled','MarkerEdgeColor','black'); % Modified code hold on; scatter(real(Znew),imag(Znew),100,'blue','square','filled','MarkerEdgeColor','black'); % Modified code figure(1); end %} %% do rotations %{ for i=1:5 phi = input('enter phi for rotations (in degrees): '); phi = piphi/180; Zrot = exp(1iphi); Znew = ZrotZo; figure(1); clf; scatter(real(Zo),imag(Zo),100,[0.85,0.85,0.85],'filled'); hold on; scatter(real(Znew),imag(Znew),100,'blue','filled'); figure(1); end %} %% do general Z-multiplication %{ for i=1:5 disp('Enter Z as Rexp(iphi)'); R = input('enter R for magnitude of Z: '); phi = input('enter phi for rotations (in degrees): '); phi = piphi/180; Zmult = Rexp(1iphi); Znew = Zmult*Zo; figure(1); clf; scatter(real(Zo),imag(Zo),100,[0.85,0.85,0.85],'filled'); hold on; scatter(real(Znew),imag(Znew),100,'blue','filled'); figure(1); end %}