# Plotting the tangent line of a vector-valued function

**URL:** https://discourse.julialang.org/t/plotting-the-tangent-line-of-a-vector-valued-function/104297
**Category:** General Usage
**Tags:** question, plotting, sympy
**Created:** [September 27, 2023, 7:50am UTC](https://discourse.julialang.org/t/plotting-the-tangent-line-of-a-vector-valued-function/104297 "2023-09-27T07:50:39Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Alf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alf/32/51653_2.png) [@Alf](https://discourse.julialang.org/u/Alf)
#### Post date: [September 27, 2023, 7:50am UTC](https://discourse.julialang.org/t/plotting-the-tangent-line-of-a-vector-valued-function/104297/1 "2023-09-27T07:50:39Z")

</div>

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.

```julia
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)

```

```julia
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

```

---

<div class="post-metadata">

### Author: ![j\_verzani](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j_verzani/32/8551_2.png) [@j\_verzani](https://discourse.julialang.org/u/j_verzani)
#### Post date: [September 27, 2023, 7:55pm UTC](https://discourse.julialang.org/t/plotting-the-tangent-line-of-a-vector-valued-function/104297/2 "2023-09-27T19:55:31Z")

</div>

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`…

---

<div class="post-metadata">

### Author: ![j\_verzani](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j_verzani/32/8551_2.png) [@j\_verzani](https://discourse.julialang.org/u/j_verzani)
#### Post date: [September 27, 2023, 10:10pm UTC](https://discourse.julialang.org/t/plotting-the-tangent-line-of-a-vector-valued-function/104297/3 "2023-09-27T22:10:51Z")

</div>

This issue should be fixed now.
