-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode-newton-raphson.html
More file actions
54 lines (49 loc) · 1.74 KB
/
code-newton-raphson.html
File metadata and controls
54 lines (49 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="monokai.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.0-2/css/all.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" charset="utf-8"></script>
<script src="highlight.min.js"></script>
<script>hljs.highlightAll();</script>
</head>
<body>
<button id="button1" onclick="CopyToClipboard('copy-code-newton-raphson')" class="fas fa-copy" style="color:dimgrey; background: none; padding:1px; border: none;"></button>
<div class="border" style="background-color:444;">
<pre><code class="language-java" id="copy-code-newton-raphson">public static final double EPSILON = 0.001;
public static double func(double x){
return x * x * x - x * x + 2;
}
public static double derivFunc(double x){
return 3 * x * x - 2 * x;
}
public static void newtonRaphson(double x){
double h = func(x) / derivFunc(x);
while (Math.abs(h) >= EPSILON){
h = func(x) / derivFunc(x);
x = x - h;
}
System.out.print("The value of the root is : "+ Math.round(x * 100.0) / 100.0);
}
</code></pre>
</div>
<script>
function CopyToClipboard(containerid) {
if (document.selection) {
var range = document.body.createTextRange();
range.moveToElementText(document.getElementById(containerid));
range.select().createTextRange();
document.execCommand("copy");
} else if (window.getSelection) {
var range = document.createRange();
range.selectNode(document.getElementById(containerid));
window.getSelection().addRange(range);
document.execCommand("copy");
}
}
</script>
</body>
</html>