%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % doit.m % This will do lots of stuff. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% fprintf(1,'\n\nStarting...\n'); clear; global X1; global Y1; global X2; global Y2; global P1; global P2; global P3; global L1; global L2; global L3; global R; X1 = 4; Y1 = 0; X2 = 0; Y2 = 4; P1 = sqrt(5); P2 = sqrt(5); P3 = sqrt(5); L1=2; L2=sqrt(2); L3=sqrt(2); R=pi/2; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % 1 Test Function %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% fprintf(1,'\n\nTesting function...\n'); f(tan(-pi/8)) f(tan(pi/8)) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % 2 Bisection Method %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% fprintf(1,'\n\nApplying the bisection method...\n'); bisect(.4,.5,10); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % 3 Bisection Method Again %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% fprintf(1,'\n\nApplying the bisection method again...\n'); bisect(-.4,-.5,10); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % 4 Secant Method %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% fprintf(1,'\n\nApplying the secant method...\n'); secant(.4,.5,10); fprintf(1,'\n\nNewtons Method is not a good choice for this problem because the derivative of the function is required, which is too difficult to find.\n'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % 5 Six Poses %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% fprintf(1,'\n\nFinding six poses...\n'); X1 = 5; Y1 = 0; X2 = 0; Y2 = 5; P1 = 5; P2 = 5; P3 = 4; L1=6; L2=6*sqrt(2); L3=6; R=pi/4; fprintf(1,'(see plot window)\n'); hold off; hold on; fplot('f',[-2 2 -5 5]); % Draw the axis plot([-2 2], [0 0], 'r'); plot([0 0], [-5 5], 'r'); pause; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % 6 Plot %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% fprintf(1,'\n\nPlotting different poses...\n'); hold off; hold on; f(-0.306161); myplot(-4.69,1.71,-0.306161); fprintf(1,'(see plot window)\n'); pause; hold off; hold on; f(-0.086645); myplot(-4.17,-2.76,-0.086645); fprintf(1,'(see plot window)\n'); pause; hold off; hold on; f(0.122182); myplot(-4.69,1.72,0.122182); fprintf(1,'(see plot window)\n'); pause; hold off; hold on; f(0.398121); myplot(-4.17,-2.76,0.398121); fprintf(1,'(see plot window)\n'); pause; hold off; hold on; f(0.523854); myplot(4.86,-1.16,0.523854); fprintf(1,'(see plot window)\n'); pause; hold off; hold on; f(1.463312); myplot(4.86,-1.16,1.463312); fprintf(1,'(see plot window)\n'); pause; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % 7 Varying P1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% fprintf(1,'\n\nTesting variations of P1...\n'); fprintf(1,'\n\n4 Poses, P1 = 4...\n'); P1 = 4; fprintf(1,'(see plot window)\n'); hold off; hold on; fplot('f',[-5 5 -5 5]); % Draw the axis plot([-5 5], [0 0], 'r'); plot([0 0], [-5 5], 'r'); pause; fprintf(1,'\n\n2 Poses, P1 = 10...\n'); P1 = 10; fprintf(1,'(see plot window)\n'); hold off; hold on; fplot('f',[-5 5 -5 5]); % Draw the axis plot([-5 5], [0 0], 'r'); plot([0 0], [-5 5], 'r'); pause; fprintf(1,'\n\n0 Poses, P1 = 50...\n'); P1 = 50; fprintf(1,'(see plot window)\n'); hold off; hold on; fplot('f',[-5 5 -5 5]); % Draw the axis plot([-5 5], [0 0], 'r'); plot([0 0], [-5 5], 'r'); pause; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % 6 Clean up %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %clear;