// Question 1

function y=f1(x)
    y=3*cos(x)-2*log(x+1)-1
endfunction

function y=ff1(x)
    y=-3*sin(x)-2/(x+1)
endfunction

function y=f2(x)
    y=2*x-1
endfunction

function y=ff2(x)
    y=2
endfunction

function y=f3(x)
    y=(2*x-1)^3
endfunction

function y=ff3(x)
    y=6*(2*x-1)^2
endfunction

function y=f4(x)
    y=(2*x-1)^5
endfunction

function y=ff4(x)
    y=10*(2*x-1)^4
endfunction


disp(dichoto(f1,0,1,5))
disp(secante(f1,0,1,5))
disp(newton(f1,ff1,0,5))

disp(dichoto(f2,0,3,5))
disp(secante(f2,0,3,5))
disp(newton(f2,ff2,0,5))

disp(dichoto(f3,0,3,5))
disp(secante(f3,0,3,5))
disp(newton(f3,ff3,0,5))

disp(dichoto(f4,0,3,5))
disp(secante(f4,0,3,5))
disp(newton(f4,ff4,0,5))

// Question 2

X=[1:5]
Y1=[]
Y2=[]
Y3=[]

for i=1:5
    Y1=[Y1,dichoto2(f1,0,1,10^(-i))]
    Y2=[Y2,secante2(f1,0,1,10^(-i))]
    Y3=[Y3,newton2(f1,ff1,0,10^(-i))]
end

scf(1)
clf()

plot2d(X',[Y1;Y2;Y3]')


Y1=[]
Y2=[]
Y3=[]

for i=1:5
    Y1=[Y1,dichoto2(f2,0,3,10^(-i))]
    Y2=[Y2,secante2(f2,0,3,10^(-i))]
    Y3=[Y3,newton2(f2,ff2,0,10^(-i))]
end

scf(2)
clf()

plot2d(X',[Y1;Y2;Y3]')

Y1=[]
Y2=[]
Y3=[]

for i=1:5
    Y1=[Y1,dichoto2(f3,0,3,10^(-i))]
    Y2=[Y2,secante2(f3,0,3,10^(-i))]
    Y3=[Y3,newton2(f3,ff3,0,10^(-i))]
end

scf(3)
clf()

plot2d(X',[Y1;Y2;Y3]')

Y1=[]
Y2=[]
Y3=[]

for i=1:5
    Y1=[Y1,dichoto2(f4,0,3,10^(-i))]
    Y2=[Y2,secante2(f4,0,3,10^(-i))]
    Y3=[Y3,newton2(f4,ff4,0,10^(-i))]
end

scf(4)
clf()

plot2d(X',[Y1;Y2;Y3]')


