FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
smallbasic.github.io/samples/node/118.bas at master · smallbasic/smallbasic.github.io · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
smallbasic
/
smallbasic.github.io
Public
Notifications
You must be signed in to change notification settings
Fork
4
Star
4
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
smallbasic.github.io
/
samples
/
node
/
118.bas
Copy path
More file actions
More file actions
Latest commit
History
History
History
77 lines (60 loc) · 1.17 KB
Breadcrumbs
smallbasic.github.io
/
samples
/
node
/
118.bas
Copy path
File metadata and controls
77 lines (60 loc) · 1.17 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
'
''NewtonRaphson.bas
'
'19/11/2002
'
'Version 1.0
'
'By Adolfo Leon Sepulveda
'
'Get a function''s root by Newton-Raphson Method
'
'example:
'
' Function: f(x)= x^2 - 4
'
' Input:
'
' x0 : 4
'
' Result:
'
' Raiz = 2
Declare
func
f
(
x
)
Declare
func
fdx
(
x
,
dx
)
Declare
func
NewtonRaphson
(
x0
,
h
,
iter
,
byref
status
)
const
dx
=
1.0e-6
const
iter
=
100
status
=
0
input
"
x0:
"
,
x0
raiz
=
NewtonRaphson
(
x0
,
dx
,
iter
,
status
)
if
status
then
print
print
"
Raiz =
"
;raiz
else
print
"
function No converge
"
endif
end
func
NewtonRaphson
(
x0
,
dx
,
iter
,
byref
status
)
local i,
x
print
"
x f(x) f''(x)
"
i
=
1
repeat
x
=
x0
-
f
(
x0
) /
fdx
(
x0
,
dx
)
error
=
abs
((
x
-
x0
)/
x0
)
print
using
"
###0.0000 ###0.0000 ###0.0000
"
;x0,
f
(
x0
),
fdx
(
x0
,
dx
)
if
error
<
dx
then
exit
loop
x0
=
x
i
=
i
+
1
until
i
>
iter
if
i
>
iter
then
status
=
0
NewtonRaphson
=
0
else
status
=
1
NewtonRaphson
=
x
endif
end
func
f
(
x
)
f
=
x
^
2-4.0
end
func
fdx
(
x
,
dx
)
local a,
b
,
c
,
d
'
'Richardson''s extrapolation for first derived
'
'-1 / (6*h) * (f(x+h) - 8*f(x + h/2) - f(x-h) + 8*f(x-h/2))
a
=
f
(
x
+
dx
)
b
=
f
(
x
+
dx
/
2.0
)
c
=
f
(
x
-
dx
)
d
=
f
(
x
-
dx
/
2.0
)
fdx
=
-1.0
/ (
6.0
*
dx
) * (
a
-
8.0
*
b
-
c
+
8.0
*
d
)
end
'
Back
|
FazBrowse Home
|
New Git URL