June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -1,16 +1,16 @@
|
|||
euler(f,T,t0,t1,h)=[(T,T+=h*f(T))[1] for t=t0:h:t1]
|
||||
euler(f::Function, T::Number, t0::Int, t1::Int, h::Int) = collect(begin T += h * f(T); T end for t in t0:h:t1)
|
||||
|
||||
# Prints a series of arbitrary values in a tabular form, left aligned in cells with a given width
|
||||
tabular(width,cells...)=println(join(map(s->rpad(s,width),cells),""))
|
||||
tabular(width, cells...) = println(join(map(s -> rpad(s, width), cells)))
|
||||
|
||||
# prints the table according to the task description for h=5 and 10 sec
|
||||
for h=(5,10)
|
||||
print("Step $h:\n\n")
|
||||
tabular(15,"Time","Euler","Analytic")
|
||||
t=0
|
||||
for T=euler(y->-0.07*(y-20.0),100.0,0,100,h)
|
||||
tabular(15,t,round(T,6),round(20.0+80.0*exp(-0.07*t),6))
|
||||
t+=h
|
||||
end
|
||||
println()
|
||||
for h in (5, 10)
|
||||
print("Step $h:\n\n")
|
||||
tabular(15, "Time", "Euler", "Analytic")
|
||||
t = 0
|
||||
for T in euler(y -> -0.07 * (y - 20.0), 100.0, 0, 100, h)
|
||||
tabular(15, t, round(T,6), round(20.0 + 80.0 * exp(-0.07t), 6))
|
||||
t += h
|
||||
end
|
||||
println()
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue