but look for hints of greater depth
A = randn(4,4)
x = rand(4)
b = A*x
x̂ = A\b
@show norm(A*x̂ - b)
U,Σ,V = svd(A);
U
U[:,1]
# show how to type and show Σ
err = norm(U*diagm(Σ)*V'-A)
typeof(err)
A = randn(4,4) |> t -> t + t' # pipe A through map A -> A + A' to symmetrize it
λ = eigmax(A);
@show det(A - λ*I) # metaprogramming: print expression then evaluate it
;
typeof(I)
using ODE
using PyPlot
# define Lorenz equations
function f(t, x)
σ = 10
β = 8/3
ρ = 28
[σ*(x[2]-x[1]); x[1]*(ρ-x[3]); x[1]*x[2] - β*x[3]]
end
# run f once
f(0, [0; 0; 0])
# integrate
t = 0:0.01:20.0
x₀ = [0.1; 0.0; 0.0]
t,x = ode45(f, x₀, t)
x = hcat(x...)' # rearrange storage of x (don't ask...)
# plot
plot3D(x[:,1], x[:,2], x[:,3], "b-")
xlabel("x")
ylabel("y")
zlabel("z")
xlim(-25,25)
ylim(-25,25)
zlim(0,60)
;
f(n) = n < 2 ? 1 : f(n-1) + f(n-2) # recursive function definition
for i = 0:10
println("f($i) = $(f(i))") # string interpolation
end