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]);