Plotting in maple/MATLAB

1.3k Views Asked by At

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.

4

There are 4 best solutions below

0
On BEST ANSWER

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

enter image description here


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))
1
On

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

enter image description here

9
On

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

enter image description here

0
On

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

enter image description here