% equipartitoin the graph 5.6 into % n=4 and n=20 equal length parts % to do this: % use part 2 for s = i/n clear clc close all n=4; figure for i = 1:n s(i) = i/n; end % call part 2 for these s's % make a vector of all t_star outputs for i = 1:n t_stars(i) = part4(s(i)); end % draw plot for given t's x = @(t) .5+.3*t+3.9*t^2-4.7*t^3; y = @(t) 1.5+.3*t+.9*t^2-2.7*t^3; for i=1:100 cont_x(i) = x(i/100); cont_y(i) = y(i/100); end MakeQTMovie('start','part_4_n_4.mov') plot(cont_x,cont_y,'LineWidth',1) hold on grid on x_vec(1) = .5; y_vec(1) = 1.5; for i = 1:length(t_stars) x_vec(i+1) = x(t_stars(i)); y_vec(i+1) = y(t_stars(i)); end plot(x_vec,y_vec,'rx') xlabel('x') ylabel('y') title(['Number of points= ', num2str(n)]) axis([0 1.4 0 1.7]) set(gca, 'Xlim',[0,2],'Ylim',[0,2], 'Drawmode', 'fast','Visible','on') axis square ball = line('color', 'r', 'Marker','o','Markersize', 10,... 'LineWidth',2,'erase','xor','xdata',[],'ydata',[]); for i = 1:length(t_stars)+1 set(ball,'xdata',x_vec(i),'ydata',y_vec(i)); drawnow;pause(1) MakeQTMovie('addfigure') end MakeQTMovie('finish') n = 20; figure for i = 1:n s(i) = i/n; end % call part 2 for these s's % make a vector of all t_star outputs for i = 1:n t_stars(i) = part4(s(i)); end % draw plot for given t's x = @(t) .5+.3*t+3.9*t^2-4.7*t^3; y = @(t) 1.5+.3*t+.9*t^2-2.7*t^3; for i=1:100 cont_x(i) = x(i/100); cont_y(i) = y(i/100); end MakeQTMovie('start','part_4_n_20.mov') plot(cont_x,cont_y,'LineWidth',1) hold on grid on x_vec(1) = .5; y_vec(1) = 1.5; for i = 1:length(t_stars) x_vec(i+1) = x(t_stars(i)); y_vec(i+1) = y(t_stars(i)); end plot(x_vec,y_vec,'rx') xlabel('x') ylabel('y') title(['Number of points= ', num2str(n)]) axis([0 1.4 0 1.7]) set(gca, 'Xlim',[0,2],'Ylim',[0,2], 'Drawmode', 'fast','Visible','on') axis square ball = line('color', 'r', 'Marker','o','Markersize', 10,... 'LineWidth',2,'erase','xor','xdata',[],'ydata',[]); for i = 1:length(t_stars)+1 set(ball,'xdata',x_vec(i),'ydata',y_vec(i)); drawnow;pause(.3) MakeQTMovie('addfigure') end MakeQTMovie('finish')