In: Computer Science
•Try to plot these three equations in the rage of x=0 to 1 using “for” and “if” commands
•Y=2sin(2πx)
•Y=2cos(2πx)
•Y=log(x)
•Y=e(x)
I only know how to plot without if and for command.
no idea about using if and for command to get this figure.
`Hey,
Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.
clc
clear all
close all
format long;
x=0:0.01:4;
y1=[];
y2=[];
y3=[];
y4=[];
for j=1:4
for i=1:length(x)
if(j==1)
y1(i)=2*sin(2*pi*x(i));
elseif(j==2)
y2(i)=2*cos(2*pi*x(i));
elseif(j==3)
y3(i)=log(x(i));
else
y4(i)=exp(x(i));
end
end
if(j==1)
figure;
plot(x,y1);
xlabel('X-values');
ylabel('Y-values');
title('Plot of 2*sin(2*pi*x)');
elseif(j==2)
figure;
plot(x,y2);
xlabel('X-values');
ylabel('Y-values');
title('Plot of 2*cos(2*pi*x)');
elseif(j==3)
figure;
plot(x,y3);
xlabel('X-values');
ylabel('Y-values');
title('Plot of 2*log(x)');
else
figure;
plot(x,y4);
xlabel('X-values');
ylabel('Y-values');
title('Plot of e^(x)');
end
end
Kindly revert for any queries
Thanks.