September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -1,15 +0,0 @@
|
|||
PROCeuler("-0.07*(y-20)", 100, 0, 100, 2)
|
||||
PROCeuler("-0.07*(y-20)", 100, 0, 100, 5)
|
||||
PROCeuler("-0.07*(y-20)", 100, 0, 100, 10)
|
||||
END
|
||||
|
||||
DEF PROCeuler(df$, y, a, b, s)
|
||||
LOCAL t, @%
|
||||
@% = &2030A
|
||||
t = a
|
||||
WHILE t <= b
|
||||
PRINT t, y
|
||||
y += s * EVAL(df$)
|
||||
t += s
|
||||
ENDWHILE
|
||||
ENDPROC
|
||||
|
|
@ -1,15 +1,17 @@
|
|||
import "futlib/math"
|
||||
|
||||
fun analytic(t0: f64) (time: f64): f64 =
|
||||
20.0 + (t0 - 20.0) * exp64(-0.07*time)
|
||||
20.0 + (t0 - 20.0) * f64.exp(-0.07*time)
|
||||
|
||||
fun cooling(_time: f64) (temperature: f64): f64 =
|
||||
-0.07 * (temperature-20.0)
|
||||
|
||||
fun main(t0: f64) (a: f64) (b: f64) (h: f64): []f64 =
|
||||
let steps = int((b-a)/h)
|
||||
let steps = i32((b-a)/h)
|
||||
let temps = replicate steps 0.0
|
||||
loop ((t,temps)=(t0,temps)) = for i < steps do
|
||||
let x = a + f64(i) * h
|
||||
let temps[i] = abs(t-analytic t0 x)
|
||||
let temps[i] = f64.abs(t-analytic t0 x)
|
||||
in (t + h * cooling x t,
|
||||
temps)
|
||||
in temps
|
||||
|
|
|
|||
32
Task/Euler-method/Kotlin/euler-method.kotlin
Normal file
32
Task/Euler-method/Kotlin/euler-method.kotlin
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
// version 1.1.2
|
||||
|
||||
typealias Deriv = (Double) -> Double // only one parameter needed here
|
||||
|
||||
const val FMT = " %7.3f"
|
||||
|
||||
fun euler(f: Deriv, y: Double, step: Int, end: Int) {
|
||||
var yy = y
|
||||
print(" Step %2d: ".format(step))
|
||||
for (t in 0..end step step) {
|
||||
if (t % 10 == 0) print(FMT.format(yy))
|
||||
yy += step * f(yy)
|
||||
}
|
||||
println()
|
||||
}
|
||||
|
||||
fun analytic() {
|
||||
print(" Time: ")
|
||||
for (t in 0..100 step 10) print(" %7d".format(t))
|
||||
print("\nAnalytic: ")
|
||||
for (t in 0..100 step 10)
|
||||
print(FMT.format(20.0 + 80.0 * Math.exp(-0.07 * t)))
|
||||
println()
|
||||
}
|
||||
|
||||
fun cooling(temp: Double) = -0.07 * (temp - 20.0)
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
analytic()
|
||||
for (i in listOf(2, 5, 10))
|
||||
euler(::cooling, 100.0, i, 100)
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
x = euler(-0.07,-20, 100, 0, 100, 2)
|
||||
x = euler-0.07,-20, 100, 0, 100, 5)
|
||||
x = euler(-0.07,-20, 100, 0, 100, 10)
|
||||
end
|
||||
|
||||
FUNCTION euler(da,db, y, a, b, s)
|
||||
print "===== da:";da;" db:";db;" y:";y;" a:";a;" b:";b;" s:";s;" ==================="
|
||||
t = a
|
||||
WHILE t <= b
|
||||
PRINT t;chr$(9);y
|
||||
y = y + s * (da * (y + db))
|
||||
t = t + s
|
||||
WEND
|
||||
END FUNCTION
|
||||
25
Task/Euler-method/Zkl/euler-method.zkl
Normal file
25
Task/Euler-method/Zkl/euler-method.zkl
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
const FMT=" %7.3f";
|
||||
|
||||
fcn ivp_euler(f,y,step,end_t){
|
||||
print(" Step %2d: ".fmt(step));
|
||||
foreach t in ([0..end_t,step]){
|
||||
if (t % 10 == 0) print(FMT.fmt(y));
|
||||
y += f(t,y) * step;
|
||||
}
|
||||
println();
|
||||
}
|
||||
|
||||
fcn analytic{
|
||||
print(" Time: ");
|
||||
foreach t in ([0..100,10]){ print(" %7g".fmt(t)) }
|
||||
print("\nAnalytic: ");
|
||||
foreach t in ([0..100,10]){ print(FMT.fmt(20.0 + 80.0 * (-0.07 * t).exp())) }
|
||||
println();
|
||||
}
|
||||
|
||||
fcn cooling(_,temp){ return(-0.07 * (temp - 20)) }
|
||||
|
||||
analytic();
|
||||
ivp_euler(cooling, 100.0, 2, 100);
|
||||
ivp_euler(cooling, 100.0, 5, 100);
|
||||
ivp_euler(cooling, 100.0, 10, 100);
|
||||
Loading…
Add table
Add a link
Reference in a new issue