Message Boards Message Boards

0
|
1493 Views
|
1 Reply
|
1 Total Likes
View groups...
Share
Share this post:

Creating a recursively-updating discrete gradient vector plot

Posted 1 year ago

I've been assigned to make a graph composed of various "jumps" from the endpoint of the previous jump following the gradient at that point. I'm sure this would be much easier to do manually, but I'd like to try and work out how to have the plot automatically change.

Since the goal of the plot of the line segments is to approximate the fastest path to the function's maximum, it's a compounding line. But eventually, following k steps of chosen length n, the line will overshoot the maximum, and kinda go crazy trying to follow the gradient. My goal is to have Mma recognize when the angle between the line it would create and the line afterwards falls below 0.5 radians, since that'd mean a complete doubling down on itself. Then, instead of it going forward with the computation, it would lower n by 1/3, so the new jump length would be 2/3 of the original, and then repeat the above code. This would go on until a specified endpoint of course, so it'd end up being a Table for {k,0,endpoint}.

My main problem is with the recursive nature of the jump length. What I tried doing was making an If function where as long as the angle between the lines would be above 0.5 Pi, the function would return the standard line with the assumed jump length. But if the angle were to dip below, the jump length would be changed, and then the function would be evaluated.

This is my first time asking something from the Mma community, so apologies if it's not to the same formality or conciseness that others often use. Thank you!

Attached is a modified version of the notebook for my assignment.

Attachments:
POSTED BY: Alex Rosenzweig

Hi Alex,

I have not looked at all of the code in the notebook. There is a problem with the code that generates the list of points. Try replacing it with

Table[If[betweengle[k] < \[Pi]/2, jump = (2 jump)/3; point[k], point[k]], {k, 1, 11}]
POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract