// Plotting graph of the function
f(x)=log(1+x)
// between (0, 1) using Scilab 5.5.2 OR
above
clf();
x = [0.01:0.01:0.99];
y = log(1+x);
plot(x, y);
title('$ f(x) = log(1+x) $');
xlabel('x-axis');
ylabel('y-axis');
// Plotting graph of the function f(x)=1/
(2x+1)
// between (1, 2) using Scilab 5.5.2 OR
above
clf();
x = [1:0.01:2]';
y = 1 ./(2*x+1);
plot(x, y);
title('$ f(x) = \frac{1}{2^x+1} $');
xlabel('x-axis');
ylabel('y-axis');
// Plotting graph of the function
f(x)=sin(x/2)
// between (0, pi/2) using Scilab 5.5.2
OR above
clf();
x = [0.01:%pi/50:%pi];
y = sin(x./2);
plot(x, y);
title('$ f(x) = sin(\frac{x}{2}) $');
xlabel('x-axis');
ylabel('y-axis');
a=gca();
a.x_location="origin";
a.y_location="origin";
// Plotting graph of the function f(x)=
x^4+2x^2-2x+5
// between (-1, 1) using Scilab 5.5.2 OR
above
clf();
x = [-1:0.01:1]';
y = x^4+2*x^2-2*x+5;
plot(x, y);
title('$ f(x) = x^4+2x^2-2x+5 $');
xlabel('x-axis');
ylabel('y-axis');
a=gca();
a.x_location="origin";
a.y_location="origin";
// Plotting of curve f(x)=cos(x) from 0 to PI/2
// & rotate it about x-axis using Scilab 5.2.2
// rotation of any curve around ax+by+c=0
function [xx, yy, zz]=rotation(x, y, a, b, c, h)
xx=x(:)';
yy=y(:)';
theta=[0:h:2*%pi+h];
u=(cos(theta)-ones(theta))';
v=sin(theta)';
// Perpendicular Distance from a given point to the curve
d=sqrt(a^2+b^2);
a=a/d;
b=b/d;
c=c/d;
alpha=xx*a+yy*b+c;
zz=v*alpha;
xx=ones(u)*xx+u*alpha*a;
yy=ones(u)*yy+u*alpha*b;
endfunction
// Rotation of cos(x) about x-axis
t=[0:(%pi/2)/20:%pi/2];
f=cos(t);
[y,x,z]=rotation(f,t,1,0,0,0.1);
clf();
subplot(211)
plot(t,f);
xtitle('f(x)=cos(t)','x-axis','y-axis');
subplot(212);
plot3d2(x,y,z);
title('Rotation of cos(x) around x-axis');
// Plotting of curve f(x)=e^(x+1) from 0 to 2
// & rotate it about x-axis using Scilab 5.2.2 or above
// rotation of any curve around ax+by+c=0
function [xx, yy, zz]=rotation(x, y, a, b, c, h)
xx=x(:)';
yy=y(:)';
theta=[0:h:2*%pi+h];
u=(cos(theta)-ones(theta))';
v=sin(theta)';
// Perpendicular Distance from a given point to the curve
d=sqrt(a^2+b^2);
a=a/d;
b=b/d;
c=c/d;
alpha=xx*a+yy*b+c;
zz=v*alpha;
xx=ones(u)*xx+u*alpha*a;
yy=ones(u)*yy+u*alpha*b;
endfunction
// Rotation of e^(x+1) about y-axis
t=[0:0.1:2];
f=exp(t+1);
[y,x,z]=rotation(f,t,0,1,0,0.1);
clf();
subplot(211)
plot(t,f);
xtitle('f(x)=e^(x+1)','x-axis','y-axis');
a=gca();
a.x_location="origin";
a.y_location="origin";
subplot(212);
plot3d2(x,y,z);
title('Rotation of e^(x+1) about y-axis');
// Plotting of Parabola using Parametric
Equation
// y^2 = 4*a*x with a parameter t
// x = a*t^2 and y = 2*a*t using Scilab
5.5.2 or 6.0.0
clf();
t=[0:0.1:1.5];
a = 1;
x = a*t^2;
y = 2*a*t;
plot2d(x,y,6); // Upper Half
plot2d(x,-y,6); // Lower Half
xtitle('Parabola y^2=4ax','x-axis','yaxis');
s=gca();
s.x_location="origin";
s.y_location="origin";
// Plotting of hyperbola
clf();
A = [1/4 0; 0 -1/9];
theta = 0:%pi/100:2*%pi; // %pi is scilab for the constant pi
n = size(theta,2); // theta is a 1 x n row vector
x = zeros(theta); // x and y start as zero vectors
y = zeros(theta);
for i = 1:n,
angle = theta(i); // this angle
c = cos(angle);
s = sin(angle);
X = [ c, s ];
r = sqrt(1/abs(X*A*X'));
x(i) = r*c; // r cos(theta)
y(i) = r*s;
end;
plot(x,y,'b');
xtitle('$ \frac{x^2}{2^2}-\frac{y^2}{3^2}=1$','x','y');
a=gca();
a.isoview="on";
a.x_location="origin";
a.y_location="origin";
// Sketching of Ellipsoid x^2/a^2 + y^2/b^2 + z^2/c^2 = 1
// Using Scilab 5.2.2 or 6.0.0
clf();
n=50; // to generate a n by n matrix
function [x, y, z]=ellipsoid(a, b, c);
theta = [-n:2:n]/n*%pi;
phi = [-n:2:n]'/n*%pi/2;
cosphi = cos(phi);
cosphi(1) = 0;
cosphi(n+1) = 0;
sintheta = sin(theta);
sintheta(1) = 0; sintheta(n+1) = 0;
x = cosphi*cos(theta);
y = cosphi*sintheta;
z = sin(phi)*ones(1,n+1);
x = a*x;
y = b*y;
z = c*z;
endfunction
[x, y, z]=ellipsoid(2,3,4);
surf(x,y,z);
title(['Ellipsoid' '$\frac{x^2}{4} + \frac{y^2}{9} +
\frac{z^2}{16} = 1$'],'fontsize',5)
// Sketching of paraboloid z = 25 x^2 + 9
y^2
// Using Scilab 5.2.2 or 6.0.0
a=1/5;
b=1/3;
function z=f(x, y)
z = x^2/a^2 + y^2/b^2;
endfunction
x=[-1:0.05:1];
y=[-2:0.05:2];
z=feval(x,y,f)';
clf();
surf(x,y,z);
title(['Paraboloid' '$z=25x^2+9y^2$']);