You are on page 1of 7

Matlab Problem 14.

5:
x=2*pi:pi/10:2*pi;
y=sin(x);
h=plot(x,y);
xlabel('x');
ylabel('y');
Output:

a) Code:
x=-2*pi:pi/10:2*pi;
y=sin(x);
h=plot(x,y);
get(h)
set(h,'color',[0,1,0]);
xlabel('x');
ylabel('y');
Output:
b) Code:
x=-2*pi:pi/10:2*pi;
y=sin(x);
h=plot(x,y);
get(h);
set(h,'LineStyle','--');
xlabel('x');
ylabel('y');
Output:

c) Code:
x=-2*pi:pi/10:2*pi;
y=sin(x);
h=plot(x,y);
get(h);
set(h,'linewidth',2);
xlabel('x');
ylabel('y');
Output:
Matlab Problem 14.7:
a) Code:
x=-2*pi:pi/10:2*pi;
y=sin(x);
plot(x,y,'r');
xlabel('x');
ylabel('y');
h=gca;
get(gcf);
set(h,'color',[0 0 1]);
Output:

b) Code:
x=-2*pi:pi/10:2*pi;
y=sin(x);
plot(x,y,'r');
xlabel('x');
ylabel('y');
h=gca;
get(gcf);
set(h,'xscale','log');
Output:
Matlab Problem 14.9:
Code:
y1=[2345,4363,3212,4565,8776,7679,6532,2376,2238,4509,5643,1137];
y2=[2343,5766,4534,4719,3422,2200,3454,7865,6543,4508,2312,4566];
plot(y1);
hold on
plot(y2);
months={'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','No
v','Dec'};
set(gca,'xtick',1:12,'xticklabel',months);
legend('2015','2016')
title('Comparison of Production')
Output:

Matlab Problem 14.13:


Code:
clc
clf
clear
x=-2*pi:pi/10:2*pi;
a=0;
y=sin(x);
[x1,y1]=meshgrid(x,y);
z=sin(x1-a).*cos(y1-a);
h=surf(z);
axis tight
set(gca,'nextplot','replacechildren');
shading interp
colormap(jet)
for a=0:pi/100:2*pi
z=sin(x1-a).*cos(y1-a).*sin(a);
set(h,'Zdata',z)
drawnow
end
Output:

Some outputs from animation.


Matlab Problem 14.15:
Code:
clear
clc
itr=80;
gz=500;
[x,y]=meshgrid(linspace(-1.5,1.5,gz),linspace(-1.5,1.5,gz));
c=-0.123+0.745i;
z=x+1i*y;
map=zeros(size(x));
for k=1:itr
z=z.^2.+c;
a=find(abs(z)>sqrt(5));
map(a)=k;
end
figure(1)
h=imagesc(map);
M(1)=getframe;
disp('Zoom in now');
disp('Move and point the cursor where you want to zoom');
[y1,x1]=ginput(1);
xx1=x(round(x1),round(y1));
yy1=y(round(x1),round(y1));
for k=2:100
[x,y]=meshgrid(linspace(xx1-1/1.1^k,xx1+1/1.1^k,gz),linspace(yy1-
1/1.1^k,yy1+1/1.1^k,gz));
c=0.123+0.745i;
z=x+1i*y;
map=zeros(size(x));
for j=1:itr
z=z.^2.+c;
a=find(abs(z)>sqrt(5));
map(a)=j;
end
set(h,'Cdata',map)
colormap(jet)
M(k)=getframe;
end

Output:
Zoom in now
Move and point the cursor where you want to zoom
Region Selection

Zoomed Region

You might also like