Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 120
License: ITEM_0
Image: ubuntu2004
#a x=var('x') f(x)=x^3-x-1 fp=diff(f,x) Newton(x)=x-(f/fp)(x) xn=1; xn #initial valueIs thi for i in range(5): #this will produce 10 iteration xn=N(Newton(xn),digits=10); #each value given to 6 decimal places xn #if xn is indented, this is part of the for loop, so it will give every xn output
1 1.500000000 1.347826087 1.325200399 1.324718174 1.324717957
#b x=var('x') f(x)=x^3-x-1 fp=diff(f,x) Newton(x)=x-(f/fp)(x) xn=0.6; xn #initial valueIs thi for i in range(15): #this will produce 10 iteration xn=N(Newton(xn),digits=10); #each value given to 6 decimal places xn #if xn is indented, this is part of the for loop, so it will give every xn output
0.600000000000000 17.90000000 11.94680233 7.985520352 5.356909315 3.624996033 2.505589190 1.820129422 1.461044110 1.339323224 1.324912868 1.324717993 1.324717957 1.324717957 1.324717957 1.324717957
#c x=var('x') f(x)=x^3-x-1 fp=diff(f,x) Newton(x)=x-(f/fp)(x) xn=0.57; xn #initial valueIs thi for i in range(40): #this will produce 10 iteration xn=N(Newton(xn),digits=10); #each value given to 6 decimal places xn #if xn is indented, this is part of the for loop, so it will give every xn output
0.570000000000000 -54.16545455 -36.11429253 -24.08209425 -16.06338741 -10.72148342 -7.165534467 -4.801703813 -3.233425235 -2.193674205 -1.496866569 -0.9975459611 -0.4963053097 -2.894162421 -1.967962058 -1.341354661 -0.8701866802 -0.2499491439 -1.192219236 -0.7319521892 0.3552129971 -1.753321697 -1.189420257 -0.7291235197 0.3778432572 -1.937868389 -1.320347113 -0.8519169831 -0.2009524859 -1.119378170 -0.6542818995 1.547288990 1.360129073 1.325832759 1.324719114 1.324717957 1.324717957 1.324717957 1.324717957 1.324717957 1.324717957
#d x=var('x') f(x)=x^3-x-1 fp(x)=diff(f,x) x1=1 #the first initial value x2=0.6 #the second value x3=0.57 #the third value tangent1=fp(x1)*(x-x1)+f(x1) tangent2=fp(x2)*(x-x2)+f(x2) tangent3=fp(x3)*(x-x3)+f(x3) a=plot(f(x), (x,-0.5,2), color='pink') b=plot(tangent1, (x,-0.5,2)) c=plot(tangent2, (x,-0.5,2)) d=plot(tangent3, (x,-0.5,2)) a+b+c+d
#e x=var('x') f(x)=x^3-x-1 fp=diff(f,x) Newton(x)=x-(f/fp)(x) xn=1;xn iterations=1 while abs(xn-find_root( x^3 -x - 1 , - 2 , 2 ))>= 10^(-6): #to compute error with the actual root iterations=iterations + 1 #to count numbers of iteration xn=N(Newton(xn), digits=6) xn iterations #Below is your attempt #while i in range (20): # xn=N(Newton(xn), digits=6); # xn
1 1.32472 5