2015年6月13日 星期六

使用MuPAD繪製Trigonometric Function

>> mupad

plot::easy(sin(x), [PI/2,1])

plot(sin(x), [PI/2,1], #x=PI/2, #y=0.5)




f1 := plot::Function2d(sin(x), x = 0..2*PI, Color = RGB::Blue);
f2 := plot::Function2d(cos(x), x = 0..2*PI, Color = RGB::Green)

plot(f1, f2)


f1 := plot::Function2d(tan(x), x = -PI..PI, Color = RGB::Blue);


plot(f1)


f1 := plot::Function2d(cot(x), x = -PI..PI, Color = RGB::Blue);

plot(f1)


f1 := plot::Function2d(sec(x), x = -PI..PI, Color = RGB::Black);

plot(f1)

f1 := plot::Function2d(csc(x), x = -PI..PI, Color = RGB::Yellow);

plot(f1)




2015年6月4日 星期四

Plot -- Inverse Trigonometric Function

%========================================
% sin^-1(x)
%========================================
close all
figure,
x=-pi:0.1:pi;
y=sin(x);
plot(x,y,'--b')
x=[-pi/2:0.1:pi/2 pi/2];
y=sin(x);
hold on
plot(x,y,'b','LineWidth',3)
hold off
axis([-3.5 3.5 -1.5 1.5])
line( [0 0], [-1.5 1.5], 'color', 'm');
line( [-3.5 3.5], [0 0], 'color', 'm');
line( [-pi/2 -pi/2], [-1.05 0.05], 'color', 'r');
line( [pi/2 pi/2], [-0.05 1.05], 'color', 'r');
gtext('\fontname{Times New Roman}\fontsize{14}{\itx}')
gtext('\fontname{Times New Roman}\fontsize{14}{\ity}')
gtext('(0,0)')
gtext('\fontname{Times New Roman}\fontsize{10}\rm-{\it\pi} /2')
gtext('\fontname{Times New Roman}\fontsize{10}\rm{\it\pi} /2')
gtext('\fontname{Times New Roman}\fontsize{10}\rm(-{\it\pi} /2,-1)')
gtext('\fontname{Times New Roman}\fontsize{10}\rm({\it\pi} /2,1)')
gtext('\fontname{Times New Roman}\fontsize{14}{\itf}\rm({\itx}) = sin\itx')

x=-pi:0.1:pi;
y=sin(x);
figure, plot(x,y,'--b')
x=[-pi/2:0.1:pi/2 pi/2];
y=sin(x);
hold on
plot(x,y,'b','LineWidth',3)
x=-1:0.1:1;
y=asin(x);
plot(x,y,'g','LineWidth',3)
x=-2:0.1:2;
y=x;
plot(x,y,'--c')
hold off
axis([-2 2 -2 2])
line( [0 0], [-2 2], 'color', 'm');
line( [-2 2], [0 0], 'color', 'm');
line( [-pi/2 -pi/2], [-1.05 0.05], 'color', 'r');
line( [-1 -1], [-pi/2-0.05 0.05], 'color', 'b');
line( [pi/2 pi/2], [-0.05 1.05], 'color', 'r');
line( [1 1], [-0.05 pi/2+0.05], 'color', 'b');
line( [-1.05 0.05], [-pi/2 -pi/2], 'color', 'b');
line( [-0.05 1.05], [pi/2 pi/2], 'color', 'b');
gtext('\fontname{Times New Roman}\fontsize{12}{\itx}')
gtext('\fontname{Times New Roman}\fontsize{12}{\ity}')
gtext('(0,0)')
gtext('\fontname{Times New Roman}\fontsize{10}\rm-{\it\pi} /2')
gtext('\fontname{Times New Roman}\fontsize{10}\rm{\it\pi} /2')
gtext('\fontname{Times New Roman}\fontsize{10}\rm(-{\it\pi} /2,-1)')
gtext('\fontname{Times New Roman}\fontsize{10}\rm({\it\pi} /2,1)')
gtext('\fontname{Times New Roman}\fontsize{12}{\itf}\rm({\itx}) = sin\itx')
gtext('\fontname{Times New Roman}\fontsize{10}\rm-{\it\pi} /2')
gtext('\fontname{Times New Roman}\fontsize{10}\rm{\it\pi} /2')
gtext('\fontname{Times New Roman}\fontsize{10}\rm(-1,-{\it\pi} /2)')
gtext('\fontname{Times New Roman}\fontsize{10}\rm(1,{\it\pi} /2)')
gtext('-1')
gtext('1')
gtext('\fontname{Times New Roman}\fontsize{12}{\itf}\rm({\itx}) = sin^{-1}\itx')



%========================================
% cos^-1(x)
%========================================
close all
figure,
x=-pi/2:0.1:3*pi/2;
y=cos(x);
plot(x,y,'--b')
x=[0:0.1:pi pi];
y=cos(x);
hold on
plot(x,y,'b','LineWidth',3)
hold off
axis([-0.5 3.5 -1.5 1.5])
line( [0 0], [-1.5 1.5], 'color', 'm');
line( [-3.5 3.5], [0 0], 'color', 'm');
line( [-0.5 0.05], [1 1], 'color', 'r');
line( [pi pi], [-1.05 0.05], 'color', 'r');
line( [pi/2 pi/2], [-0.05 0.05], 'color', 'r');
gtext('\fontname{Times New Roman}\fontsize{12}{\itx}')
gtext('\fontname{Times New Roman}\fontsize{12}{\ity}')
gtext('(0,0)')
gtext('\fontname{Times New Roman}\fontsize{10}\rm{\it\pi} /2')
gtext('\fontname{Times New Roman}\fontsize{10}\rm{\it\pi}')
gtext('(0,1)')
gtext('\fontname{Times New Roman}\fontsize{10}\rm({\it\pi},-1)')
gtext('\fontname{Times New Roman}\fontsize{12}{\itf}\rm({\itx}) = cos\itx')
x=-2:0.1:3*pi/2;
y=cos(x);
figure, plot(x,y,'--b')
x=[0:0.1:pi pi];
y=cos(x);
hold on
plot(x,y,'b','LineWidth',3)
x=-1:0.1:1;
y=acos(x);
plot(x,y,'g','LineWidth',3)
x=-2:0.1:4;
y=x;
plot(x,y,'--c')
hold off
axis([-2 4 -2 4])
line( [0 0], [-2 4], 'color', 'm');
line( [-2 4], [0 0], 'color', 'm');
line( [-2 0.1], [1 1], 'color', 'r');
line( [pi pi], [-1.1 0.1], 'color', 'r');
line( [pi/2 pi/2], [-0.1 0.1], 'color', 'r');
line( [-0.1 0.1], [pi/2 pi/2], 'color', 'r');
line( [-2 -0.9], [pi pi], 'color', 'b');
line( [-1 -1], [-0.1 pi+0.1], 'color', 'b');
line( [1 1], [-0.1 0.1], 'color', 'b');
gtext('\fontname{Times New Roman}\fontsize{12}{\itx}')
gtext('\fontname{Times New Roman}\fontsize{12}{\ity}')
gtext('(0,0)')
gtext('-1')
gtext('1')
gtext('\fontname{Times New Roman}\fontsize{10}\rm({\it\pi} /2,0)')
gtext('\fontname{Times New Roman}\fontsize{10}\rm{\it\pi}')
gtext('\fontname{Times New Roman}\fontsize{10}\rm({\it\pi},-1)')
gtext('\fontname{Times New Roman}\fontsize{10}\rm(-1,{\it\pi})')
gtext('\fontname{Times New Roman}\fontsize{10}\rm(0,{\it\pi} /2)')
gtext('\fontname{Times New Roman}\fontsize{12}{\itf}\rm({\itx}) = cos\itx')
gtext('\fontname{Times New Roman}\fontsize{12}{\itf}\rm({\itx}) = cos^{-1}\itx')



%========================================
% tan^-1(x)
%========================================
close all
figure,
x=[-pi/2+0.05:0.1:pi/2];
y=tan(x);
plot(x,y,'b','LineWidth',3)
axis([-10 10 -10 10])
line( [0 0], [-10 10], 'color', 'm');
line( [-10 10], [0 0], 'color', 'm');
line( [-pi/2 -pi/2], [-10 0.2], 'color', 'r');
line( [pi/2 pi/2], [-0.2 10], 'color', 'r');
gtext('\fontname{Times New Roman}\fontsize{12}{\itx}')
gtext('\fontname{Times New Roman}\fontsize{12}{\ity}')
gtext('(0,0)')
gtext('\fontname{Times New Roman}\fontsize{10}\rm-{\it\pi} /2')
gtext('\fontname{Times New Roman}\fontsize{10}\rm{\it\pi} /2')
gtext('\fontname{Times New Roman}\fontsize{12}{\itf}\rm({\itx}) = tan\itx')
x=[-pi/2+0.05:0.1:pi/2];
y=tan(x);
figure, plot(x,y,'b','LineWidth',3)
hold on
x=-10:0.1:10;
y=atan(x);
plot(x,y,'g','LineWidth',3)
x=-10:0.1:10;
y=x;
plot(x,y,'--c')
hold off
axis([-10 10 -10 10])
line( [0 0], [-10 10], 'color', 'm');
line( [-10 10], [0 0], 'color', 'm');
line( [-pi/2 -pi/2], [-10 0.2], 'color', 'r');
line( [pi/2 pi/2], [-0.2 10], 'color', 'r');
line( [-10 0.2], [-pi/2 -pi/2], 'color', 'b');
line( [-0.2 10], [pi/2 pi/2], 'color', 'b');
gtext('\fontname{Times New Roman}\fontsize{12}{\itx}')
gtext('\fontname{Times New Roman}\fontsize{12}{\ity}')
gtext('(0,0)')
gtext('\fontname{Times New Roman}\fontsize{10}\rm-{\it\pi} /2')
gtext('\fontname{Times New Roman}\fontsize{10}\rm{\it\pi} /2')
gtext('\fontname{Times New Roman}\fontsize{12}{\itf}\rm({\itx}) = tan\itx')
gtext('\fontname{Times New Roman}\fontsize{10}\rm-{\it\pi} /2')
gtext('\fontname{Times New Roman}\fontsize{10}\rm{\it\pi} /2')
gtext('\fontname{Times New Roman}\fontsize{12}{\itf}\rm({\itx}) = tan^{-1}\itx')




%========================================
% cot^-1(x)
%========================================
close all
figure,
x=[0.05:0.1:pi];
y=cot(x);
plot(x,y,'b','LineWidth',3)
axis([-10 10 -10 10])
line( [0 0], [-10 10], 'color', 'm');
line( [-10 10], [0 0], 'color', 'm');
line( [pi pi], [-10 0.2], 'color', 'r');
line( [pi/2 pi/2], [-0.2 0.2], 'color', 'r');
gtext('\fontname{Times New Roman}\fontsize{12}{\itx}')
gtext('\fontname{Times New Roman}\fontsize{12}{\ity}')
gtext('(0,0)')
gtext('\fontname{Times New Roman}\fontsize{10}\rm{\it\pi} /2')
gtext('\fontname{Times New Roman}\fontsize{10}\rm{\it\pi}')
gtext('\fontname{Times New Roman}\fontsize{12}{\itf}\rm({\itx}) = cot\itx')
x=[0.05:0.1:pi];
y=cot(x);
figure, plot(x,y,'b','LineWidth',3)
hold on
x=-10:0.1:-0.1;
y=acot(x)+pi;
x2=0:0.1:10;
y=[y acot(x2)];
plot([x x2],y,'g','LineWidth',3)
x=-10:0.1:10;
y=x;
plot(x,y,'--c')
hold off
axis([-10 10 -10 10])
line( [0 0], [-10 10], 'color', 'm');
line( [-10 10], [0 0], 'color', 'm');
line( [pi pi], [-10 0.2], 'color', 'r');
line( [-10 0.2], [pi pi], 'color', 'b');
gtext('\fontname{Times New Roman}\fontsize{12}{\itx}')
gtext('\fontname{Times New Roman}\fontsize{12}{\ity}')
gtext('(0,0)')
gtext('\fontname{Times New Roman}\fontsize{10}\rm{\it\pi}')
gtext('\fontname{Times New Roman}\fontsize{12}{\itf}\rm({\itx}) = cot\itx')
gtext('\fontname{Times New Roman}\fontsize{10}\rm{\it\pi}')
gtext('\fontname{Times New Roman}\fontsize{12}{\itf}\rm({\itx}) = cot^{-1}\itx')




%========================================
% sec^-1(x) ------nonunique
%========================================
close all
figure,
x=[-pi/2+0.05:0.1:pi/2-0.05];
y=sec(x);
plot(x,y,'--b')
hold on
x3 = x-3*pi;  y=sec(x3);  plot(x3,y,'--b')
x2 = x-2*pi;  y=sec(x2);  plot(x2,y,'--b')
x1 = x-pi;    y=sec(x1);  plot(x1,y,'--b')
x3 = x+3*pi;  y=sec(x3);  plot(x3,y,'--b')
x2 = x+2*pi;  y=sec(x2);  plot(x2,y,'--b')
x1 = x+pi;    y=sec(x1);  plot(x1,y,'--b')
x=[0:0.1:pi/2-0.05];
y=sec(x);
plot(x,y,'b','LineWidth',3)
x=[pi/2+0.05:0.1:pi pi];
y=sec(x);
plot(x,y,'b','LineWidth',3)
axis([-10 10 -10 10])
hold off
line( [0 0], [-10 10], 'color', 'm');
line( [-10 10], [0 0], 'color', 'm');
line( [5*pi/2 5*pi/2], [-10 10], 'color', 'r');
line( [3*pi/2 3*pi/2], [-10 10], 'color', 'r');
line( [pi/2 pi/2], [-10 10], 'color', 'r');
line( [-5*pi/2 -5*pi/2], [-10 10], 'color', 'r');
line( [-3*pi/2 -3*pi/2], [-10 10], 'color', 'r');
line( [-pi/2 -pi/2], [-10 10], 'color', 'r');
line( [-0.5 0.5], [1 1], 'color', 'r');
line( [-0.4 pi+0.4], [-1 -1], 'color', 'r');
line( [pi pi], [-1.4 0.4], 'color', 'r');
line( [2*pi 2*pi], [-0.4 1.4], 'color', 'r');
line( [-pi -pi], [-1.4 0.4], 'color', 'r');
gtext('\fontname{Times New Roman}\fontsize{12}{\itx}')
gtext('\fontname{Times New Roman}\fontsize{12}{\ity}')
gtext('(0,0)')
gtext('1')
gtext('-1')
gtext('\fontname{Times New Roman}\fontsize{10}\rm{\it\pi} /2')
gtext('\fontname{Times New Roman}\fontsize{10}\rm{\it\pi}')
gtext('\fontname{Times New Roman}\fontsize{10}\rm3{\it\pi} /2')
gtext('\fontname{Times New Roman}\fontsize{10}\rm2{\it\pi}')
gtext('\fontname{Times New Roman}\fontsize{10}\rm-{\it\pi} /2')
gtext('\fontname{Times New Roman}\fontsize{10}\rm-{\it\pi}')
gtext('\fontname{Times New Roman}\fontsize{12}{\itf}\rm({\itx}) = sec\itx')
figure,
x=[-pi/2+0.05:0.1:pi/2-0.05];
y=sec(x);
plot(x,y,'--b')
hold on
x3 = x-3*pi;  y=sec(x3);  plot(x3,y,'--b')
x2 = x-2*pi;  y=sec(x2);  plot(x2,y,'--b')
x1 = x-pi;    y=sec(x1);  plot(x1,y,'--b')
x3 = x+3*pi;  y=sec(x3);  plot(x3,y,'--b')
x2 = x+2*pi;  y=sec(x2);  plot(x2,y,'--b')
x1 = x+pi;    y=sec(x1);  plot(x1,y,'--b')
x=[0:0.1:pi/2-0.05];
y=sec(x);
plot(x,y,'b','LineWidth',3)
x=[pi/2+0.05:0.1:pi pi];
y=sec(x);
plot(x,y,'b','LineWidth',3)
x=[-10:0.1:-1];
y=asec(x);
plot(x,y,'g','LineWidth',3)
x=[1:0.1:10];
y=asec(x);
plot(x,y,'g','LineWidth',3)
x=-10:0.1:10;
y=x;
plot(x,y,'--c')
hold off
line( [0 0], [-10 10], 'color', 'm');
line( [-10 10], [0 0], 'color', 'm');
line( [pi/2 pi/2], [-10 10], 'color', 'r');
line( [-0.5 0.5], [1 1], 'color', 'r');
line( [-0.4 pi+0.4], [-1 -1], 'color', 'r');
line( [pi pi], [-1.4 0.4], 'color', 'r');
line( [-10 0.4], [pi pi], 'color', 'b');
line( [-1 -1], [-0.4 pi+0.4], 'color', 'b');
line( [1 1], [-0.4 0.4], 'color', 'b');
axis([-10 10 -10 10])
gtext('\fontname{Times New Roman}\fontsize{12}{\itx}')
gtext('\fontname{Times New Roman}\fontsize{12}{\ity}')
gtext('(0,0)')
gtext('1')
gtext('-1')
gtext('\fontname{Times New Roman}\fontsize{10}\rm{\it\pi} /2')
gtext('\fontname{Times New Roman}\fontsize{10}\rm{\it\pi}')
gtext('-1')
gtext('1')
gtext('\fontname{Times New Roman}\fontsize{10}\rm{\it\pi}')
gtext('\fontname{Times New Roman}\fontsize{12}{\itf}\rm({\itx}) = sec\itx')
gtext('\fontname{Times New Roman}\fontsize{12}{\itf}\rm({\itx}) = sec^{-1}\itx')



%========================================
% csc^-1(x) ------nonunique
%========================================
close all
figure,
x=[0.05:0.1:pi-0.05];
y=csc(x);
plot(x,y,'--b')
hold on
x3 = x-3*pi;  y=csc(x3);  plot(x3,y,'--b')
x2 = x-2*pi;  y=csc(x2);  plot(x2,y,'--b')
x1 = x-pi;    y=csc(x1);  plot(x1,y,'--b')
x3 = x+3*pi;  y=csc(x3);  plot(x3,y,'--b')
x2 = x+2*pi;  y=csc(x2);  plot(x2,y,'--b')
x1 = x+pi;    y=csc(x1);  plot(x1,y,'--b')
x=[0:0.1:pi/2 pi/2];
y=csc(x);
plot(x,y,'b','LineWidth',3)
x=[-pi/2:0.1:-0.05 -0.05];
y=csc(x);
plot(x,y,'b','LineWidth',3)
axis([-10 10 -10 10])
hold off
line( [0 0], [-10 10], 'color', 'm');
line( [-10 10], [0 0], 'color', 'm');
line( [5*pi/2 5*pi/2], [-10 10], 'color', 'r');
line( [3*pi/2 3*pi/2], [-10 10], 'color', 'r');
line( [pi/2 pi/2], [-10 10], 'color', 'r');
line( [-5*pi/2 -5*pi/2], [-10 10], 'color', 'r');
line( [-3*pi/2 -3*pi/2], [-10 10], 'color', 'r');
line( [-pi/2 -pi/2], [-10 10], 'color', 'r');
line( [-0.5 0.5], [1 1], 'color', 'r');
line( [-0.4 pi+0.4], [-1 -1], 'color', 'r');
line( [pi pi], [-1.4 0.4], 'color', 'r');
line( [2*pi 2*pi], [-0.4 1.4], 'color', 'r');
line( [-pi -pi], [-1.4 0.4], 'color', 'r');
gtext('\fontname{Times New Roman}\fontsize{12}{\itx}')
gtext('\fontname{Times New Roman}\fontsize{12}{\ity}')
gtext('\fontname{Times New Roman}\fontsize{12}{\itf}\rm({\itx}) = csc\itx')


2015年5月28日 星期四

繪製反函數圖形(Inverse Function)

x=-3.5:0.1:3.5;
y=x.^2-1;
plot(x,y,'--b')
x=-3:0.1:-1;
y=x.^2-1;
hold on
plot(x,y,'b','LineWidth',1.5)
axis([-3.5 3.5 -1.5 10])
line( [0 0], [-1.5 10], 'color', 'm');
line( [-3.5 3.5], [0 0], 'color', 'm');
line( [-1 -1], [-0.5 0.2], 'color', 'r');
line( [-3 -3], [-0.5 9], 'color', 'r');
gtext('(0,0)')
gtext('-3')
gtext('-1')
gtext('(-3,8)')
gtext('(0,-1)')
gtext('\fontname{Times New Roman}\fontsize{14}{\itf}\rm({\itx}) = {\itx}^2-1')



x=-4:0.1:-1;
y=x.^2-1;
%subplot(1,2,2),
figure, plot(x,y,'b','LineWidth',1.5)
hold on
x=0:0.1:10;
y=-sqrt(x+1);
plot(x,y,'g','LineWidth',1.5)
x=-4:0.1:10;
y=x;
plot(x,y,'--c')
hold off
axis([-4 10 -4 10])
line( [0 0], [-4 10], 'color', 'm');
line( [-4 10], [0 0], 'color', 'm');
line( [-1 -1], [-0.5 0.2], 'color', 'r');
line( [-3 -3], [-0.5 9], 'color', 'r');
line( [-0.5 0.2], [-1 -1], 'color', 'r');
line( [-0.5 9], [-3 -3], 'color', 'r');
gtext('(0,0)')
gtext('-3')
gtext('-1')
gtext('-1')
gtext('-3')
gtext('(-3,8)')
gtext('(-1,0)')
gtext('(0,-1)')
gtext('(8,-3)')
mystr = '$f(x) = x^2-1$';
h = text('string',mystr,'interpreter','latex',...
            'fontsize',14,'units','norm','pos',[0.11 0.7]);
mystr = '$f^{-1}(x) = -\sqrt{x+1}$';
h = text('string',mystr,'interpreter','latex',...
            'fontsize',14,'units','norm','pos',[0.63 0.16]);


2015年3月2日 星期一

15.基本陣列(矩陣)運算函數


>> A=magic(3); B=2*A;
>> det(A)
ans =
  -360
>> expm(A)
ans =
  1.0e+006 *
    1.0898    1.0896    1.0897
    1.0896    1.0897    1.0897
    1.0896    1.0897    1.0897
>> A=magic(2)
A =
     1     3
     4     2
>> inv(A)
ans =
   -0.2000    0.3000
    0.4000   -0.1000
>> B=expm(A)
B =
   63.6830   63.5476
   84.7302   84.8655
>> logm(B)
ans =
    1.0000    3.0000
    4.0000    2.0000
>> pow2(B,A)
ans =
  1.0e+003 *
    0.1274    0.5084
    1.3557    0.3395
>> sqrtm(A)
ans =
   0.9583 + 0.8081i   0.9583 - 0.6061i

   1.2778 - 0.8081i   1.2778 + 0.6061i

14.陣列(矩陣)處理函數

陣列(矩陣)處理函數


命令
功能
[A, B] [A  B]
將相同列數的AB陣列合併成新的橫排陣列,此陣列的列數不變。
[A; B]
將相同行數的AB陣列合併成新的縱排陣列,此陣列的行數不變。
cat(dim, A, B)
dim指定,將AB陣列合併成新的陣列,AB陣列的dim維度必須相同。dim1, 2, ...分別表示row, column, ...
diag(A)
回傳陣列A的主對角元素之行向量
diag(A, n)
回傳陣列A的第n個對角元素之行向量
diag(x)
建構一個以x為內容的對角矩陣,除主對角元素以外均為0
flipdim(A, dim)
將陣列Adim維度翻轉。dim1, 2, ...分別表示row, column, ...
fliplr(A)
將陣列A的元素左右翻轉。
flipud(A)
將陣列A的元素上下翻轉。
repmat(A,[m, n, ..., r])
將陣列A的元素沿第一維度重複m次;沿第二維度重複n次,以此類推。
repmat(A, m, n)
將陣列A的元素沿第一維度重複m次;沿第二維度重複n次。
reshape(A, m, n)
將陣列A的元素重新建立一個大小為m×n的陣列元素各數不可增減
rot90(A)
將陣列A的元素逆時針旋轉90度。
rot90(A, n)
將陣列A的元素逆時針旋轉90×n度。
tril(A)
回傳陣列A的下三角陣列
tril(A, n)
回傳陣列A的第n個下三角陣列
triu(A)
回傳陣列A的上三角陣列
triu(A, n)
回傳陣列A的第n個上三角陣列
wshift(type, x, p)
()向量x之循環位移
type可為1'1''1d''1D'p必須為整數,p>0為向左()循環位移;p<0為向右()循環位移;p=0則維持不變。
wshift(type, A, p)
陣列A之循環位移,type可為2'2''2d''2D'p必須為整數的列向量,p(1)控制行循環位移;p(2)控制列循環位移。p(1)>0為向上循環位移;p(1)<0為向下循環位移;p(1)=0則維持不變;p(2)>0為向左循環位移;p(2)<0為向右循環位移;p(2)=0則維持不變。

>> A=magic(3); B=2*A;
>> C=[A; B]
C =
     8     1     6
     3     5     7
     4     9     2
    16     2    12
     6    10    14
     8    18     4
>> D=[A B]
D =
     8     1     6    16     2    12
     3     5     7     6    10    14
     4     9     2     8    18     4
>> E=cat(2,A,B)
E =
     8     1     6    16     2    12
     3     5     7     6    10    14
     4     9     2     8    18     4
>> diag(E)
ans =
     8
     5
     2
>> x=diag(E)
x =
     8
     5
     2
>> diag(x)
ans =
     8     0     0
     0     5     0
     0     0     2
>> diag(E,-1)
ans =
     3
     9
>> diag(E,3)
ans =
    16
    10
     4
>> flipdim(A,1)
ans =
     4     9     2
     3     5     7
     8     1     6
>> fliplr(A)
ans =
     6     1     8
     7     5     3
     2     9     4
>> flipud(A)
ans =
     4     9     2
     3     5     7
     8     1     6
>> repmat(A,[2, 3, 1])
ans =
     8     1     6     8     1     6     8     1     6
     3     5     7     3     5     7     3     5     7
     4     9     2     4     9     2     4     9     2
     8     1     6     8     1     6     8     1     6
     3     5     7     3     5     7     3     5     7
     4     9     2     4     9     2     4     9     2
>> repmat(A,2,3)
ans =
     8     1     6     8     1     6     8     1     6
     3     5     7     3     5     7     3     5     7
     4     9     2     4     9     2     4     9     2
     8     1     6     8     1     6     8     1     6
     3     5     7     3     5     7     3     5     7
     4     9     2     4     9     2     4     9     2
>> reshape(A, 1, 9)
ans =
     8     3     4     1     5     9     6     7     2
>> reshape(A(3:6), 2, 2)                %增加限制元素條件
ans =
     4     5
     1     9 
>> rot90(A)
ans =
     6     7     2
     1     5     9
     8     3     4
>> rot90(A,3)
ans =
     4     3     8
     9     5     1
     2     7     6
>> tril(A)
ans =
     8     0     0
     3     5     0
     4     9     2
>> tril(A,-1)
ans =
     0     0     0
     3     0     0
     4     9     0
>> triu(A)
ans =
     8     1     6
     0     5     7
     0     0     2
>> triu(A,1)
ans =
     0     1     6
     0     0     7
     0     0     0
>> wshift('1d', x, 1)
ans =
     5
     2
     8
>> wshift('1d', x, -1)
ans =
     2
     8
     5
>> wshift('2d', A, [1 -1])
ans =
     7     3     5
     2     4     9
     6     8     1
>> wshift('2d', A, [-1 0])
ans =
     4     9     2
     8     1     6
     3     5     7

2014年11月20日 星期四

繪圖之水平座標與垂直座標刻度設定

Example:

n = [-100:100];
x = cos(0.1*pi*n);
Hx = stem(n,x,'r--','filled');
set(Hx,'markersize',2);
axis([-110, 110,-2,2]);
xtick = [-100:18:100];
ytick = [-2:0.5:2];
set(gca,'XTickMode','manual','XTick',xtick);
set(gca,'YTickMode','manual','YTick',ytick);
xlabel('n','FontSize',10);
ylabel('x(n)','FontSize',10);
其中水平座標刻度設定

xtick = [刻度由此開始:刻度間隔:刻度結束]

垂直座標刻度設定亦同

ytick = [刻度由此開始:刻度間隔:刻度結束]