Xaero's Solution
==========Problem 6 =========
Main:
----------------
in matlab command window:
---------------
h=[1/4,2/4,3/4];
hh=[1/3,2/3];
dx=0.005;
x=[dx:dx:1-dx];
y_1=y1(x);
y_2=y2(y_1,x,h);
y_3=y3(y_2,x,hh);
plot(x,y_1,'r',x,y_2,'g',x,y_3,'b');
---------------y1.m------------
function y1=y1(x)
% Y1.m file : Generate y1 from x
x=x(:);
y1=x.^2;
return
----------y2.m----------------
function y2=y2(y1,x,h)
% Generate y2 from y1, using vector h as the separating ticks.
y1=y1(:); h=h(:); x=x(:);
y2=y1+1;
for a=1:length(h)
y2=y2+(x>=h(a));
end
---------y3.m--------------
function y3=y3(y2,x,hh)
%Generate y3 from y1....
y2=y2(:); x=x(:); hh=hh(:);
idx=2*ones(size(y2));
for a=1:length(hh)
idx=idx+(x>=hh(a));
end
y3=y2./idx;
=============Problem 7=========
%PS:那两条线是不是没写清楚, 这么简单????
h=[20,3,2008];
a='我的';
b='生日';
x=0:0.01:3;
%y=x.^2;
xx=[1,2];
hFig=figure('Name',['我的生日是',num2str(h(3)),'年',num2str(h(2)),'月',num2str(20),'日']);
set(get(hFig,'Children'),'YTicklabel',[1,2],'XTicklabel',[1,4])
hold on;
%用实线画:(0,y(x=1))-(1,y(x=1))-(1,0) , 用虚线画:(0,y(x=2))-(2,y(x=2))-(2,0)
plot([0,1,1],[1,1,0],'-',[0,2,2],[2^2,2^2,0],'--'),
plot([1,2],[1,4],'.','Markersize',5)
%标注点:(1,y(x=1))和(2,y(x=2))
set(get(hFig,'Children'),'XTick',[1,2],'YTick',[1,4])
%在纵轴上显示:“1”和“4”
%在横轴上显示:“1”和“2”