# Does anyone know how to calculate the slope of elliptical line by using the matlab？

11 views (last 30 days)
huazai2020 on 8 Jul 2020
Commented: huazai2020 on 12 Jul 2020 at 16:02
I have some data of the elliptical line， does anyone know how to calculate the slope of elliptical line by using the matlab？

Show 1 older comment
huazai2020 on 9 Jul 2020
x^2/4+y^2/16=1
James Tursa on 9 Jul 2020
If you mean the slope of the tangent line at a point on the ellipse, take the differential of both sides:
2*x*dx/4 + 2*y*dy/16 = 0
Then solve for dy/dx, the slope of the tangent line at the point (x,y):
dy/dx = -4*x/y
John D'Errico on 9 Jul 2020
Or, given that equation, differentiate, recognizing that d/dx applied to x^2 is 2*x. d/dx applied to y^2 is 2*y*dy/dx. Now solve for dy/dx.

Image Analyst on 8 Jul 2020
Exactly what is an "elliptical line"? That's a new one on me. I know lines, and I know ellipses, but not an elliptical line. What is it?
Anyway, if you have "some data" on a line, you can get the slope of a line fitted through your "some data" from the polyfit() function.
coefficients = polyfit(x, y, 1);
The slope of the line fitted through the x and y points is
slope = coefficients(1);

huazai2020 on 9 Jul 2020
As you see the below codes, but it only give one slope,not all the slope on each point, how to solve it ?
clc;
clear all;
rgx = '([-+]?\d+\.?\d*([eE][-+]?\d+)?)';
tkn = regexp(str,[rgx,'\s+',rgx],'tokens');
walldata(:,1:2) = str2double(vertcat(tkn{:}));%21为壁面x值，22为壁面y值
x=walldata(:,1);%提取壁面x坐标
y=walldata(:,2);%提取壁面y坐标
coefficients = polyfit(x, y, 1);
slope = coefficients(1);
Image Analyst on 9 Jul 2020
No, because I didn't know what you meant. So you have an ellipse and you want the slope of a line that's tangent to the ellipse at each points. What I'd probably do is Use John and James code. Untested code
slopeInfo = zeros(length(x), 3); % Col1 = x, col2 = y, col3 = slope
for k = 1 : length(x) % for every (x,y) point on the ellipse (almost)...
slopeInfo(k, 1) = x(k); % Assign x to column 1.
slopeInfo(k, 2) = y(k); % Assign y to column 2.
slopeInfo(k, 3) = -4 * x(k) / y(k); % Assign slope to column 3.
end
huazai2020 on 12 Jul 2020 at 16:02
But how can I import the data to x（k）？