Hi, i want to plot simple function, Can someone tell me how to plot it

15 views (last 30 days)
y1 = c1*exp(-6*t)+c2*t*exp(-6*t);
y2 = -c1*exp(-6*t)+c2*(exp(-6*t)*(-t-0.5));
where c1 and c2 are arbitary values and t is time. I want to plot y1 vs y2 for different values of c1,c2

Accepted Answer

M
M on 15 Nov 2017
t=0.001:0.001:1; % define t as you want
c1=rand;
c2=rand;
y1 = c1*exp(-6*t)+c2*t.*exp(-6*t);
y2 = -c1*exp(-6*t)+c2*(exp(-6*t).*(-t-0.5));
plot(t,y1)
hold on; % if you want to plot on the same graph
plot(t,y2)

More Answers (1)

KL
KL on 15 Nov 2017
t = 0:0.01:2;
c1 = [10;20;30];
c2 = [5;15;25];
now you have t and different set of c's. Then pre-allocate y1 and y2 and then calculate them for every c1 and c2
y1 = zeros(size(c1,1),size(t,2));
y2 = zeros(size(c1,1),size(t,2));
for k=1:numel(c1)
y1(k,:) = c1(k,1).*exp(-6.*t)+c2(k,1).*t.*exp(-6.*t);
y2(k,:) = -c1(k,1).*exp(-6.*t)+c2(k,1).*(exp(-6.*t).*(-t-0.5));
end
Then plot and give them legends.
figure
plot(y1,y2)
legend('curve1','curve2','curve3')

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!