# How to Reflect Tangent Line toward \$y=x\$ axis with CalculusWithJulia?

Hi all,

I am able to plot reflection of a curve toward y=x axis. But how to reflect a tangent line that went through a certain point to that curve as well?

I want a tangent line plotted at (d,c).

``````using Plots, LaTeXStrings, Plots.PlotMeasures, CalculusWithJulia # ignore any warnings
gr()

# Define the x-range explicitly
xrange = 0.0:0.1:23.0
# Define the transform (or anything else like `(x,y) -> (x, -y)` etc.
xyidentity = (x,y) -> (x,y)
xytransform = (x,y) -> (y, x)

function make_fg_plot()
f(x) = log(0.2x) + sin(0.01x^2)
a, b = 0, 2
c = 1

plt = plot(; xtick=:true, xlims = (-5,23), ylims = (-5, 23),
legend = :topleft, bottom_margin=5mm)
plt_tangent = plot(tangent(f,c); linecolor = :red,
legend = :topleft, bottom_margin=5mm)

for (T, attrs) in [(xyidentity, (;label = "", linecolor = :green)),
(xytransform, (;label = "", linecolor = :red))]
# Apply the transformation to all tuples (x, f(x))
transformedPoints = T.(xrange, f.(xrange))
# Make vectors out of the resulting tuples for plotting
newx = first.(transformedPoints)
newy = last.(transformedPoints)

plot!(plt, newx, newy; label="")
#plot!(plt_tangent, newx, newy; label="")
plot!(tangent(f,c), a, b, linecolor = :red, label="")
g(x)=x
plot!(g,linecolor=:green, line=(:dash), label="")

scatter!([1], [f(1)], color = "red1", label="", markersize = 3)
scatter!([f(1)], [1], color = "red1", label="", markersize = 3)
plot!([1,f(1)],[f(1),1], label="", linecolor=:green, line=(:dash))
annotate!([(-2.1,1.5, (L"(d,c)", 7, :black))])
annotate!([(2.1,-2, (L"(c,d)", 7, :black))])
annotate!([(0.5,-3.7, (L"l_{1}", 7, :black))])
annotate!([(-3.4,0.8, (L"l_{2}", 7, :black))])

end
return plt
end

make_fg_plot()
``````

Is my old answer here of help?

There is an example here Calculus with Julia - 10Â  The Inverse of a Function

1 Like

you could try to define yourself your â€śinverse tangentâ€ť something like the following

``````using Plots, CalculusWithJulia
gr()

tangentinv(f,c)=x->c + inv(f'(c))*(x-f(c))

function make_fg_plot(f,c, xr)

plt = plot(; xtick=:true, xlims = (-5,23), ylims = (-5, 23), aspect_ratio=:equal)

plot!(f;linecolor = :red, label="")
a, b = 0, 2
plot!(tangent(f,c), a, b, linecolor = :black, label="")

plot!(x->x,linecolor=:green, line=(:dash), label="")

plot!(plt, f.(xr), xr; linecolor = :red, label="")
A, B = tangent(f,c)(a), tangent(f,c)(b)  # inverse of f
plot!(tangentinv(f,c), A, B, linecolor = :black, label="")

return plt
end

xrange = 0.0:0.1:23.0
f(x) = log(0.2x) + sin(0.01x^2)
c = 1

make_fg_plot(f,c, xrange)

``````

1 Like

Thanks a lot for this @rocco_sprmnt21