Matlab 2

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Graph Plotting

Q1. Draw a circle of unit radius.


Ans:
>> theta = [0:pi/300:2*pi];
>> r=1;
>> x= r*sin(theta);
>> y= r*cos(theta);
>> plot(x,y)

Q2. Plot y=sin(x) where 0<=x<=2pi taking 100 linearly spaced points in a

given interval also label x and y axis and give the figure title as your

name.
Ans:
>> x = [0:pi/100:2*pi];
>> y = sin(x);
>> plot (x,y)
>> xlabel('x axis')
>> ylabel('y axis')
>> title('Sine curve')

5
Graph Plotting

Q3. For the figure of question 2 instead of plotting the line of curve show

Unconnected data points.


Ans.
>> x = [0:pi/100:2*pi];
>> y = sin(x);
>> plot (x,y, '*')
>> xlabel('x axis')
>> ylabel('y axis')
>> title('Sine curve')

Q4. Combine the plots of question 2 and 3.


Ans:
>> x = [0:pi/100:2*pi];
>> y = sin(x);
>> plot (x,y)
>> xlabel('x axis')
>> ylabel('y axis')
>> title('Sine curve')
>> hold on
>> plot (x,y,'*')

6
Graph Plotting

Q5.Plot y=exp(-0.4)*sin(x) where 0<=x<=4pi taking

(i)10 points in interval.

(ii)100 points in interval.


Ans.
>> x=[0:pi/10:4*pi];
>> y=(exp((-0.4)*x)).*(sin(x));
>> plot(y)

>> x=[0:pi/100:4*pi];
>> y=(exp((-0.4)*x)).*(sin(x));
>> plot(y)

Q6.Plot circular helix if x(t)=sin(t),y(t)=cos(t),z(t)=t where 0<=t<=20


Ans.
>> t=[0:20];
>> x=sin(t);
>> y=cos(t);
>> z=t;
>> plot3(x,y,z)

7
Graph Plotting

Q7.Create a vector x=0:10:100, plot x vs. x^3 on log scale.


Ans.
>> x=[0:10:1000];
>> semilogx=x;
>> semilogy=(x.^3);
>> plot(semilogx,semilogy)
>> xlabel('x')
>> ylabel('x^3')

8
Graph Plotting

Q8.Plot y and z on the same graph where y=cosx, z=1-((x^2)/2)+((x^4)/24) and


0<=x<=pi
Ans.
>> x=[0:pi];
>> y=cos(x);
>> z=1-((x.^2)/2)+((x.^4)/24);
>> plot(y,’g’)
>> hold on
>> plot(z,’b’)

Q9.Modify the plot of question 1 to represent the centre of circle by '+'.


Ans.
>> theta=[0:pi/100:2*pi];
>> r=1;
>> x=r*sin(theta);
>> y=r*cos(theta);
>> plot(x,y)
>> hold on
>> plot(0,0,'+')

9
Graph Plotting

Q10.For question 1 write a program to draw a circle of arbitary radius 'r' using

script file.
Ans.
Create a new scipt aand type the following commands -
r=input('Enter the radius of circle:');
t=(0:pi/100:2*pi);
x=r*sin(t);
y=r*cos(t);
plot(x,y)

then Save it as Q10, then in command


window type -
>> Q10
it will ask then the radius of circle
like then I put it as 50, then finally it will plot the circle.

10
Graph Plotting

11

You might also like