Stream: helpdesk (published)

Topic: Derivative of vectior


view this post on Zulip brett knoss (Jan 22 2023 at 21:29):

If I have a vector

using ForwardDiff
r=1-.9^2/(1-.9cos(x)
 p(x)=r(x)*[sin(x), cos(x),0]
ForwardDiff.gradient(p, [1:2pi])

tells me that I have a type miss match. How do I fix this?

view this post on Zulip jar (Jan 22 2023 at 21:53):

what is g? what is x?

view this post on Zulip brett knoss (Jan 22 2023 at 22:00):

I changed it.

view this post on Zulip jar (Jan 22 2023 at 22:05):

julia> ForwardDiff.gradient(f, 3)
ERROR: DimensionMismatch: gradient(f, x) expects that x is an array. Perhaps you meant derivative(f, x)?

view this post on Zulip jar (Jan 22 2023 at 22:05):

Perhaps you meant ForwardDiff.derivative(f, 3)?

view this post on Zulip brett knoss (Jan 22 2023 at 22:06):

why isn't it an array?

view this post on Zulip brett knoss (Jan 22 2023 at 22:08):

say I have a vector

r=1-.9^2/(1-.9cos(x)
 r(x)*[sin(x), cos(x),0]

how would I get the derivative?

view this post on Zulip Sukera (Jan 22 2023 at 22:14):

the x you're passing is just a 3, not an array

view this post on Zulip brett knoss (Jan 22 2023 at 22:30):

I changed the problem

view this post on Zulip Mason Protter (Jan 23 2023 at 00:34):

It looks like you're still halfway through editing the question

view this post on Zulip Mason Protter (Jan 23 2023 at 00:35):

Your line defining r doesn't have balanced parentheses, and doesnt define what x is. Later on, you call r(x), so I'm guessing it's mean to be a function?

view this post on Zulip Mason Protter (Jan 23 2023 at 00:38):

When you write ForwardDiff.gradient(p, [1:2pi]), what are you actually trying to do here? This is saying that you're asking for the gradient of p at the point [1:2pi] which is a vector containing a unit range, which doesn't seem like a valid input.

view this post on Zulip Mason Protter (Jan 23 2023 at 00:40):

I think probably what you want to do here is something like this?

julia> using ForwardDiff

julia> r(x) = 1 - 0.9^2 / (1 - 0.9 * cos(x));

julia> p(x) = r(x) * [sin(x), cos(x), 0];

julia> [ForwardDiff.derivative(p, x) for x in 1:2pi]
6-element Vector{Vector{Float64}}:
 [1.6442699017595095, 1.7411330053365992, 0.0]
 [0.14811354293589507, -0.5194621159954294, 0.0]
 [-0.5618728649816087, -0.10915361349834958, 0.0]
 [-0.15477901047354534, 0.5137982587545297, 0.0]
 [1.1838568224428756, -0.4416363739969377, -0.0]
 [-1.680831194586201, -11.984723260384289, -0.0]

But it's hard to tell what you're actually trying to do

view this post on Zulip brett knoss (Jan 27 2023 at 16:35):

Sorry I'm way off I,m trying to create vectors that reflect positions on this function

orbit(x)=-1*sqrt((a-(x+c)^2)*(1-e^2))
orbitm(x)=-orbit(x)

And, I'd like to show 12 vectors from 0 to 2pi


Last updated: Nov 06 2024 at 04:40 UTC