function MatExpo_mzip % MATLAB zip file, a self-extracting MATLAB archive. % Usage: Run this file to recreate the original directory. fname = mfilename; fin = fopen([fname '.m'],'r'); dname = fname(1:find(fname=='_',1,'last')-1); mkdir(dname); mkdir([dname filesep 'lib']) addpath(dname) addpath([dname filesep 'lib']) L = fgetl(fin); while length(L) < 2 || ~isequal(L(1:2),'%%') L = fgetl(fin); end while ~isequal(L,'%% EOF') F = [dname filesep L(4:end)]; disp(F) fout = fopen(F,'w'); L = fgetl(fin); while length(L) < 2 || ~isequal(L(1:2),'%%') fprintf(fout,'%s\n',L); L = fgetl(fin); end fclose(fout); end fclose(fin); end %% cspy.m function cspy(A,ms) % cspy(A) is spy(a) in living color. % cspy(A,ms) has markersize = ms. if nargin < 2 ms = 10; end cla co = get(gca,'colororder'); [m,n] = size(A); axis([0 m+1 0 n+1]) axis ij axis square axis padded box on set(gca,'xaxislocation','top') for k = 1:m for j = 1:n if A(k,j) ~= 0 line(j,k, ... 'linestyle','none', ... 'marker','.', ... 'markersize',ms, ... 'color',co(mod(floor(A(k,j)),7)+1,:)) end end end end %% fiedler.m function F = fiedler(a) % Fiedler companion matrix % F = fiedler(a) is the pentadiagonal Fiedler companion matrix of the % polynomial x^n + a(1)*x^(n-1) + a(2)*x^(n-2) + ... + a(n-1)*x + a(n). % F is n-by-n where n = length(a). % Miroslav Fiedler, Linear Algebra and its Applications 372 (2003), 325-331. % https://blogs.mathworks.com/cleve/2013/12/23/fiedler-companion-matrix/ % ex: F6 = % -a1 -a2 1 0 0 0 % 1 0 0 0 0 0 % 0 -a3 0 -a4 1 0 % 0 1 0 0 0 0 % 0 0 0 -a5 0 -a6 % 0 0 0 1 0 0 n = length(a); b = ones(n-2,1); b(1:2:n-2) = 0; c = -a(2:n); c(1:2:n-1) = 0; c(1) = 1; d = -a(2:n); d(2:2:n-1) = 0; e = ones(n-2,1); e(2:2:n-2) = 0; F = diag(b,-2) + diag(c,-1) + diag(d,1) + diag(e,2); F(1,1) = -a(1); end %% mat_expo.m function mat_expo(A,titl) % mat_expo(A,titl) displays six views of the matrix % A and its eigenvalues and singular values. % titl is the title of the entire display. % March 6, 2025. % Copyright 2015 MathWorks, Inc. A = full(double(A)); e = eig(A); [~,p] = sort(real(e),'descend'); e = e(p); s = svd(A); tiledlayout(2,3) nexttile cspy(A) nexttile surf(A); axis square axis padded view(45,45) titl(length(titl)+1:12) = ' '; title(titl, ... 'fontsize',14, ... 'horiz','center') nexttile surf(A); axis square axis padded view(135,45) nexttile plot(real(e),imag(e),'*','markersize',5,'linewidth',1) xlabel('real(e)') ylabel('imag(e)') axis square axis padded title('eig') nexttile [~,n] = size(A); plot(1:n,real(e),'.','markersize',10) xlabel('1:n') ylabel('real(e)') axis square axis padded title('real(eig)') nexttile plot(1:n,s,'.','markersize',10) xlabel('1:n') ylabel('sigma') axis square axis padded title('svd') end %% EOF