Uploaded by Patel Yagnik

CTCE Assignment-3 by Yagnik Patel

advertisement
Name: Yagnik Patel
PRN NO: 2019033800127612
Exam NO: 501022
Team id: yagnikpatel17111@gmail.com
Assignment-3
Write Syntax, description and example for each command.
1. Perform diary command.
octave:1> diary yagnik
octave:2> x=linspace(10,20,5)
x=
10.000 12.500 15.000 17.500 20.000
octave:4> a=b+c;
octave:5> x=x.*2;
octave:6> diary off
2. Plot the following graphs and give appropriate title, legend ,
labels, different colours and markers.
ο‚· Plotting one graph in one figure window:
a. y=x2 in the interval [−2,2]. (Using colon operator)
octave:1> x=-2:2;
octave:2> y=x.^2;
octave:5> plot(x,y,'r--','linewidth',2)
octave:6> title('Graph of y=x^2')
octave:7> grid
octave:10> xlabel('Value of x'), ylabel('Value of y')
b. y=x3−4x−9 in the interval [2,3]. (Using linspace() function)
octave:11>
octave:12>
octave:13>
octave:14>
x=linspace(2,3,10);
y=x.^3-x*4-9;
plot(x,y,'rs:')
title('Graph of y=f(x)')
octave:15> grid
octave:16> xlabel('Value of x'), ylabel('Value of y')
Plotting two graphs in two figure windows: (Using figure command
and xlim() command)
a. y=sin(x) and z=cos(x) in the interval [−2π,2π].
octave:17> figure(1)
octave:18> x=linspace(-2*pi,2*pi,20);
octave:19> y=sin(x);
octave:22> plot(x,y,'y*-','linewidth',2),xlim([-pi,pi]),ylim([-1,1])
octave:23> grid
octave:24> title('Graph of sin(x)')
octave:25> xlabel('Value of x'),ylabel('Value of y')
b. y=sin−1(x) and z = cos−1 (x) in the interval [−1,1].
octave:26>
octave:28>
octave:29>
octave:30>
octave:31>
octave:32>
octave:33>
figure(2)
x=linspace(-2*pi,2*pi,20);
z=cos(x);
plot(x,y,'g*-','linewidth',2),xlim([-pi,pi]),ylim([-1,1])
grid
title('Graph of cos(x)')
xlabel('Value of x'), ylabel('Value of y')
c. y=sin−1(x) and z = cos−1 (x) in the interval [−1,1].
octave:38>
octave:39>
octave:40>
octave:42>
octave:43>
octave:44>
octave:45>
x=linspace(-1,1,10);
y=asin(x);
figure(1)
plot(x,y,'rx-','linewidth',2),xlim([-0.9,0.9])
grid
title('Graph of sin^-1(x)')
xlabel('Values of x'),ylabel('Values of f(x)')
octave:47> x=linspace(-1,1,10);
octave:48> z=acos(x);
octave:49> figure(2)
octave:50> plot(x,z,'k.-','linewidth',2),xlim([-0.9,0.9])
octave:51> grid
octave:52> title('Graph of cos^-1(x)'),xlabel('Value of
x'),ylabel('Value of f(x)')
Plotting three graphs in three figure windows: (Also use grid on
in each graph)
a. y1 =cosx−xe^x in the interval [−1,1] , y2=cosx− 3x+1 in the
interval [−π/2,π/2] and y3=2x−log10x−7 in the interval [3,4].
octave:1> x=-1:0.1:1;
octave:2> a=cos(x);
octave:3> b=exp(x);
octave:4> c=x.*b;
octave:5> y1=a-c;
octave:6> figure(1)
octave:7> plot(x,y1,'m.-')
octave:8> grid,title('Graph of cos(x)-xe^x vs x'),xlabel('Values
of x'),ylabel('Values of f(x)')
octave:9> x=linspace(-pi/2,pi/2,10);
octave:10> y2=cos(x)-3.*x+1;
octave:11> figure(2)
octave:12> plot(x,y2,'m.--')
octave:13> grid
octave:14> title('Dashed line Graph'),xlabel('Values of
x'),ylabel('Values of f(x)')
octave:15> x=3:0.1:4;
octave:16> a=2*x;
octave:17> b=log10(x);
octave:18> y3=a-b-7;
octave:19> figure(3)
octave:20> plot(x,y3,'m.--')
octave:22> title('Dash-dot Graph'),xlabel('Values of
x'),ylabel('Values of f(x)')
Plot two graphs in same figure window:
Using hold on/hold off
a. y = tsint and z=tcost in the interval [0,10π]
octave:24> t=linspace(0,10*pi,20);
octave:26> y=t.*sin(t);
octave:27> plot(t,y,'c^-')
octave:28> hold on
octave:29> z=t.*cos(t);
octave:30> plot(t,z,'k*-')
octave:31> title('Two graph in same window'),xlabel('Value of
t'),ylabel('Values of f(t)'),legend('y=t.*sin(t)','z=t.*cos(t)')
Using plot (x, y, ’^r’, x, z, ’og’)
a. y=sin(x)x and z =cos(x) in the interval [−3π,3π]
octave:32> x=linspace(-3*pi,3*pi,10);
octave:33> y=sin(x)/x;
octave:34> y=sin(x)./x;
octave:35> z=cos(x);
octave:36> plot(x,y,'^r',x,z,'og')
octave:37> title('Multiple Graph'),xlabel('Values of
x'),ylabel('Values of F(t)')
Multiple graphs in same figure window: (Using subplot(m, n, p))
(1) C= 4e^−2t+e^−0.1t in the interval [1,7] , y = x 4 + x3 – 7x2 – x + 5
in the interval [2,3] , z = t2cos(3t) in the interval [−3π,3π] and w
=tsin(t/2) in the interval [0,2π].
octave:38>
octave:39>
octave:40>
octave:41>
octave:42>
octave:43>
octave:44>
t=linspace(1,7,10);
a=4*exp(-2*t);
b=exp(-0.1*t);
c=a+b;
subplot(2,2,1),plot(t,c,'y.-')
grid
title('G-1')
octave:45> x=linspace(2,3,10);
octave:47> y=x.^4+x.^3-(7*x.^2)-x+5;
octave:49> subplot(2,2,2),plot(x,y,'r.-'),grid,title('G-2')
octave:50>
octave:51>
octave:52>
octave:53>
octave:54>
t=linspace(-3*pi,3*pi,10);
a=t.^2;
b=cos(3*t);
z=a.*b;
subplot(2,2,3),plot(t,z,'k.-'),title('G-3'),grid
octave:55>
octave:56>
octave:57>
octave:58>
t=linspace(0,2*pi,10);
a=sin(t/2);
z=t.*a;
subplot(2,2,4),plot(x,z,'g.-'),title('G-4'),grid
(2) y1=xsinx+cosx in the interval [−π,π] , y2=2x−3sinx−5 in the
interval [0,2π], y3=xlogex−1.2 in the interval [2,3].
octave:0> x=linspace(-pi,pi,10);
octave:60> a=x.*sin(x);
octave:61> b=cos(x);
octave:62> y1=a+b;
octave:63> subplot(1,3,1),plot(x,y1,'c.-'),title('G-1'),gird
octave:70> x=linspace(0,2*pi,10);
octave:72> y2=2*x-3*sin(x)-5;
octave:73> subplot(1,3,2),plot(x,y2,'k.-'),title('G-2'),grid
octave:75>
octave:76>
octave:77>
octave:78>
x=linspace(2,3,10);
a=log(x);
y3=x.*a-1.2;
subplot(1,3,3),plot(x,y3,'m.-'),title('G-3'),grid
(3) y1=√x3−x3 in the interval [−3,3] , y2=sinxβˆ™sin2x in the interval
[0,2π] and y3=ln(x2−4x+5) in the interval [−2,5].
octave:79> x=linspace(-3,3,10);
octave:80> a=x.^3-x;
octave:81> y1=cbrt(a);
octave:82> subplot(3,1,1),plot(x,y1,'g.-'),title('G-1'),grid
octave:83>
octave:84>
octave:85>
octave:86>
octave:87>
x=linspace(0,2*pi,10);
a=sin(x);
b=sin(2*x);
y=a.*b;
subplot(3,1,2),plot(x,y,'r.-'),title('G-2'),grid
octave:88>
octave:89>
octave:90>
octave:91>
x=linspace(-2,5,10);
a=x.^2-4.*x+5;
y3=log(a);
subplot(3,1,3),plot(x,y3,'b.-'),title('G-3'),grid
Plotting using fplot:
a. f(x)= e−x10sin(x) ; 0<x<20
octave:94> f=@(x)exp(-x/10)*sin(x)
f=
@(x) exp (-x / 10) * sin (x)
octave:95> class(f)
ans = function_handle
octave:96> fplot(f,[0,20])
b. 𝑓(π‘₯)=tan(π‘₯) ; [−5πœ‹,5πœ‹]
octave:1> f=@(x)tan(x);
octave:2> fplot(f,[-5*pi,5*pi]),grid,title('Graph of
Tan(x)'),xlabel('Values of x'),ylabel('Values of F(x)')
Plotting of Polar Curves: (Using polar command)
a. r2=2sin5t ; 0≤t≤2π
octave:3>
octave:4>
octave:5>
octave:6>
t=linspace(0,2*pi,100);
a=sin(5*t);
r=sqrt(2*a);
polar(t,r,'g.-')
b. r = 3 –3cosθ ; 0≤θ≤2π
octave:8> o=linspace(0,2*pi,150);
octave:9> r=3-3*cos(o);
octave:10> polar(o,r,'m.--')
c. π‘Ÿ = 1−2sinπœƒ ; 0≤πœƒ≤2πœ‹
octave:12> t=linspace(0,2*pi,500);
octave:13> r=1-2*sin(t);
octave:14> polar(t,r,'p.-')
Plotting using comet command:
a. y=cosxβˆ™cos3x ; 0≤π‘₯≤2πœ‹
octave:15> x=linspace(0,2*pi,10);
octave:16> y=cos(x).*cos(3*x);
octave:18> comet(x,y)
b. 𝑧=𝑒−π‘‘βˆ™π‘‘2 ; 0≤𝑑≤10
octave:25>
octave:26>
octave:27>
octave:28>
octave:29>
t=linspace(0,10,30);
a=exp(-t);
b=t.^2;
y=a.*b;
comet(t,y)
Download