Asked by PB
on 18 Apr 2019

I have to find the lengths of an ellipse which is given by y = cost and x = 5 sint. Evaluate the length from t1=0 to the following points,

t2=[0.5,1,1.5,2,2.5,3,3.5,4,4.5,5,5.5,6]. Have to use one of the methods, trapezoidal, midpoint or simpson's to two digit accuracy. How do i write a script from 0 to 0.5, 0 to 1, 0 to 1.5 etc ( from 0 to each point) to get 12 values for the lengths.

Answer by David Wilson
on 18 Apr 2019

Accepted Answer

If you need a little more help, then it pays to plot the ellipse and look at the arc lengths.

t = linspace(0,2*pi)';

x = @(t) 5*sin(t); y = @(t) cos(t);

t2=[0.5,1,1.5,2,2.5,3,3.5,4,4.5,5,5.5,6]';

plot(x(t),y(t),'r-', ...

x(0), y(0), 'bs', ...

x(t2), y(t2), 'kh');

for i=1:length(t2)

text(x(t2(i)), y(t2(i)),sprintf('%2.1f',t2(i)))

end

grid on; axis equal;

xlabel('x'); ylabel('y')

It's important to have the axis equal in order to roughly approximate the arc lengths. You can see that from t=0 to t=0.5, the arc length is a little over 2.5. That makes a good check.

Now I've used the formlar above for the arc length, but I've had to convert your sine to my cosine etc. I;'ve also used integral, your (homework?) requested you use a simpler Simpson etc, which I'll leave you to implement. At least you have a tentative solution.

>> f = @(t) sqrt(25*sin(pi/2-t).^2 + cos(pi/2-t).^2);

>> arcLengths = arrayfun(@(t2) integral(f,0,t2), t2)

arcLengths =

2.4014

4.2454

5.1803

5.8983

7.5035

9.7993

12.2605

14.3121

15.5117

16.1217

17.4652

19.6122

As a check, you can see that my guess of 2.5 is not too far off.

PB
on 18 Apr 2019

Thank you so much. How do add a small step size to this? justadd a step size in the linespace?

David Wilson
on 18 Apr 2019

Following my way, you don't need to adjust the stepsize since integral will (magically) take care of it using its adaptive step size ability. I didn't bother add any tolerance to integral, since 2 decimal places is pretty lax.

HOWEVER, you were asked to use a simple integrator without error control, so you will have to choose a suitable stepsize when using Simpson's etc. If you are going to use a straight-forward approach, I'd subdivied the interval (in t) to say about 100 steps as a first approximation.

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## David Wilson (view profile)

## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/457114-finding-lengths-of-an-ellipse#comment_695519

## PB (view profile)

## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/457114-finding-lengths-of-an-ellipse#comment_695522

Sign in to comment.