%% Homework Set 9 %% Problem 1: Script file that performs Newton's Method f=inline('x-exp(-x)'); df=inline('1+exp(-x)'); x(1)=-1; for j=1:100 y(j)=f(x(j)); dy(j)=df(x(j)); x(j+1)=x(j)-y(j)/dy(j); if abs(y(j))<10^(-6) break; end end N=length(x); plot(1:N,x,'^-',1:N-1,y,'*-'); %% Problem 2: Find the line of best fit using the data below clear x=[-1,1,2,3]'; y=[-1,1,1,2]'; A=[x, ones(4,1)]; c=linsolve(A,y) t=linspace(-1,3); z=c(1)*t+c(2); plot(x,y,'*',t,z);