# Plotting the tangent line of a vector-valued function

Hi! I want to plot the tangent line of the vector valued function \mathbf{f}(t)=(\cos(t),\sin(t),t) at t=\pi, but I get an error. I can’t not understad what I am doing wrong.

using SymPy, Plots
@syms t::real
g(t) = [cos(t), sin(t), sqrt(t)]
plot(g(t)..., 0, 2pi)
tl(t) = g(pi) + subs.(diff.(g(t)), t=>pi) * t
plot!(tl(t)..., 0, 2pi)

ERROR: MethodError: no method matching var"##320"(::Float64)

Closest candidates are:
var"##320"()
@ SymPy none:0

Stacktrace:
[1] #invokelatest#2
@ ./essentials.jl:819 [inlined]
[2] invokelatest
@ ./essentials.jl:816 [inlined]
[3] #122
@ ~/.julia/packages/SymPy/WFaz9/src/lambdify.jl:253 [inlined]
[4] iterate
@ ./generator.jl:47 [inlined]
[5] _collect(c::StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, itr::Base.Generator{StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, SymPy.var"#122#123"{SymPy.var"###320"}}, #unused#::Base.EltypeUnknown, isz::Base.HasShape{1})
@ Base ./array.jl:802
[6] collect_similar(cont::StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, itr::Base.Generator{StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, SymPy.var"#122#123"{SymPy.var"###320"}})
@ Base ./array.jl:711
[7] map(f::Function, A::StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64})
@ Base ./abstractarray.jl:3263
[8] _map_funcs(f::Function, u::StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64})
@ RecipesPipeline ~/.julia/packages/RecipesPipeline/BGM3l/src/utils.jl:211
[9] macro expansion
@ ~/.julia/packages/RecipesPipeline/BGM3l/src/user_recipe.jl:287 [inlined]
[10] apply_recipe(plotattributes::AbstractDict{Symbol, Any}, fx::SymPy.var"#122#123"{SymPy.var"###320"}, fy::SymPy.var"#122#123"{SymPy.var"###321"}, fz::SymPy.var"#122#123"{SymPy.var"###322"}, u::AbstractVector)
@ RecipesPipeline ~/.julia/packages/RecipesBase/BRe07/src/RecipesBase.jl:300
[11] _process_userrecipes!(plt::Any, plotattributes::Any, args::Any)
@ RecipesPipeline ~/.julia/packages/RecipesPipeline/BGM3l/src/user_recipe.jl:38
[12] recipe_pipeline!(plt::Any, plotattributes::Any, args::Any)
@ RecipesPipeline ~/.julia/packages/RecipesPipeline/BGM3l/src/RecipesPipeline.jl:72
[13] _plot!(plt::Plots.Plot, plotattributes::Any, args::Any)
@ Plots ~/.julia/packages/Plots/sxUvK/src/plot.jl:223
[14] plot!(::Plots.Plot, ::Any, ::Vararg{Any}; kw::Base.Pairs{Symbol, V, Tuple{Vararg{Symbol, N}}, NamedTuple{names, T}} where {V, N, names, T<:Tuple{Vararg{Any, N}}})
@ Plots ~/.julia/packages/Plots/sxUvK/src/plot.jl:213
[15] plot!(::Plots.Plot, ::Any, ::Any, ::Vararg{Any})
@ Plots ~/.julia/packages/Plots/sxUvK/src/plot.jl:208
[16] plot!(::Any, ::Vararg{Any}; kw::Base.Pairs{Symbol, V, Tuple{Vararg{Symbol, N}}, NamedTuple{names, T}} where {V, N, names, T<:Tuple{Vararg{Any, N}}})
@ Plots ~/.julia/packages/Plots/sxUvK/src/plot.jl:202
[17] plot!(::Any, ::Any, ::Any, ::Vararg{Any})
@ Plots ~/.julia/packages/Plots/sxUvK/src/plot.jl:194
[18] top-level scope
@ /run/media/alf/datos/misrepositorios/docencia/analisis-practicas-julia/08-funciones-vectoriales.qmd:6

1 Like

There is a bug when plotting a symbolic value which is a constant, in this case 0. You can see the difference where g(t) = [t+3/2*sin(2t), 4*cos(t), a*cos(2t)] will plot as you do with a nonzero a, but will have the same error when a=0. I’ll open an issue and hopefully address soon. Until then you could use some other value, say 3, instead of pi

2 Likes

This issue should be fixed now.

3 Likes