Finding the perimeter of a 2D ellipse using composite trapezoidal integration

4 ビュー (過去 30 日間)
Lorson Blair
Lorson Blair 2022 年 3 月 16 日
コメント済み: Lorson Blair 2022 年 3 月 17 日
I am trying to find the perimeter of a 2D ellipse given by the parametric equations: x = 4 * cos(t), y = 3 * sin(t), for 0 <= t <= 2*pi. I'm using a provided trapezoid function, called trap given below:
% trap function
% a = lower limit of integral, b = upper limit of integral, n = # of subintervals
function g=trap(a,b,n)
xd=linspace(a,b,n+1);
h=xd(2)-xd(1);
sum=0.5*f(xd(1));
for j=2:n
sum=sum+f(xd(j));
end
g=h*(sum+0.5*f(xd(n+1)));
end
I also have a function for the f(x) version of the ellipse function: (x/4)^2 + (y/3)^2 = 1
function y=f(x)
y=3*sqrt(1-(x^2/16));
end
However, this does not seem to be working. My values turn out to be complex since you cannot find the square root of a negative number. I know I'm doing something wrong, but cannot seem to wrap my head around it. My main question is how do I get the equation of the ellipse into y = f(x) form. I don't think I'm doing it correctly. I have a = 0 and b = 2*pi since that's the range we are integrating over. However, I'm also not sure about that. Any help would be greatly appreciated.

採用された回答

Torsten
Torsten 2022 年 3 月 16 日
編集済み: Torsten 2022 年 3 月 16 日
The arclength of a curve in parametrized form C = ((f1(t),f2(t)) ,a<=t<=b) is given as
integral_{a}^{b} sqrt(f1'(t)^2+f2'(t)^2) dt.
This is used in the code below.
If you want to use your trap function instead of trapz, you can implement it as
perimeter = trap(f,0,2*pi,100)
and
function g = trap(f,a,b,n)
...
end
syms t
x = 4*cos(t);
y = 3*sin(t);
dfx = diff(x,t);
dfy = diff(y,t);
f = sqrt(dfx^2+dfy^2);
f = simplify(f);
f = matlabFunction(f);
T = linspace(0,2*pi,100);
F = f(T);
perimeter = trapz(T,F)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumerical Integration and Differentiation についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by