% Figure of Banana Function % NUMERICAL METHODS: Matlab Programs % (c) 2007 by Xie Liling % Complementary Software to accompany the textbook: % Information and Computing Science: A Laboratory Course figure x1=[-2:0.125:2]'; x2=[-1:0.125:3]'; [x1,x2]=meshgrid(x1',x2'); meshd=100*(x2-x1.^2).^2+(1-x1).^2; mesh(meshd) view(-40.5,20.4) xlabel('x_1'); ylabel('x_2'); zlabel('f(x)'); % Contour of Banana Function figure conts=exp(3:20); contour(x1,x2,meshd,conts,'k:') % 3D Contour of Banana Function figure [x1,x2]=meshgrid(0.5:0.01:1.5); z=100*(x2-x1.^2).^2+(1-x1).^2; contour3(x1,x2,z,100),zlim([0,310]) hold on plot3(1,1,0,'ro')