Write a program to estimate pi by the above series using the Newton-Raphson sequ
ID: 3885519 • Letter: W
Question
Write a program to estimate pi by the above series using the
Newton-Raphson sequence to calculate the square root factor.
Use the code in java to write it in jasmin code . jfile, use the Java code below.
public class FastestPIest {
public static void main(String[] args){
// First term of series is initialized in pi
double pi=1, numerator=1, denominator=1;
// Calculate sum
for(int k=1;k<25;k++){
numerator *= k;
denominator *= (2*k)*(2*k+1);
pi += numerator * numerator / denominator;
}
// calculate sqrt(6.75)
double s=6.75, sqrt_s=2;
for(int i=0;i<5;i++)
sqrt_s = .5*(sqrt_s + s/sqrt_s);
// Print pi estimate
pi *= sqrt_s;
System.out.println(pi);
}
}
Explanation / Answer
; FastestPIest.j
; Generated by ClassFileAnalyzer (Can)
; Analyzer and Disassembler for Java class files
; (Jasmin syntax 2, http://jasmin.sourceforge.net)
;
; ClassFileAnalyzer, version 0.7.0
.bytecode 52.0
.source FastestPIest.java
.class public chegg/FastestPIest
.super java/lang/Object
.method public <init>()V
.limit stack 1
.limit locals 1
.var 0 is this Lchegg/FastestPIest; from Label0 to Label4
Label0:
.line 3
0: aload_0
1: invokespecial java/lang/Object/<init>()V
Label4:
4: return
.end method
.method public static main([Ljava/lang/String;)V
.limit stack 8
.limit locals 12
.var 0 is args [Ljava/lang/String; from Label0 to Label106
.var 1 is pi D from Label2 to Label106
.var 11 is i I from Label68 to Label94
.var 3 is numerator D from Label4 to Label106
.var 5 is denominator D from Label7 to Label106
.var 7 is k I from Label10 to Label55
.var 7 is s D from Label60 to Label106
.var 9 is sqrt_s D from Label65 to Label106
Label0:
.line 6
0: dconst_1
1: dstore_1
Label2:
2: dconst_1
3: dstore_3
Label4:
4: dconst_1
5: dstore 5
Label7:
.line 8
7: iconst_1
8: istore 7
Label10:
10: goto Label48
Label13:
.line 9
13: dload_3
14: iload 7
16: i2d
17: dmul
18: dstore_3
.line 10
19: dload 5
21: iconst_2
22: iload 7
24: imul
25: iconst_2
26: iload 7
28: imul
29: iconst_1
30: iadd
31: imul
32: i2d
33: dmul
34: dstore 5
.line 11
36: dload_1
37: dload_3
38: dload_3
39: dmul
40: dload 5
42: ddiv
43: dadd
44: dstore_1
.line 8
45: iinc 7 1
Label48:
48: iload 7
50: bipush 25
52: if_icmplt Label13
Label55:
.line 14
55: ldc2_w 6.75
58: dstore 7
Label60:
60: ldc2_w 2.0
63: dstore 9
Label65:
.line 15
65: iconst_0
66: istore 11
Label68:
68: goto Label88
Label71:
.line 16
71: ldc2_w 0.5
74: dload 9
76: dload 7
78: dload 9
80: ddiv
81: dadd
82: dmul
83: dstore 9
.line 15
85: iinc 11 1
Label88:
88: iload 11
90: iconst_5
91: if_icmplt Label71
Label94:
.line 19
94: dload_1
95: dload 9
97: dmul
98: dstore_1
.line 20
99: getstatic java/lang/System/out Ljava/io/PrintStream;
102: dload_1
103: invokevirtual java/io/PrintStream/println(D)V
Label106:
.line 21
106: return
; full_frame (frameNumber = 0)
; frame_type = 255, offset_delta = 13
; frame bytes: 255 0 13 0 5 7 0 46 3 3 3 1 0 0
.stack
offset 13
locals Object [Ljava/lang/String;
locals Double
locals Double
locals Double
locals Integer
.end stack
; same_frame (frameNumber = 1)
; frame_type = 34, offset_delta = 34
; frame bytes: 34
.stack
offset 48
locals Object [Ljava/lang/String;
locals Double
locals Double
locals Double
locals Integer
.end stack
; full_frame (frameNumber = 2)
; frame_type = 255, offset_delta = 22
; frame bytes: 255 0 22 0 7 7 0 46 3 3 3 3 3 1 0 0
.stack
offset 71
locals Object [Ljava/lang/String;
locals Double
locals Double
locals Double
locals Double
locals Double
locals Integer
.end stack
; same_frame (frameNumber = 3)
; frame_type = 16, offset_delta = 16
; frame bytes: 16
.stack
offset 88
locals Object [Ljava/lang/String;
locals Double
locals Double
locals Double
locals Double
locals Double
locals Integer
.end stack
.end method
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.