Skewed slope of a perpendicular function.

Click For Summary
SUMMARY

The discussion focuses on fitting a sine function to a general curve using Octave, specifically addressing the challenge of calculating perpendicular points along the curve. The user employs derivatives to find slopes and constructs perpendicular lines, but encounters issues as the derivative approaches zero, leading to inaccuracies in the plotted points. The provided Octave code outlines the process of deriving the general function and its derivative, but the user seeks clarification on missing elements in their mathematical approach.

PREREQUISITES
  • Understanding of calculus, specifically derivatives and slopes.
  • Familiarity with Octave programming for numerical computations.
  • Knowledge of trigonometric functions, particularly sine functions.
  • Basic principles of curve fitting and geometric interpretations of functions.
NEXT STEPS
  • Explore advanced curve fitting techniques in Octave.
  • Learn about numerical stability in derivative calculations.
  • Investigate alternative methods for calculating perpendicular distances in curve fitting.
  • Study the implications of zero derivatives on function behavior and plotting.
USEFUL FOR

Mathematicians, data scientists, and software developers interested in numerical methods for curve fitting and geometric analysis using Octave.

Nugget_Mon
Messages
6
Reaction score
0
Hello,
I am trying to fit a sine function to a general curve. Convolution isn't giving me what I want, which is for every point on a general curve, displace that point by another function. I have written some code in Octave, and it's close, but not quite it.
What I did was to take a general function, take it's derivative at each point, took the inverse reciprocal for the slope of the perpendicular line to that point, set the distance to the point I wanted, then put the perpendicular line in point slope for to solve for the points of interest. The plot come close, but at the derivative approaches zero, so do the perpendicular points.

Code:
theta=[-2*pi:2*pi/1000:2*pi];#domain

z=4*theta.^3-36*theta.^2+14*theta+4;#general function
dz=12*theta.^2-72*theta+14;#derivative

d=0.5*cos(36*theta);#distance

x=((d.*dz)./(sqrt(dz.^2-1)))+theta;
y=-((x-theta)./dz)+z;

figure
hold on
#plot(theta,z)#un-comment for general plot.
plot(x,y)
hold off

What am I missing?
 
Physics news on Phys.org
My math:
f(theta)= as above
f'(theta)= as above
(1) tan line: y-z=f'(theta)*(x-theta)
(2) perp line: y-z=(-1/f'(theta))*(x-theta)
(3) d=sqrt((x-theta)^2+(y-z)^2)

solve for y in (2) and sub into (3)
d^2=(x-theta)^2+((theta-x)/f'(theta)+z-z)^2
Simplify
d^2=(x-theta)^2*(1-1/f'(theta)^2)
Simplify
sqrt((d^2*f'(theta)^2)/(f'(theta)-1))=x-theta
Solve for x
d*f'(theta)/sqrt(f'(theta)^2-1)+theta=x
Then sub into perpendicular point slope form and solve for y.
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 53 ·
2
Replies
53
Views
6K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
16
Views
3K
  • · Replies 16 ·
Replies
16
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 21 ·
Replies
21
Views
3K