%-- 2/19/2025 10:31 AM --% ver bench %-- 2/21/2025 1:52 PM --% peaks paths path which sin which peaks type peaks edit peaks help plot doc plot x = 0:pi/10:2*pi; y1 = sin(x); y2 = sin(x-0.25); y3 = sin(x-0.5); figure plot(x,y1,'g',x,y2,'b--o',x,y3,'c*') ver demos %-- 2/24/2025 6:24 PM --% pwd %-- 2/28/2025 1:08 PM --% ver 1+1 path vibes edit vibes travel truss pwd ls echodemo m01 format compact whos x = [1 2 3 4] x = 1:5 sqrt(x) tic, sqrt(1:10^6); toc tic, sqrt(1:10^7); toc tic, sqrt(1:10^9); toc whos help realmin doc realmin help help complex realmax realmax*10 1/0 0/0 x=1:4 x x = [1 -i 1-i 2] x(1) x(2) x(3) x(1:2) x(1:4) whos x x(1:5) size(x) y = sin(x); plot(x,y) grid 1:5 3:1 3:-1:1 fliplr(1:5) 1:5 1:2:5 1:0.5:5 y x x = 1:10 y = x^2 y = x.^2 y(2:5) y([2 3 4 5]) y([3 3 6 5]) which linspace edit linspace log10(ans) 10^1.8 a a,b a(1:4)+b a,b a*b a.*b a a' a*b' a'*b a/b b/a b,a b./a a.\b a a.^2 a.**2 a**2 a, b 1 2 3; 4 5 6] z = [1 2 3; 4 5 6] g = [1 2 3 4 5 6 7 8 9] a, b [a;b] z = [a;b] z(1,3) z(1,;) z(1,:) zeros(4) zeros(4,3) rand(4) history hist history hist a'*b QUIT %-- 3/3/2025 5:14 PM --% ver pwd cdf .. cd .. pwd 1:5 x = 1:5 whos sin(x) x^2 x*x x x.*x x.^2 x' 1:5 1:2:9 b = 1:2:9 a.*b x.*b a,b,b./a x,b,b./x format compact help format doc format A = [1 2 3; 4 5 6 7 8 9] det(A) eps 1+eps/2 -1 1+eps -1 whos 1:10 linspace(1,10,10) linspace(1,10,2) linspace(1,2,20) x = linspace(0, 2*pi, 30); size(x) y = sin(x); plot(x,y) plot(x,y, '*-') grid plot(x,y, x,y.^2) xlabel('nezavisle promenna x' ylabel('zavisle promenna' title('2sin(x)cos(x) = sin(2x)') xlabel('nezavisle promenna x') ls dir doc plot a = 1:9 a>4 b=9-a a==b -3:3 x = (-3:3)/3 sin(x)./x 0/0 x = linspace(0, 2*pi, 30); x = linspace(0, pi/2, 30); plot(x,x, x,sin(x)) x = (-3:3)/3 x==0 xx = x + (x==0)*eps sin(xx)./xx a a>2 a<6 (a<6) & (a<2) (a<6) & (a>2) 100^400 realmax pwd discont type discont.m f01(2) 1:4 f01(1:4) edit Pi1 rand rand(2) rand(1,2) doc if Pi1(10) Pi1(10^5) Pi1(10^6) Pi1(10^7) 1:4 sum(1:4) Pi2(10^5) tic, Pi1(10^6), roc tic, Pi1(10^6), toc tic, Pi1(10^7), toc tic, Pi2(10^7), toc edit Pi_err.m Pi_err %-- 3/5/2025 5:43 PM --% PWD pwdpwd pwd doc hilb edit pi1 N=5; A=hilb(N), bar3(A*inv(A)) N=5; A=hilb(N); bar3(A*inv(A)) N=10; A=hilb(N); bar3(A*inv(A)) N=11; A=hilb(N); bar3(A*inv(A)) N=13; A=hilb(N); bar3(A*inv(A)) Pi2(1000) (Pi2(10^7)/pi-1) format compact tic, Pi1(10^5), toc tic, Pi1(10^7), toc tic, (Pi1(10^7)/pi-1), tpc tic, (Pi1(10^7)/pi-1), t0c tic, (Pi1(10^7)/pi-1), toc tic, (Pi1(10^8)/pi-1), toc tic, (Pi2(10^8)/pi-1), toc Pi_err hilb(4) doc hilb edit hilb det(hilb(4) det(hilb(4)) det(hilb(9)) det(hilb(20)) det(hilb(24)) det(hilb(28)) det(hilb(32)) A = [1 2 3; 4 5 6 7 8 0] det(A) b = [366; 804; 351] x=inv(A)*b A*x-b eps x=A\b A*x-b doc \ edit op_vs_inv.m op_vs_inv N=8, A =hilb(N); bar3(inv(A)&A) N=8, A =hilb(N); bar3(inv(A)*A) N=8, A =hilb(N); pcoloer(inv(A)*A) N=8, A =hilb(N); pcolor(inv(A)*A) N=11; A =hilb(N); pcolor(inv(A)*A), colorbar N=12; A =hilb(N); pcolor(inv(A)*A), colorbar N=13; A =hilb(N); pcolor(inv(A)*A), colorbar N=14; A =hilb(N); pcolor(inv(A)*A), colorbar N=14; A =hilb(N); bar3(inv(A)*A), colorbar N=12; A =hilb(N); bar3(inv(A)*A), colorbar ver Learning HDL Toolbox Version 24.1 (R2024a) Deep Learning Toolbox Version 24.1 (R2024a) Econometrics T %-- 3/7/2025 1:16 PM --% pwd sin(Pi) sin(pi) whos who format compact help format doc format clear 10^300 * 10^9 1+eps > 1 eps 1+eps/2 > 1 1+eps/2-1 1+eps-1 format long 1+eps-1 1+eps/2-1 sqrt(4) sqrt(-1) format short 0/0 doc imag sqrt(-1) imag(sqrt(-1)) conj(sqrt(-1)) help lookfor complex a=3, b=4 [1 3 5] [1,3,5] 1:5 1:2:5 x = 0:0.1:1 x = (0:0.1:1)*pi sin(Pi) sin(pi) sin([pi, pi/3 pi/4]) plot(x,sin(x)) plot(x,sin(x).'*-') plot(x,sin(x),'*-') grid b=1:2:9 size(b) b(2) b(6) b(1) 2:4 b, b(2:4) b([4 3 1 4 4]) 1:7 linspace(1,4,4) linspace(1,4,6) linspace(1,5,6) linspace(0,5,6) edit linspace xx = logspace(0,2,11) log10(xx) log(xx) a=1:5 b( = 1:2:9 b = 1:2:9 a sin(a) a a/2 a*2 a*b a,b a.*b b, b' a*b' a'*b a,b b/a b./a b./a, a.\b a sqrt(a) a.^2 a^a 2^a 2.^a a a' c=[1; 2; 3;4;5] c' g=[1 2 3; 4 5 6] g(2,3) g(2,1:3) g(2,:) g(1:end,2:end) zeros(3) zeros(2:4) zeros(2,4) ones(3) diaf(3) diag(3) diag(3,3) rand(4) A = rand(100,4); sum(1:4) doc ones sum(A) sum(A)/100 sum(rand(1000,5))/1000 sum(rand(10000,5))/10000 clear peaks %-- 3/10/2025 5:06 PM --% 1:9 format compact clc A = 1:9 A = reshape(A,3,3) A' rot90(A) rot90(A,-1) fliplr(rot90(A,-1)) rot90(A,2) rot90(A,3) A' A = A' det(A) eps A(3,3)=0 b = [366;804;352] det(A) x = inv(A)*b A*x-b doc \ x2 = A\b A*x2-b eig(A) V = eig(A) [V,D] = eig(A) hilb(4) hilb(3) hilb(4) det(hilb(4)) det(hilb(8)) det(hilb(20)) realmin det(hilb(22)) det(hilb(24)) det(hilb(28)) det(hilb(31)) det(hilb(30)) doc norm which norm edsit norm edit norm op_vs_inv N=5; A=hilb(N); pcolor(A*inv(A)), colorbar N=10; A=hilb(N); pcolor(A*inv(A)), colorbar N=12; A=hilb(N); pcolor(A*inv(A)), colorbar N=12; A=hilb(N); bar3(A*inv(A)), colorbar N=14; A=hilb(N); bar3(A*inv(A)) fh = @(N) A=hilb(N); bar3(A*inv(A)) fh = @(N) bar3(hilb(N)*inv(hiln(N))) fh(5) fh = @(N) bar3(hilb(N)*inv(hilb(N))) fh(5) fh(15) eps 1+eps >1 1+eps/2 >1 calc_eps EPS-eps EPS==eps num_dif grid num_dif2 clc x = linspace(0, 2*pi, 30); y = sin(x); z = cos(x); plot(x,y,x,z) grid xlabel( 'Independent Variable X') % x-axis label ylabel( 'Dependent Variables Y and Z') % y-axis label title(`Sine nad Cosine Curves') % title the plot title('Sine nad Cosine Curves') % title the plot text(2.5, 0.7, 'sin(x)') gtext('cos(x)') axis off axis on, grid off axis square figure(3) x = linspace(0, 2*pi, 30); y = sin(x); z = cos(x); plot(x,y) plot(x,z) hold on plot(x,y) hold off plot(x,y) which ezplot doc ezplot fplot('sin(x)/(1+x^2)') fplot(@(x) sin(x)./(1+x.^2)) fplot(@(x) sin(x)/(1+x.^2)) fplot(@sin) fplot(@sin. [0 10]) fplot(@sin, [0 10]) fplot(@sin^2, [0 10]) fplot(@sin*2, [0 10]) fplot(@(x) sin*2, [0 10]) fplot(@(x) sin.*2, [0 10]) fplot(@(x) sin(x)*2, [0 10]) fplot(@(x) sin(x).^2, [0 10]) ezplot('2*cos(t)','2*sin(t)') ezplot('2*cos(t)','2*sin(t)', [0 1.5*Pi]) ezplot('2*cos(t)','2*sin(t)', [0 1.5*pi]) fplot(@(t) 2*cos(t), @(t) 2*sin(t)), grid axis equal ezplot('x^2+y^2-4') axis([-2 2 -2 2]) axis equal fimplicit(@(x,y) x.^2 + y.^2 -4) fimplicit(@(x,y) x.^2 + y.^2 -4), grid, axis equal, axis([-3 3 -3 3]) ezpolar('sin(t)/t', [-6*pi,6*pi]) fplot(@(t) (sin(t)./t).*cos(t), @(t) (sin(t)./t).*sin(t), ... [-6*pi,6*pi], 'LineWidth', 2), grid h1 = fplot3( @(t) cos(2*pi*t), @(t) sin(2*pi*t), @(t) t,[0,4]) h1.LineWidth=3 h1.color=red h1.Color=[2 0 0] h1.Color=[1 0 0] h1.color=[1 0 0] QUIT %-- 3/12/2025 5:18 PM --% edit f401 edit f401_d num_dif grid figure(2) num_dif2 @(x) x^9 f1 = @(x) x^9 f1(2) f1([1 2]) f1 = @(x) x.^9 f1([1 2]) num_dif2 clc x = linspace(0, 2*pi, 30); clear x = linspace(0, 2*pi, 30); y = sin(x); z = cos(x); plot(x,y, x,z) plot(x,y, x,z, '*-') doc ezplot ezplot('x^2') ezplot('x^2', [-3, 5]) fplot('x^2', [-3, 5]) fplot('x.^2', [-3, 5]) fplot('x^2', [-3, 5]) fplot(@sin, [-3, 5]) fplot(@(x) sin(x)^2, [-3, 5]), grid fplot(@(x) sin(x).^2, [-3, 5]), grid fplot(@(t) 2*cos(t), @(t) 2*sin(t)), grid axis square fplot(@(t) 2*cos(t), @(t) 2*sin(t), t=[0, 3/2*pi]), grid fplot(@(t) 2*cos(t), @(t) 2*sin(t), [0, 3/2*pi]), grid fplot([@(t) 2*cos(t), @(t) 2*sin(t)], [0, 3/2*pi]), grid fplot({@(t) 2*cos(t), @(t) 2*sin(t)}, [0, 3/2*pi]), grid fimplicit(@(x,y) x.^2 + y.^2 -4) grid, axis square fplot(@(t) (sin(t)./t).*cos(t), @(t) (sin(t)./t).*sin(t), ... [-6*pi,6*pi], 'LineWidth', 2), grid h1 = [-6*pi,6*pi], 'LineWidth', 2), grid h1 = fplot3( @(t) cos(2*pi*t), @(t) sin(2*pi*t), @(t) t,[0,4]) h1.LineWidth = 2; get(h1 get(h1) h1.Color = [1 1 0] h1.ZFunction = @(x) sqrt(t) get(h1) h1.ZFunction = @(t) sqrt(t) doc dsolve which dsolve syms y(t) eq = diff(y(t),t)== y(t)+t format compact dsolve(eq) euler01_demo(0.1) euler01_demo(0.0.2) euler01_demo(0.02) h_vect = []; err_vect = []; h = 0.2; euler02_demo h euler02_demo loglog(h_vect, err_vect); xlabel('Step size'); ylabel('Maximum error'); grid loglog(h_vect, err_vect. '*-'); xlabel('Step size'); ylabel('Maximum error'); grid loglog(h_vect, err_vect, '*-'); xlabel('Step size'); ylabel('Maximum error'); grid h = 0.2; h_vect = []; eul_vect = []; rk2_vect = []; rk4_vect = []; rk01_demo rk01_demo loglog(h_vect, eul_vect, h_vect, rk2_vect, h_vect, rk4_vect); grid; %-- 3/14/2025 1:06 PM --% A = [6,12,4;7,-2,3;2,8,-9] format compact pwd m02 a=1:9, b=9-a a=4 a=1:9 a==4 whos tf = a>4 tf = a==b a,b (a>2) b-(a>2) b-(a>2)*3 x=(-3:3)/3 sin(x)/x a,b b./a x sin(x)./x 0/0 x==0 (x==0)*10^-10 eps 1+eps > 1 1+eps/2 > 1 (x==0)*eps x=x+(x==0)*eps format help format format long x format compact format short x x(4) x(4)==0 x(4)>0 sin(x)./x x=(-3:3)/3 sx = sin(x)./x isnan(sx) finite(sx) isfinite(sx) any(sx) any(x) doc any edit discont discont whos plot(x,y) discont hold on plot(x,y) plot(x,y, 'LineWidth',3) plot(x,y, 'LineWidth',3, Color, [0.8 0 0.8]) plot(x,y, 'LineWidth',3, 'Color', [0.8 0 0.8]) plot(x, cos(x)) figure(2) plot(x, cos(x)) plot(x,y, 'LineWidth',3, 'Color', [0.8 0 0.8]) hold on plot(x, cos(x)) grid hold off plot(x,y+1, 'LineWidth',3, 'Color', [0.8 0 0.8]) rand rand(3) rand(1,2) x = rand(1,2) x(1)^2+x(2)^2 <1 f01(2) f01(1:4) edit Pi1 which pi1 Pi1(10^4) Pi1(10^4)*4 Pi1(10^8) Pi1(10^6) abs(Pi1(10^6)/pi-1) abs(Pi1(10^7)/pi-1) tic. abs(Pi1(10^6)/pi-1), toc tic, abs(Pi1(10^6)/pi-1), toc tic, abs(Pi1(10^7)/pi-1), toc x=1:4 y = 5:8 x,x.^2 y, y.^2 x,y, x.^2 + y.^2 x sum(x) tic, abs(Pi2(10^7)/pi-1), toc tic, abs(Pi2(10^8)/pi-1), toc A = [1, 2, 3; 4 5 6; 7 8 0] size(A) det(A) b=[366; 804; 351) b=[366; 804; 351] x1 = inv(A)*b A*x1 A*x1-b x2=A\b A*x2-b det(A) [L, U] = lu(A) [L, U] =qr(A) eig(A) [V,D] = eig(A) zeros(4) ones(4) rand(3) M = magic(5) sum(M) M = magic(3) sum(M) M' sum(M') %-- 3/17/2025 5:07 PM --% fplot(@cos) fplot(@cos, [0 3*pi]) fplot(@(x) cos*x)^2, [0 3*pi]) fplot(@(x) cos(x), [0 3*pi]) fplot(@(x) cos(x)^2, [0 3*pi]) fplot(@(x) cos(x).^2, [0 3*pi]) fplot(@(x) cos(x)*sin(x), [0 3*pi]) fplot(@(x) cos(x).*sin(x), [0 3*pi]) fplot(@(x) [cos(x), sin(x)], [0 3*pi]) fplot(@(x) [cos(x), sin(x)], [0 3*pi], 'Color', [red blue]) fplot(@(x) [cos(x), sin(x)], [0 3*pi], 'Color', [[1 0 0], [0 0 1]]) h1 = fplot(@(x) [cos(x), sin(x)], [0 3*pi]) x = (0:1/2000:1)'; plot(x,cos(tan(pi*x))) plot(x,cos(tan(pi*x)), '*-') fplot( @(x) cos(tan(pi.*x)) ) fplot( @(x) cos(tan(pi.*x)), [0 1] ) fplot( @(x) cos(x), [0 3*pi]); [x,y] = fplot( @(x) cos(x), [0 3*pi]); clear [x,y] = fplot( @(x) cos(x), [0 3*pi]); plot(x,y, '-*') plot(y,x, '-*') x = 0:0.1:4*pi; z = [cos(x)' sin(x)' sin(x).^2']; plot(z) plot(x.z) plot(x,z) peaks edit peaks plot(peaks) plot(peaks(20)) plot(peaks, rot90(peaks')) X = peaks(7) plot(X) subplot(2,2,1) fplot(@sin) subplot(2,2,3) fplot(@tan) subplot(1,2,2) fplot(@cos) subplot(2,1,1) fplot(@cos) doc subplot fplot(@cos) figure peaks subplot(2,1,1) subplot(2,1,2) pe peaks which peaks figure(20) peaks figure(20) doc axis doc axes pwd path subplot_demo ginput_demo messgrid([-2:1:2]) mesgrid([-2:1:2]) meshgrid([-2:1:2]) [X,Y] = meshgrid([-2:1:2]) format compact clc format compact [X,Y] = meshgrid([-2:1:2]) X, flipud(Y) X.^2 Y, Y.^2 Z = exp(X.^2+ Y.^2) plot3(Z) surf(Z) Z = exp(-X.^2 - Y.^2) surf(Z) clear [X,Y] = meshgrid([-2:0.1:2]); Z = exp(-X.^2 - Y.^2); surf(X,Y,Z) colorbar colormap(hsv) colormap(hsv(10)) shading interp shading faceted colormap(jet) colormap(winter(32)) doc jet surf(X,Y,Z) colormap(jet) pcolor(X,Y,Z) colorb colorbar plot3(X,Y,Z) t=0:pi/50:10*pi; plot3(sin(t),cos(t),t) plot3(sin(t),cos(t),t.^2) x = -8:0.5:8; y = x; [X, Y] = meshgrid(x,y); R = sqrt(X.^2 + Y.^2) + eps; % distance from the origin (0,0) Z = sin(R)./R; % calculate sin(r)/r mesh(X,Y,Z) reshape(1:9,3,3) M = reshape(1:9,3,3) M(2,3) M(:) M' M2 = M' M2(:) M2(8) M2(5:8) M2, max(M2) M2, max(max(M2)) M2(:) max(M2(:)) axis([-8 8 -8 8 min(Z(:)) max(Z(:))]) view [az el] = view view(2) view(3) view(30, 20) view(30, 70) contour(peaks) contour(peaks,30) contour3(peaks,30) mesh(peaks(30)+7) hold on pcolor(peaks(30)) colorbar colomap(jet) colormap(jet) hold off pcolor(peaks(30)) surfl(peaks) colormap(grey) colormap(gray) shading interp surfc(peaks) colormap(jet) surfz(peaks) meshz(peaks) [X, Y] = meshgrid([-2:.2:2]); Z = X.* exp(-X.^2 - Y.^2); surfz(X,Y,Z) surf(X,Y,Z) Z = exp(-X.^2 - Y.^2); surf(X,Y,Z) Z = X.*exp(-X.^2 - Y.^2); surf(X,Y,Z) surf(Z) surf(X,Y,Z) surf(X,Y,Z, gradient(Z)) colorba colorbar surf(Z, gradient(Z)) P = peaks(40); C - del2(P) C = del2(P) surf(P,C) colormap(jet) colorb colorbar QUIT quitquit %-- 3/19/2025 5:09 PM --% ode45('0', [0 10], 1) ode45(@(x,y) 0, [0 10], 1) F1 = @(x,y) 0 format compact ode45(F1, [0 10], 1) [x,y] = ode45(F1, [0 10], 1); plot(x,y) ode45(@(x,y) t, [0 10], 1) ode23(@(t,y) t, [0 10], 1) ode23(@(t,y) y, [0 10], 1) ode23(@(t,y) -y, [0 10], 1) ode23(@(t,y) 1/(1-3*t), [0 10], 1) ode23(@(t,y) 1/(1-3.*t), [0 10], 1) ode23(@(t,y) 1./(1-3.*t), [0 10], 1) ode23s(@(t,y) 1./(1-3.*t), [0 10], 1) ode23s(@(t,y) 1./(1-3.*t), [1/3 10], 1) ode23s(@(t,y) 1./(1-3.*t), [1.01/3 10], 1) sin(sym(pi)), sin(pi) doc dsolve which subs doc subs ode23(@(t,y) [y(2); -y(1)], [0 3*pi], [0;1]), grid ode23(@(t,y) [y(2); -y(1)], [0 3*pi], [0;2]), grid ode23(@(t,y) [y(2); -y(1)], [0 3*pi], [0.5;2]), grid [t,y] = ode23(@(t,y) [y(2); -y(1)], [0 3*pi], [0;1]), grid [t,y] = ode23(@(t,y) [y(2); -y(1)], [0 3*pi], [0;1]); grid plot(t,y(:,1), t,y(:,2)) plot(t,y(:,1), t,y(:,2), '*-') plot(y(:,1), y(:,2), '*-') plot(y(:,1), y(:,2), '*-'), grid axis equal [t,y] = ode23(@(t,y) [y(2); -y(1)], [0 2*pi], [0;1]); grid plot(y(:,1), y(:,2), '*-'), grid, axis equal odeset [t y] = ode23(@(t,y) [y(2); -y(1)], [0 2*pi], [0;1], odeset('Refine', 2)); plot(y(:,1), y(:,2), '*-'), grid, axis equal [t y] = ode23(@(t,y) [y(2); -y(1)], [0 2*pi], [0;1]); [t y] = ode45(@(t,y) [y(2); -y(1)], [0 2*pi], [0;1]); plot(y(:,1), y(:,2), '*-'), grid, axis equal [t y] = ode23(@(t,y) [y(2); -y(1)], [0 2*pi], [0;1], odeset('Refine', 1)); plot(y(:,1), y(:,2), '*-'), grid, axis equal [t y] = ode23(@(t,y) [y(2); -y(1)], [0 2*pi], [0;1], odeset('Refine', 4)); [t y] = ode45(@(t,y) [y(2); -y(1)], [0 2*pi], [0;1], odeset('Refine', 4)); plot(y(:,1), y(:,2), '*-'), grid, axis equal [t y] = ode45(@(t,y) [y(2); -y(1)], [0 2*pi], [0;1]); [t y] = ode45(@(t,y) [y(2); -y(1)], [0 2*pi], [0;1], odeset('Refine', 1)); plot(y(:,1), y(:,2), '*-'), grid, axis equal [t y] = ode45(@(t,y) [y(2); -y(1)], [0 2*pi], [0;1]); plot(y(:,1), y(:,2), '*-'), grid, axis equal [t y] = ode45(@(t,y) [y(2); -y(1)], [0 2*pi], [0;1], odeset('Refine', 10)); plot(y(:,1), y(:,2), '*-'), grid, axis equal ode45(@(t,y) [y(2); -y(1)], [0 2*pi], [0;1]); sol = ode45(@(t,y) [y(2); -y(1)], [0 2*pi], [0;1]); sol = ode45(@(t,y) [y(2); -y(1)], [0 2*pi], [0;1]) sol = ode45(@(t,y) [y(2); -y(1)], [0 2*pi], [0;1]); plot(sol.x, sol.y(1,:) plot(sol.x, sol.y(1,:)) plot(sol.x, sol.y(1,:), '*-') sol = ode45(@(t,y) [y(2); -y(1)], [0 2*pi], [0;1], odeset('Refine',5); sol = ode45(@(t,y) [y(2); -y(1)], [0 2*pi], [0;1], odeset('Refine',5)); plot(sol.x, sol.y(1,:), '*-') sol sol = ode45(@(t,y) [y(2); -y(1)], [0 2*pi], [0;1], odeset('Refine',10)); sol doc odes3et doc odeset F = @(t,y) -100*y + 100*t +1 ode45(F, [0 1], 1) [t y] = ode45(F, [0 1], 1) [t y] = ode45(F, [0 1], 1); plot(t,y, '*-') figure(2) figure(3) ode15s(F, [0 1], 1); tic, ode15s(F, [0 1], 1); toc tic, ode45(F, [0 1], 1); toc [t,y] = ode15s(F, [0 1], 1); sol = ode15s(F, [0 1], 1); sol sol.stats ode01_demo ode02_demo_sym ode02_demo ode03_demo ode04_demo ode05_demo 100 10 ode05_demo 10 ode05_demo 5 stiff_demo stiff_demo02 %-- 3/21/2025 12:59 PM --% x=(0:0.1:1)*2*pi; x format compact x y = sin(x); z=cos(x); plot(x,y, '*-') plot(x,y, '*-r') grid plot(x,y, x,z) plot(x,y, x,z, 'r--x') xlabel( 'Independent Variable X') % x-axis label ylabel( 'Dependent Variables Y and Z') % y-axis label title(`Sine nad Cosine Curves') % title the plot title('Sine nad Cosine Curves') % title the plot grid text(2.5, 0.7, 'sin(x)') text(1.8, 0.4, 'cos(x)') gtext('cos(x)') axis off axis on x=(0:0.05:1)*2*pi; x=(0:0.02:1)*2*pi; plot(x,sin(x), x,cos(x), 'r--x') x = linspace(0, 2*pi, 30); y = sin(x); z=cos(x); plot(x,y) plot(x,z) hold on plot(x,y) grid plot(x, tan(x)) plot(x, tan(x), '*-') hold off plot(x,y) figure(2) plot(x,z, 'LineWidth', 3) plot(y,z) plot(y,z, '*-') axis equal; grid doc axis ezplot('sin(x)/(1+x^2)') fplot('sin(x)/(1+x^2)') doc ezplot fplot(@sin) edit num_dif f401(2) f401([1 2 4]) num_dif grid h h=10^-10 format long f401(1+h), f401(1) f401(1+h/10), f401(1) f401(1+h/10000), f401(1) f401(1+h/1000000), f401(1) f401(1+h*1000), f401(1) @(x) x.^2 ans(3) f1 = @(x) x.^2 f1(1:4) fplot(@f1) f1 fplot(f1) fplot(f1, [-2 3]) hold on fplot(@sin, [-2 3]) hold off fplot(@sin, [0 3*pi]) fplot(@(x) x^2, [-3 4]) x=1:3 x=1:4 x^2 x*x x, x.*x x, x.^x x, x.^2 fplot(@(x) x.^2, [-3 4]) fplot( @(x) sin(x)./(1+x.^2)), grid doc fplot fimplicit(@(x,y) x.^2+y.^2-4) axis equal, grid axis([-2.2 2.4 -2.1 1.8]) ezpolar('sin(t)/t', [-6*pi,6*pi]) fplot(@(t) (sin(t)./t).*cos(t), @(t) (sin(t)./t).*sin(t), ... [-6*pi,6*pi], 'LineWidth', 2), grid axis equal, grid fplot([@sin @cos]) fplot([@sin' @cos']) fplot([@(x) sin(x) @(x) cos(x)]) fplot([@(x) sin(x)' @(x) cos(x)']) fplot([@(x) [sin(x) cos(x)]) fplot(@(x) [sin(x) cos(x)]) fplot(@cos. [0 38pi]) fplot(@cos, [0 3*pi]) [x y] = fplot(@cos, [0 3*pi]); clear [x y] = fplot(@cos, [0 3*pi]); plot(x,y, '*-') figure(2) plot(x) plot(x, '*') x = (0:1/2000:1)'; plot(x, cos(tan(pi*x)) plot(x, cos(tan(pi*x))) plot(x, tan(pi*x)) plot(x*pi, tan(pi*x)) plot(x*pi, tan(pi*x), '*') fplot(@tan, [0 pi]) view([0 pi 0 10]) axis([0 pi 0 10]) axis([0 pi -100 10]) axis([0 pi -10 10]) grid fplot(@tan, [0 pi], '*') axis([0 pi -10 10]), grid fplot(@tan, [0 pi], '*-') axis([0 pi -10 10]), grid plot(x,cos(tan(pi*x))) fplot( @(x) cos(tan(pi.*x)) ) fplot( @(x) cos(tan(pi.*x)), [0 1] ) peaks colorbar off colorbar colormap jet doc colormap colormap hsv doc fsurf fsurf(@(x,y) sin(x).*cos(y)) fsurf(@(x,y) sin(x).*sin(y), [0 3*pi]) fsurf(@(x,y) sin(x).*abs(sin(y)), [0 3*pi]) fplot(exp(-x.^2) fplot(exp(-x.^2)) fplot(exp(-x.^2), [-3 3]) fplot(@(x) exp(-x.^2), [-3 3]) fsurf(@(x,y) exp(-(x.^2+y.^2)), [-3 3]) fsurf(@(x,y) exp(-(x.^2+y.^2)), [-2 2]) %-- 3/24/2025 5:06 PM --% peaks p = peaks; pcolor(p) p(35:40,25:30) p(35:40,25:30) = 0.1; surf(p) p(35:40,25:30) = NaN; surf(p) p(4,4) = NaN surf(p) doc quiver imag(Z) == 0 ~imag(Z) == 0 peaks colorbar colomaphot(8)) colomap(hot(8)) colormap(hot(8)) hot(8) edit hot edit mapa1 mapa1(3) edit mapa1 mapa1(3) doc linspace mapa1(3) mapa1(5) colormap(mapa1(8)) colormap(mapa1(20)) colormap(mapa1(32)) rgbplot(mapa1(32)) colormap(mapa1(32)) mapa1(5) colormap(mapa1(32)) peaks colormap(mapa1(32)) colorbar mapa1(5) plot(mapa1(32)) doc rgbplot edit rgbplot rgbplot(mapa1(32)) rgbplot(mapa1(32), '*') rgbplot(mapa1(64)), '*') rgbplot(mapa1(64)) peaks colormap(mapa1(32)) colorbar colormap(gray) figure(2) rgbplot(gray) new_gray = brighten(gray,0.5); rgbplot(newgray) rgbplot(new_gray) colormap(new_gray) edit brighten [1:17;1:17]' pcolor([1:17;1:17]') colormap(hsv(8)) colorbar caxis([-3 23]) caxis auto caxis([5 12]) hadamard_demo edit hadamard_demo hadamard(4) hadamard(8) hadamard(6) hadamard(4) which count.dat type count.dat pwd save clear cd .. load load('matlab.mat') clear load doc save clear load count.dat plot(count) plot(count, '*-') max(count) [mx, idx] = max(count) [mx, idx] = max(max(count)) M = reshape(1:9. 3,3) M = reshape(1:9, 3,3) M(:)' [mx, idx] = max(M(:))) [mx, idx] = max(M(:)) [mx, idx] = max(count(:)) size(count) doc std %-- 3/28/2025 1:09 PM --% x = (0:1:30:1**2*pi; x = (0:1:30:1)*2*pi; x = (0:1/30:1)*2*pi; y = sin(x); z=cos(x); plot(x,y) plot(x,y, x,z), grid plot(x,y, x,z, '*--m' ), grid axis off axis on axis tight axis([0 3/2*pi -1.2 0.8]) fplot('sin') fplot(f1) fplot(f01) fplot(@f01) fplot(@f01, [-3 3]) fplot(@sin, [-3 3]) fplot(@sin, [-3 3]), grid [x y] = fplot(@sin, [-3 3]), grid [x y] = fplot(@sin, [-3 3]) plot(x,y, '*') h1 = fplot(@sin, [-3 3]) h1.Color = [1 0 1] h1.LineWidtH = 3 h1.LineWidth = 3 h1.Marker = '*' doc marker h1.Function = @cos h1 fimplicit(@(x,y) x.^2 + y.^2 -4) axis equal grid fimplicit(@(x,y) x.^2 + y.^2 -3) hold('on') fimplicit(@(x,y) x.^2 + y.^2 -4) axis equal grid figure(3) hold off fplot(@(t) 2*cos(t), @(t) 2*sin(t)), grid axis equal fplot(@(t) 2*cos(t), @(t) 2*sin(t), [0 3/2*pi]) fplot(@(t) 2*cos(t), @(t) 2*sin(t), [0.2 3/2*pi]) axis equal fplot([@(t) 2*cos(t), @(t) 2*sin(t)], [0.2 3/2*pi]) fplot([@(t) cos(t'), @(t) sin(t')], [0.2 3/2*pi]) fplot({@(t) cos(t), @(t) sin(t)}, [0.2 3/2*pi]) fplot({@(t) cos(t), @(t) sin(t), @tan}}, [0.2 2*pi]) fplot({@(t) cos(t), @(t) sin(t), @tan}, [0.2 2*pi]) ylim([-3 3]) @(x) x^2 ans(4) format compact f2 = @(x) x^2 f2(3) f2([3 4 5]) x=[3 4 5] x^2 x*x x.*x x.2 x.^2 f2 = @(x) x.^2 f2([3 4 5]) fplot(f2) rand(5) A = rand(5) fplot(@(x) exp(-x^2)) fplot(@(x) exp(-x^2), -3 3]) fplot(@(x) exp(-x.^2), [-3 3]) fsurf(@(x,y) exp(-x.^2-y^.2), [-3 3]) fsurf(@(x,y) exp(-x.^2-y^.2), [-3 3 -3 3]) fsurf(@(x,y) exp(-x.^2-y^.2)) fsurf(@(x,y) exp(-x.^2-y.^2)) fsurf(@(x,y) exp(-x.^2-y.^2), [-3 3]) fsurf(@(x,y) x.*exp(-x.^2-y.^2), [-3 3]) colorbar off colorbar colormap(hsv) colormap(hsv(10)) hsv(10) doc hsv fmesh(@(x,y) x.*exp(-x.^2-y.^2), [-3 3]) fsurf(@(x,y) x.*exp(-x.^2-y.^2), [-3 3]) shading flat shading faceted shading interp peaks peaks(20) edit peaks x=-2:1:2 meshgrid(x) meshgrid(x,x) [X,Y] = meshgrid(x,x) exp(-X.2-Y.^2) exp(-X.^2-Y.^2) Z = exp(-X.^2-Y.^2) surf(Z) surf(X,Y,Z) [X,Y] = meshgrid(-2:0.1:2); Z = exp(-X.^2-Y.^2) surf(X,Y,Z) plot3X,Y,Z) plot3(X,Y,Z) x = 0:0.1:4*pi; plot(x, cos(x)) plot(x, [cos(x)' sin(x)']) 1:5 (1:5)' plot(x, [cos(x)' sin(x)' tan(x')]) axis([0 4*pi -2 2]) t=0:pi/50:10*pi; plot3(sin(t), cos(x), t) plot3(sin(t), cos(t), t) plot3(sin(t), cos(t), sqrt(t)) dcc plo3 dcc plot3 doc plot3 h1 = plot3(sin(t), cos(t), sqrt(t)) h1.LineWidth = 3 surf(X,Y,Z) view [az el] = view pcolor(X,Y,Z) colorbar colormap(hsv(10) colormap(jet) pcolor(surf(150) pcolor(surf(15)) pcolor(surf(20)) pcolor(surf(20,20)) pcolor(peaks(20) pcolor(peaks(20)) shading flat shading faceted shading interp [X, Y] = meshgrid([-2:.2:2]); Z = X.* exp(-X.^2 - Y.^2); surf(X, Y, Z) colorbar surf(X, Y, Z, gradient(Z)) colorbar [X, Y] = meshgrid([-3:.2:3]); Z = X.* exp(-X.^2 - Y.^2); surf(X, Y, Z, gradient(Z)) colorbar surf(X, Y, Z, del2(Z)) colorbar QUIT %-- 3/31/2025 4:11 PM --% pwd cd uvp edit kostka1 kostka1(600) k = kostka1(600) bar(k) bar(k), grid k = kostka1(6000) bar(k), grid tic, k = kostka1(6000); toc tic, k = kostka1(6*10^5); toc tic, k = kostka1(6*10^6); toc k format compact k doc randi tic, k = kostka1(6*10^3); toc k bar(k), grid tic, k = kostka1(6*10^6); toc tic, k = kostka2(6*10^3); toc k tic, k = kostka2(6*10^6); toc rnd = randi(10) rnd = randi(10,1,10) rnd = randi(6,1,10) rnd == 1 sum(rnd == 1) tic, k = kostka3(6*10^3); toc k tic, k = kostka3(6*10^6); toc bar(k), grid ylim([10^5 5*10^6]) ylim([10^5 1.2*10^6]) k ylim([min(k)-100 max(k)+100]) clc clear x = (0:0.1:1)*2*pi; y = sin(x); plot(x,y, '*--' plot(x,y, '*--') plot(x,y, '*--'), grid xi = (0:0.02:1)*2*pi; yi = interp1(x,y, xi); plot(x,y, '*--', xi,yi,'o'), fplot(@sin, [0 2*pi]);grid plot(x,y, '*--', xi,yi,'o'), hold on, fplot(@sin, [0 2*pi]);grid yi = interp1(x,y, xi, 'cubic'); plot(x,y, '*--', xi,yi,'o'), hold on, fplot(@sin, [0 2*pi]);grid plot(x,y, '*--', xi,yi,'o'), hold on, fplot(@sin, [0 2*pi]);grid, hold off plot(x,y, '*--', xi,yi,'o'), hold on, fplot(@sin, [0 2*pi]);grid doc interp1 [x, y] = meshgrid(-3:1:3); z = peaks(x,y); surf(x,y,z) hold off surf(x,y,z) [xi, yi] = meshgrid(-3:0.25:3); zi1 = interp2(x,y,z,xi,yi, 'nearest'); surf(xi,yi,zi) surf(xi,yi,zi1) zi2 = interp2(x,y,z,xi,yi, 'bilinear'); surf(xi,yi,zi2) zi3 = interp2(x,y,z,xi,yi, 'bicubic'); surf(xi,yi,zi3) peaks humps plot(humps) doc humps edit humps h1 = fplot(@humps, [-2 3]), grid, h1.LineWidth=2 fzero(@humps, -0.2) humps(ans) fzero(@humps, -2) fzero(@humps, 9) fzero(@humps, 2) fzero(@humps, 0.5) fzero(@sin, 1) fzero(@sin, 2) plot(@sin, [0 4*pi]) fplot(@sin, [0 4*pi]) grid fzero(@sin, 5) fzero(@sin, 5) - 2*pi fzero(@sin, 4.5) - 2*pi fzero(@sin, 4.5) h1 = fplot(@humps, [-2 3]), grid, h1.LineWidth=2 x = fminbnd(@humps, 0.3, 1) x = fminbnd(@humps, 1, 3) doc fminbnd fminbnd(@(x) -humps(x), -1, 2) x = fminbnd(@(x) -humps(x), -1, 2) humps(x) x = fminbnd(@(x) -humps(x), 0.5, 1.5) humps(x) integral(@sin, 0,2*pi) integral(@(x) sin(x)^2, 0,2*pi) integral(@(x) sin(x).^2, 0, 2*pi) doc inegral doc integral x=(0:0.05:1)*2*pi x=(0:0.05:1)*2*pi; plot(x,sin(x), '*-') y = sin(x) doc quad trapz(x,y) int(@sin, [0 2*pi]) int(@sin, 0,2*pi) doc int which int syms x sin(pi) sin(sym(pi)) syms x clear syms x int(sin(x),0,pi) int(sin(x),0,2*pi) %-- 4/2/2025 4:22 PM --% edit cube1 rand(600) cube1(600) su,(ans) c1 = cube1(600) sum(c1) bar(c1) tic. c1 = cube1(6*10^6), toc format compact ba tic, c1 = cube1(6*10^6), toc clear tic, c1 = cube1(6*10^6), toc bar(c1), grid ylim([min(c1)-10, max(c1)+10)]) ylim([min(c1)-10, max(c1)+10]) ylim([min(c1)-50, max(c1)+50]) tic, c1 = cube2(6*10^6), toc tic, c2 = cube2(6*10^6), toc sum(c2) r1 = randi(10) r1 = randi(6,1,10) r1=1 r1 = randi(6,1,10) r1==1 sum(r1==1) sum(r1==2) tic, c3 = cube3(6*10^6), toc sum(c3) bar(c3), grid ylim([min(c3)-50, max(c3)+50]) min(c3), max(c3 min(c3), max(c3) min(c3)/max(c3) x=(0:0.1:1)*2*pi y = sin(x); plot(x,y, '*-') h1 = plot(x,y, '*-') h1.LineWidth = 2 hold on, fplot(@sin, [0 2*pi]) grid, axis([0 2*pi -1.1 1.1] ) x1 =(0:0.025:1)*2*pi; y1 = interp1(x,y, x1); hold off plot(x,y, '*-', x1,y1, 'o') y1 = interp1(x,y, x1, 'cubic'); plot(x,y, '*-', x1,y1, 'o') hold on, fplot(@sin, [0 2*pi]) doc interp1 y1 = interp1(x,y, x1, 'spline'); hold off plot(x,y, '*-', x1,y1, 'o') hold on, fplot(@sin, [0 2*pi]) peaks [x, y] = meshgrid(-3:1:3) z = peaks(x.y); z = peaks(x,y); surf(x,y,z) [xi, yi] = meshgrid(-3:0.25:3); zi1 = interp2(x,y,z,xi,yi, 'nearest'); surf(xi,yi,zi1) zi2 = interp2(x,y,z,xi,yi, 'bilinear'); surf(xi,yi,zi2) zi3 = interp2(x,y,z,xi,yi, 'bicubic'); surf(xi,yi,zi3) doc interp2 zi3 = interp2(x,y,z,xi,yi, 'spline'); surf(xi,yi,zi3) figure(2) surf(x,y,z) x=(0:0.1:1)*2*pi y=sin(x); h1 = plot(x,y, '*-') grid which spline p1 = [2 2] y1 = polyval(p1, x); plot(x,y1, '*-') y1 = polyval([1 0 2], x); plot(x,y1, '*-') edit polyval p = [1 0 -2 -5]; polyder(p) g = [1 1 1 1 1] polyder(g) roots(p) r = r = roots(p) polyval(r) polyval(p. r) polyval(p, r) poly(r) which data1 which data1.asc x = [0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1]; y = [-.447 1.978 3.28 6.16 7.08 7.34 7.66 9.56 9.48 9.30 11.2]; plot(x,y, '*-') p2 = polyfit(x,y,2) xi = linspace(0,1,100); yi = polyval(p,xi); plot(x,y,'o',x,y,xi,yi,'--'); yi = polyval(p2,xi); plot(x,y,'o',x,y,xi,yi,'--'); plot(x,y,'o-', xi,yi,'--'); size(x) p10 = polyfit(x,y,10) yi = polyval(p10,xi); plot(x,y,'o-', xi,yi,'--'); xi = linspace(-0.1,1.1,100); yi = polyval(p10,xi); plot(x,y,'o-', xi,yi,'--'); ver %-- 4/4/2025 12:14 PM --% rand(3) rand(1,5) format compact doc rand rand(6,1,10) randi(6,1,10) edit kostka1 zeros(2,3) zeros(1,6) kostka1(5) k1 = kostka1(600) sum(k1) doc bar bar(k1) [imin, mn] = min(k1) max(k1) tic, k1 = kostka1(6*10^6), toc tic, k1 = kostka1(6*10^6); toc bar(k1), grid fplot(@sin, [0 2*pi]) axis([-0.2 2*pi-1 -1.1 0.8] axis([-0.2 2*pi-1 -1.1 0.8]) bar(k1), grid ylim([min(k1) max(k1)]) ylim([min(k1)-50 max(k1)+50]) k2 = kostka2(600) sum(k2) tic, k2 = kostka1(6*10^6); toc tic, k2 = kostka2(6*10^6); toc tic, k2 = kostka1(6*10^6); toc randi(6,1,16) r = randi(6,1,16) r = randi(6,1,8) r == 1 sum(ans) r r == 3 sum(ans) kostka3(600) sum(ans) k3 = kostka3(600) bar(k3), grid tic, k3 = kostka3(6*10^6); toc bar(k3), grid ylim([min(k3)-50 max(k3)+50]) pwd save whos clear whos load whos save k1, k2, r clear load k1 doc save save(d1, k1,k3,r) save("d1", k1,k3,r) save('d1', k1,k3,r) save('d1', 'k1','k3','r') clear load d1 which count.dat path which count.dat edit count.dat clear load count.dat whos size(count) [n, p] = size(count) plot(count) grid legend count(2,:) plot(count(:,1)) plot(count(:,1), '*--') plot(count(1:2,1)) plot(count(:,1:2)) plot(count(:,:)) grid max(count) men(count) mean(count) max(count) max(max(count)) [idx mx] = max(count) [mx idx] = max(count) randi(3) randi(10,3) r = randi(10,3) max(r) r(:) max(r(:)) [mx idx] = max(r(:)) x = (0:0.1:1)*2*Pi x = (0:0.1:1)*2*pi y = sin(y); y = sin(x); plot(x,y, '*--'), grid, hold on, fplot(@sin, [0 2*pi]) doc interp1 interp1(x,y, 4.75) interp1(x,y, [4.75, 4.25]) xi = (0:0.02:1)*2*pi; yi = interp1(x,y, xi); plot(xi,yi, 'o') plot(xi,yi, 'ok') yic = interp1(x,y, xi, 'cubic'); plot(xi,yic, 'mx') yis = interp1(x,y, xi, 'spline'); plot(xi,yic, '^c') %-- 4/7/2025 4:07 PM --% x = 1:3 y = sin(x) save clear load doc load clear a = -5:0.25:6; b = a.^2.5; save('pokus.data') whos a1 = a; b1=b1 whos b1=b whos clear a b load "pokus.data" load 'pokus.data' load('pokus.data') load pokus.data load(pokus.data) save('pokus.data','a','b','-ascii','-double') save('pokus.data','a1','b1','-ascii','-double') save('pokus.data','a1','b1','-ascii','-single') load(pokus.data) load('pokus.data') cd .. clear imread('slon.pgm') I = imread('slon.pgm'); imshow(I) imshow(flipud(I)) imshow(fliplr(I)) imshow(rot90(I)) imshow(rot90(I,2)) imshow(I(end:-1:1,:)) imshow(I(1:2:end,:)) imshow(I(1:2:end,1:2:end)) I = imread('slon.jpg'); imshow(I(:,:,1)) imshow(I(:,:,2)) imshow(I(:,:,3)) imshow(I(:,:,:)) imshow(I) I2 = I(1:2:end,1:2:end,:); imshow(I2) I3(:,:,3) = I(:,:,,3)./2; I3 = I; I3(:,:,3) = I(:,:,,3)./2; I3(:,:,3) = I(:,:,3)./2; imshow(I3) I3(:,:,3) = 0 imshow(I3) I3(:,:,3) = 200; imshow(I3) I3(:,:,3) = 100; imshow(I3) I3(:,:,3) = 250; imshow(I3) doc imshow which mri.mat ver which imagesc doc imagesc I = imread('slon.pgm'); imshow(I) Is - size(I) Is = size(I) I2 = zeros(2*Is); size(I2) A = resize(1:9,3,3) doc resize A = reshape(1:9,3,3) A2 = zeros(6,6) A2(1:2:end,1:2:end) = A I2(1:2:end,1:2:end) = I; imshow(I2) shading flat I2(2:2:end,1:2:end) = I; I2(:,2:2:end) = I2(I,1:2:end); I2(:,2:2:end) = I2(:,1:2:end); imshow(I2) I3 = cast(I2,'uint8'); imshow(I2) imshow(I3) doc imagesc doc imresizer I4 = imresize(I,2); figure(2), imshow(I4) a = [1 0 -2 -5] format compact polyval(a, 1) fplot(@(x) polyval(a,x), [-3 3]) a2 = [1 0 0]; fplot(@(x) polyval(a2,x), [-3 3]) xi = linspace(-2,2,50); y = polyval(s2,xi); y = polyval(a2,xi); plot(xi,y, '*-') a polyder(a) roots(a) r = roots(a) p2 = poly(r) p-p2 a-p2 doc polyval edit polyval QUIT %-- 4/10/2025 2:46 PM --%