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 .5I 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
endhowever this does not return an answer, I am wondering if there is something I am not addressing correctly.
No products are associated with this question.
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
Oh man, that is a really good idea, using a tolerance to break the loop.
0 Comments