How do you plot the following parametric equation (equation of an ellipse) in the same graph
$$ x = a\cos{t} $$ $$ y = b\sin{t} $$
with varying value of $a$ and $b$ in either maple or MATLAB ?
Many thanks.
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It only takes a minute to sign up.
Sign up to join this communityHow do you plot the following parametric equation (equation of an ellipse) in the same graph
$$ x = a\cos{t} $$ $$ y = b\sin{t} $$
with varying value of $a$ and $b$ in either maple or MATLAB ?
Many thanks.
And in MATLAB:
min_a = 1; max_a = 10;
min_b = .5; max_b = 5;
t = linspace(0,2*pi,101);
cost = cos(t);
sint = sin(t);
N = 21; % Number of distinct values of a, b to plot
a = linspace(min_a,max_a,N);
b = linspace(min_b,max_b,N);
x = kron(a',cost);
y = kron(b',sint);
figure; hold on
for i=1:size(x,1)
plot(x(i,:),y(:,:))
end
Code comparison for loop versus vectorization techniques:
clear all
clc
time = zeros(5,1);
for k=1:5
close all
tic
min_a = 1; max_a = 10;
min_b = .5; max_b = 5;
t = linspace(0,2*pi,101);
cost = cos(t);
sint = sin(t);
N = 21; % Number of distinct values of a, b to plot
a = linspace(min_a,max_a,N);
b = linspace(min_b,max_b,N);
x = kron(a',cost);
y = kron(b',sint);
figure(1); hold on
for i=1:size(x,1)
plot(x(i,:),y(:,:))
end
time(k) = toc;
end
mean(time(2:end))
clear all
time = zeros(5,1);
for k=1:5
close all
tic
min_a = 1; max_a = 10;
min_b = .5; max_b = 5;
t = linspace(0,2*pi,101);
N = 21; % Number of distinct values of a, b to plot
a = linspace(min_a,max_a,N);
b = linspace(min_b,max_b,N);
figure(1); hold on
for i=1:length(a)
for j=1:length(b)
for l=1:length(t)
x = a(i)*cos(t(l));
y = b(j)*sin(t(l));
plot(x,y)
end
end
end
time(k) = toc;
end
mean(time(2:end))
Here is the command and the plot
plot([[ cos(t), 2*sin(t), t = 0 .. 2*Pi], [2*cos(t), 3*sin(t), t=0 .. 2*Pi],[4*cos(t), sin(t), t = 0 .. 2*Pi]], color = [blue, yellow] );
a=1..10
and b=1..10
, this seems to be a very tedious task. I know commands for explicit equations, eg plot({a*sin(t) $ a =-1..1},t=0..2*Pi)
Maybe you can manipulate it and tell me the same for parametric equations. Meanwhile i'll also try MaplePrimes as user64494 suggested.
$\endgroup$
– Vineet Maheshwari
Jun 27 '13 at 18:24
You may use the following codes in Maple 17 to do your job.
> with(plots):
> with(student):
> for i to 80 do a[i] := i*cos(x) od:
> for i to 80 do a[i] := \sqrt{i}*sin(x) od:
> d := seq([a[i], b[i], x = -5 .. 5], i = 1 .. 80);
> plot({d});
In Matlab
for a=1:3
for b=1:3
for t=0:0.01:2*pi
x=a*cos(t);
y=b*sin(t);
hold on
plot(x,y)
end
end
end
cos
and sin
work just fine on vectors.
$\endgroup$
– Emily
Jun 27 '13 at 14:51
hold on
and plot a set of single points. That still takes up memory, even when you over-write the variable, because MATLAB creates a separate data structure for the axes that completely contains all data used to generate the plot.
$\endgroup$
– Emily
Jun 27 '13 at 14:59