This document is try to use Julia to demonstrate the concepts related to the calculus and kinematics
using Plots #The package related to ploting the data
gr() #The GR as plot background
Plots.GRBackend()
using SymPy #The symbolic package
Try to demonstrate the limit process
xi=0.01:0.1:1.01
0.01:0.1:1.01
yi=sin.(xi)
11-element Array{Float64,1}: 0.009999833334166664 0.10977830083717481 0.20845989984609956 0.3050586364434435 0.3986093279844229 0.48817724688290753 0.5728674601004813 0.6518337710215366 0.7242871743701426 0.7895037396899505 0.8468318446180152
yi./xi
11-element Array{Float64,1}: 0.9999833334166665 0.9979845530652256 0.9926661897433312 0.9840601175594952 0.9722178731327388 0.9572102880057011 0.9391269837712808 0.9180757338331502 0.8941816967532623 0.8675865271318137 0.838447370908926
plot(xi,yi./xi,color=:black,linewidth=2,xlabel="x",ylabel="\$\\frac{\\sin(x)}{x}\$",legend=false)
x = symbols("x");
limit(sin(x)/x,x,0)
xi=0.01:0.01:0.1;plot(xi,sin.(xi)./xi,color=:black,linewidth=2,xlabel="x",ylabel="\$\\frac{\\sin(x)}{x}\$",legend=false)
plot(sin,0,3,linewidth=2,color=:cyan,lab="sin(x)")
x=0:1:3;plot!(x,sin.(x),linewidth=2,color=:black,lab="\\Delta x=1");
x=0:0.6:3;plot!(x,sin.(x),linewidth=2,color=:red,lab="\\Delta x=0.6");
x=0:0.5:3;plot!(x,sin.(x),linewidth=2,color=:blue,lab="\\Delta x=0.5");
x=0:0.2:3;plot!(x,sin.(x),linewidth=2,color=:yellow,lab="\\Delta x=0.2");
x=0:0.1:3;plot!(x,sin.(x),linewidth=2,color=:pink,lab="\\Delta x=0.1");
xlabel!("x");ylabel!("sin(x)")
plot(sin,0,π,lab="sin(x)",linewidth=2,color=:red)
Δ=0.5;
θ₀=π/3;
ds=(sin(θ₀+Δ)-sin(θ₀))/Δ;
plot!([0,π],ds.*([0,π].-θ₀).+sin(θ₀),linewidth=2,color=:blue,lab="Tagent line")
θ₀=π/3;anim=@animate for Δ in [1 0.8 0.6 0.4 0.2 0.1 0.001]
plot(sin,0,π,lab="sin(x)",linewidth=2,color=:red,xlim=(0,π),ylim=(0,1.7))
ds=(sin(θ₀+Δ)-sin(θ₀))/Δ;
plot!([0,π],ds.*([0,π].-θ₀).+sin(θ₀),linewidth=2,color=:blue,lab="Tagent line")
end;
gif(anim,"diff.gif",fps=2,show_msg=false)
θ = symbols("θ");diff(sin(θ))
θ=π/3;Δθ=0.01:0.1:1.01
0.01:0.1:1.01
lim=sin.(θ.+Δθ).-sin.(θ)
11-element Array{Float64,1}: 0.004956615757736871 0.04965497771110228 0.08520416397625552 0.11124897883503404 0.12752919110663985 0.13388213429157803 0.13024433188154816 0.11665213159573395 0.09324134220640712 0.06024587658256764 0.01799541450987807
plot(Δθ,lim./Δθ,w=2,shape=:circle)
x=(0:0.01:1)π;plot(x,sin.(x),st=:bar,linewidth=2,color=:yellow,lab="\\Delta x=0.01\\pi");
plot!(sin,0,π,linewidth=2,color=:black)
xi=0.5;xe=2.5;Δx=0.00001;
x=xi:Δx:xe;
sx=sin.(exp.(x));
sum(sx.*Δx)
0.07894535615905263
integrate(sin(symbols("x")),xi,xe)
rx(t)=v.*cos(θ)*t
rx (generic function with 1 method)
ry(t)=v.*sin(θ)*t-g.*t.^2/2
ry (generic function with 1 method)
v=3;θ=π/3;g=9.8;
t=0:0.01:1;plot(rx(t),ry(t),lab="projectile",linewidth=2,color=:red)
p=plot(rx,ry,zeros(1),lab="projectile",linewidth=2,color=:blue,xlim=(-0.1,1.5),ylim=(-2,0.5))
traj=@animate for t=0:0.01:1
push!(p,rx(t),ry(t))
end;
gif(traj,"projectile.gif",fps=8,show_msg=false)
t=0:0.01:1;plot(rx.(t),ry.(t),lab="projectile",linewidth=2,color=:red,xlim=(-0.1,1.5),ylim=(-2.5,0.5))
traj_v=@animate for t=0.1:0.1:1
plot!([0,rx(t)],[0,ry(t)],arrow=:true,linewidth=2,color=:blue,xlim=(-0.1,1.5),ylim=(-2.5,0.5))
end;
gif(traj_v,"vec.gif",fps=8,show_msg=false)
rx_c(t)=r.*cos.(ω.*t);
ry_c(t)=r.*sin.(ω.*t);
r=2;ω=π/6;
t=0:0.1:12;plot(rx_c(t),ry_c(t),lab="circular",linewidth=2,color=:red,xlims=(-3,3),ylims=(-2.1,2.1))
p=plot(rx_c,ry_c,zeros(1),lab="circular",linewidth=2,color=:red,xlims=(-3,3),ylims=(-2.1,2.1))
circ=@animate for t=0:0.1:12
push!(p,rx_c(t),ry_c(t))
end;
gif(circ,"circular.gif",fps=8,show_msg=false)