In [1]:
?linspace


search: linspace LinSpace

Out[1]:
linspace(start, stop, n=100)

Construct a range of n linearly spaced elements from start to stop.


In [2]:
?collect


search: collect Collections

Out[2]:
collect(collection)

Return an array of all items in a collection. For associative collections, returns Pair{KeyType, ValType}.

collect(element_type, collection)

Return an array of type Array{element_type,1} of all items in a collection.


In [3]:
collect(linspace(0, 1, 9))


Out[3]:
9-element Array{Float64,1}:
 0.0  
 0.125
 0.25 
 0.375
 0.5  
 0.625
 0.75 
 0.875
 1.0  

In [4]:
?fill


search: fill fill! finally filt filt! filter filter! Filter filesize filemode

Out[4]:
fill(x, dims)

Create an array filled with the value x. For example, fill(1.0, (10,10)) returns a 10x10 array of floats, with each element initialized to 1.0.

If x is an object reference, all elements will refer to the same object. fill(Foo(), dims) will return an array filled with the result of evaluating Foo() once.


In [5]:
?vcat


search: vcat hvcat VecOrMat DenseVecOrMat StridedVecOrMat AbstractVecOrMat

Out[5]:
vcat(A...)

Concatenate along dimension 1


In [6]:
?cumsum


search: cumsum cumsum! cumsum_kbn

Out[6]:
..  cumsum(A, [dim])

Cumulative sum along a dimension ``dim`` (defaults to 1).
See also :func:`cumsum!` to use a preallocated output array,
both for performance and to control the precision of the
output (e.g. to avoid overflow).

In [7]:
A = [2, 3]
cumsum(A, 1)


Out[7]:
2-element Array{Int64,1}:
 2
 5

In [11]:
[2, 3], [[2, 3]]


Out[11]:
([2,3],[2,3])

In [12]:
?minimum


search: minimum minimum! DimensionMismatch

Out[12]:
minimum(A, dims)

Compute the minimum value of an array over the given dimensions.

minimum(itr)

Returns the smallest element in a collection.


In [14]:
minimum(linspace(0, 1, 10))


Out[14]:
0.0

In [15]:
?AbstractVector


search: AbstractVector AbstractSparseVector AbstractVecOrMat

Out[15]:

No documentation found.

Base.AbstractVector is of type TypeConstructor:

Summary:

immutable TypeConstructor <: Type{T}

Fields:

parameters :: SimpleVector
body       :: Any

In [1]:
zeros(10)


Out[1]:
10-element Array{Float64,1}:
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0

In [2]:
?push!


search: push! pushdisplay

Out[2]:
..  push!(collection, items...) -> collection

Insert one or more ``items`` at the end of ``collection``.

.. doctest::

  julia> push!([1, 2, 3], 4, 5, 6)
  6-element Array{Int64,1}:
   1
   2
   3
   4
   5
   6

Use :func:`append!` to add all the elements of another collection to
``collection``.
The result of the preceding example is equivalent to
``append!([1, 2, 3], [4, 5, 6])``.

In [3]:
push!([], 2, 3)


Out[3]:
2-element Array{Any,1}:
 2
 3

In [4]:
push!([2, 3], 4, 5)


Out[4]:
4-element Array{Int64,1}:
 2
 3
 4
 5

In [6]:
?zeros


search: zeros spzeros nonzeros count_zeros set_zero_subnormals

Out[6]:
zeros(type, dims)

Create an array of all zeros of specified type. The type defaults to Float64 if not specified.

zeros(A)

Create an array of all zeros with the same element type and shape as A.


In [7]:
zeros(10, 2)


Out[7]:
10x2 Array{Float64,2}:
 0.0  0.0
 0.0  0.0
 0.0  0.0
 0.0  0.0
 0.0  0.0
 0.0  0.0
 0.0  0.0
 0.0  0.0
 0.0  0.0
 0.0  0.0

In [12]:
zeros(2, 2)


Out[12]:
2x2 Array{Float64,2}:
 0.0  0.0
 0.0  0.0

In [14]:
?copy!


search: copy! unsafe_copy! copy copysign deepcopy

Out[14]:
copy!(dest, do, src, so, N)

Copy N elements from collection src starting at offset so, to array dest starting at offset do. Returns dest.

copy!(dest, src)

Copy all elements from collection src to array dest. Returns dest.


In [15]:
?vcat


search: vcat hvcat VecOrMat DenseVecOrMat StridedVecOrMat AbstractVecOrMat

Out[15]:
vcat(A...)

Concatenate along dimension 1


In [42]:
ygrid0 = linspace(-4, 4, 10)


Out[42]:
linspace(-4.0,4.0,10)

In [43]:
using BasisMatrices

# 1st method
y_basis = Basis(ChebParams(length(ygrid0), minimum(ygrid0), maximum(ygrid0)))


Out[43]:
1 dimensional Basis on the hypercube formed by [-4.0] × [4.0].
Basis families are BasisMatrices.Cheb

In [44]:
S, (ygrid) = nodes(y_basis);

In [45]:
Φ = BasisMatrix(y_basis, Expanded(), S, 0)


Out[45]:
BasisMatrix{BasisMatrices.Expanded} of order 1x1 Array{Int64,2}:
 0

In [46]:
# Actual function at interpolation nodes
f(x::Vector{Float64}) = 1./(1 .+ 25x.^2)
y = f(S[:,1])

# Get coefficients
c = Φ.vals[1] \ y;

In [47]:
using QuantEcon

ygridf = linspace(-4, 4, 100)
Sf = gridmake(ygridf)
yf = f(Sf[:, 1])
interp = funeval(c, y_basis, Sf);

In [48]:
using Plots
plotlyjs()

plt_a = plot(ygridf, [interp[1:length(ygridf)] yf[1:length(ygridf)]], 
             label=["Interpolant", "Original"]',
             lw=2,
             xlabel="a")


Out[48]:

Approximation


In [1]:
using QuantEcon

In [2]:
#Approximated Function
f(x::Array{Float64, 1}) = 1./(1 .+ 25x.^2)


Out[2]:
f (generic function with 1 method)

In [3]:
c_grid = linspace(-1, 1, 1000)
c_basis = Basis(ChebParams(length(c_grid), minimum(c_grid), maximum(c_grid)))

#Approximant
c_S, (c_grid) = nodes(c_basis)
c_phi = BasisMatrix(c_basis, Direct(), c_S)
y = f(c_S[:, 1])
c = c_phi.vals[1] \ y
c_interp = funeval(c, c_basis, c_S)

#Plot
ylims = (-1.1, 1.1)
plot(c_grid, c_interp, ylims=ylims, leg=false)


LoadError: UndefVarError: Basis not defined
while loading In[3], in expression starting on line 2

In [ ]: