MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Determining if a curve is a closed loop

Asked by James Simko on 16 Nov 2012

This is for a lab assignment for an intro to matlab course

assuming a parametric curve composed of

```    x=3*cos(t);
y=3*sin((3+ee)*t);
where ee is an epsilon between -.5 and .5```

I must find where what value of ee makes the curve a closed curve

my initial code is

t=[0:.1:10]; ee=-0.5; hold on for i=1:100

```    x=3*cos(t);
y=3*sin((3+ee)*t);
if y(1) ~= y(length(t))
ee=ee+.01;```
```    else
plot(x,y)
ee
y(i)
x(i)
end
end```

however this does not return an answer, I am wondering if there is something I am not addressing correctly.

Products

No products are associated with this question.

Answer by Image Analyst on 17 Nov 2012

Your curve never closes. Run this code to see why:

```clc;    % Clear the command window.
clearvars;  % Erase all existing variables.
workspace;  % Make sure the workspace panel is showing.
format longg;
format compact;
fontSize = 20;
```
```t=[0:.1:10];
ee=-0.5;
tolerance = 0.05;
for i=1:100

x=3*cos(t);
y=3*sin((3+ee)*t);
if abs(y(1) - y(end)) < tolerance
break;
end
ee = ee + .01;

cla;
plot(x,y, 'bo-');
hold on;
% Plot end points
plot(x(1), y(1), 'rs', 'MarkerSize', 20, 'LineWidth', 3);
plot(x(end), y(end), 'rs', 'MarkerSize', 20, 'LineWidth', 3);
grid on;
if i == 1
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
end
promptMessage = sprintf('Do you want to Continue processing,\nor Cancel to abort processing?');
titleBarCaption = 'Continue?';
button = questdlg(promptMessage, titleBarCaption, 'Continue', 'Cancel', 'Continue');
if strcmp(button, 'Cancel')
close all;
break;
end
end
```

1 Comment

James Simko on 25 Nov 2012

Oh man, that is a really good idea, using a tolerance to break the loop.