diff --git a/docs/src/api.md b/docs/src/api.md index e2e2d011..f60818e8 100644 --- a/docs/src/api.md +++ b/docs/src/api.md @@ -25,6 +25,7 @@ set_variables show_params_TaylorN get_coeff evaluate +evaluate! derivative integrate gradient diff --git a/src/Taylor1.jl b/src/Taylor1.jl index ddd6e805..5602a6dc 100644 --- a/src/Taylor1.jl +++ b/src/Taylor1.jl @@ -1049,6 +1049,39 @@ function evaluate{T<:Number,S<:Number}(a::Taylor1{T}, dx::S) end evaluate{T<:Number}(a::Taylor1{T}) = a.coeffs[1] +doc""" + evaluate(x, δt) + +Evaluates each element of `x::Array{Taylor1{T},1}`, representing +the dependent variables of an ODE, at *time* δt. +""" +function evaluate{T<:Number, S<:Number}(x::Array{Taylor1{T},1}, δt::S) + R = promote_type(T,S) + return evaluate(convert(Array{Taylor1{R},1},x), convert(R,δt)) +end +function evaluate{T<:Number}(x::Array{Taylor1{T},1}, δt::T) + xnew = Array{T}( length(x) ) + evaluate!(x, δt, xnew) + return xnew +end +evaluate{T<:Number}(a::Array{Taylor1{T},1}) = evaluate(a, zero(T)) + +doc""" + evaluate!(x, δt, x0) + +Evaluates each element of `x::Array{Taylor1{T},1}`, +representing the Taylor expansion for the dependent variables +of an ODE at *time* δt. It updates the vector `x0` with the +computed values. +""" +function evaluate!{T<:Number}(x::Array{Taylor1{T},1}, δt::T, x0::Array{T,1}) + @assert length(x) == length(x0) + @inbounds for i in eachindex(x) + x0[i] = evaluate( x[i], δt ) + end + nothing +end + """ evaluate(a, x) diff --git a/src/TaylorSeries.jl b/src/TaylorSeries.jl index ad670760..3b6ef06d 100644 --- a/src/TaylorSeries.jl +++ b/src/TaylorSeries.jl @@ -24,11 +24,13 @@ import Base: zero, one, zeros, ones, isinf, isnan, convert, promote_rule, promote, eltype, length, show, real, imag, conj, ctranspose, rem, mod, mod2pi, abs, gradient, -sqrt, exp, log, sin, cos, tan, asin, acos, atan, A_mul_B! + sqrt, exp, log, sin, cos, tan, + asin, acos, atan, A_mul_B! export Taylor1, TaylorN, HomogeneousPolynomial -export get_coeff, derivative, integrate, evaluate, +export get_coeff, derivative, integrate, + evaluate, evaluate!, show_params_TaylorN, get_order, get_numvars, set_variables, get_variables, diff --git a/test/runtests.jl b/test/runtests.jl index 136a1afe..788e8660 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -101,10 +101,11 @@ facts("Tests for Taylor1 expansions") do @fact atan(tan(tsquare)) == tsquare --> true @fact asin(t) + acos(t) == pi/2 --> true @fact derivative(acos(t)) == - 1/sqrt(1-t^2) --> true - @fact_throws ArgumentError asin(ta(1.0)) - @fact_throws ArgumentError acos(ta(big(1.0))) - @fact_throws ArgumentError atan(ta(1//1*im)) + v = [sin(t), exp(-t)] + @fact evaluate(v) == [0.0, 1.0] --> true + @fact evaluate(v, complex(0.0,0.2)) == + [complex(0.0,sinh(0.2)),complex(cos(0.2),sin(-0.2))] --> true @fact derivative(5, exp(ta(1.0))) == exp(1.0) --> true @fact derivative(3, exp(ta(1.0pi))) == exp(1.0pi) --> true @fact isapprox(derivative(10, exp(ta(1.0pi))) , exp(1.0pi) ) --> true