# Plotting in maple/MATLAB

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.

• MaplePrimes is a better place for such questions. – user64494 Jun 27 '13 at 14:20
• Thanks .. Didn't know that !! .. – Vineet Maheshwari Jun 27 '13 at 17:49

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] );

• This method works but suppose if i want plot for 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. – 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


• Never loop over t. cos and sin work just fine on vectors. – Emily Jun 27 '13 at 14:51
• Right but takes too much space in memory – AnilB Jun 27 '13 at 14:57
• Ummmm.... what? – Emily Jun 27 '13 at 14:58
• You're not saving any memory when you 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. – Emily Jun 27 '13 at 14:59
• But in your case you have the plot + vectors – AnilB Jun 27 '13 at 15:26