summaryrefslogtreecommitdiff
path: root/149/CH24/EX24.5/ques5.sce
blob: a11557622616adfb957204e530a4c58efb50aba4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//ques 5
disp(' To find the roots of f(x)=3x-cos(x)-1 by newtons method ');
disp('f(0)=-ve and f(1) is +ve so a root lies between 0 and 1');
l=0;
m=1;
function y=f(x)
  y=3*x-cos(x)-1;
endfunction
x0=0.6;
disp('let us take x0=0.6 as the root is closer to 1');
disp("Root is given by r=x0-f(xn)/der(f(xn)) ");
disp('approximated root in each steps are');
for i=1:3
  k=x0-f(x0)/derivative(f,x0);
  disp(k);
  x0=k;
end