You are on page 1of 24

QUESTION-1

The equation of a straight line is y = mx +c, where m and c are


constants. Compute the y-coordinates of a line with slope
m = 0.5 and the intercept c = -2 at the following x-coordinates:
x = 0, 1.5 , 3 , 4, 5 , 7, 9 , and 10.

x=[0 1.5 3 4 5 7 9 10]


y=0.5*x-2

QUESTION-2
Create a vector t with 10 elements: 1 , 2, 3, . . . , 10. Now compute
the following quantities.

1. X=t*sin(t)
2. Y=

t1
t +1

3. Z= sin(t2)/ t2

t=[1 2 3 4 5 6 7 8 9 10]
x= t.*sin(t)
y=(t+1)./(t-1)
z=(sin(t.^(2)))./(t.^(2))

QUESTION-3
Enter the following 2 matrices, and compute the following..
2 6

A= 3 9

1 2

B= 3 4

1. Addition of the two matrices. (X)


2. Multiplication of the two matrices. (Y)

A=[2 6; 3 9]
B=[1 2; 3 4]
X=A+B
y=A*B

QUESTION-4
Solve the system of linear equations by using matrix method.
(AX=B)
5x-y+4z=5
2x+3y+5z=2
5x-2y+6z=-1

A=[5 -1 4;2 3 5; 5 -2 6]
B=[5; 2; -1]
X=inv(A)\B

QUESTION-5
Plot y = exp(-0.4x).sin x ,where limit is 0 x 4 , taking
10, 50, and 100 points in the interval.

x=linspace(0,4*pi,10)
y=exp(-0.4*x).*sin(x)
plot(x,y)
x=linspace(0,4*pi,100)
y=exp(-0.4*x).*sin(x)
plot(x,y)
x=linspace(0,4*pi,100)
y=exp(-0.4*x).*sin(x)
plot(x,y)

% for interval 10

% for interval 50

% for interval 100

QUESTION-6
Use the command plot3(x,y,z) to plot the circular helix
X(t)=t cos(3 t), y(t)=t sin(3 t), z(t)=t.

t=linspace(0,20,10)
x= t.*cos(3.*pi.*t)
y=t.*sin(3.*pi.*t)
z=t
plot3(x,y,z)

QUESTION-7
A nonstiff system is the system of equations describing the motion
of a rigid body without external forces.

function main
[T,Y] = ode45(@rigid,[0 12],[0 1 1]);
plot(T,Y(:,1),'-',T,Y(:,2),'-.',T,Y(:,3),'.')
function dy = rigid(t,y)
dy = zeros(3,1);
dy(1) = y(2)* y(3);
dy(2) = -y(1) * y(3);
dy(3) = -0.51 * y(1) * y(2);

QUESTION-8
A reactant is decomposed by the ODE, plot a graph between
concentration vs. time. Time interval is from 0 to 100 sec.
Initially the reactant concentration is 0.05 mol/m 3.
dCa
dt

1
50

Ca

1
100

Ca(0)=0.05.

function main
[T,Y] = ode45(@rigid,[0 100],[0.05]);
plot(T,Y,'-.')
function dy = rigid(t,y)
dy = zeros(1,1);
dy(1) = 0.01-0.02*y(1);

QUESTION-9

(Boundary value problem) The second-order differential equation


has exactly two solutions that satisfy the boundary conditions
y(0) = 0,
Equation will be

y(4) = 2.
y + |y| = 0

function mainfunc
solinit = bvpinit(linspace(0,4,5),[1 0]);
sol = bvp4c(@twoode,@twobc,solinit);
x = linspace(0,4);
y = deval(sol,x);
plot(x,y(1,:));
function dydx = twoode(x,y)
dydx = [ y(2)
-abs(y(1))];
function res = twobc(ya,yb)
res = [ ya(1)
yb(1) + 2];

QUESTION-10
The radial temperature distribution in a sphere with external heat
source is given by differential equation
x
y-(1- e )y=0

Boundary conditions are


BC. 1: at x=0
BC.2: at x=1

y=0
dy
dx =y

x is the radius of the sphere


Obtain the temp profile (10)

function sphere
solinit=bvpinit(linspace(0,10,5),[1 0]);
sol=bvp4c(@twoode,@twobc,solinit);
x=linspace(0,10);
y=deval(sol,x);
plot(x,y(1,:));
function dydx = twoode(x,y)
dydx = [ y(2)
(1-exp(-x))*y(1)];
function res = twobc(ya,yb)
res = [ ya(1)-1
yb(1) ];

QUESTION-11
The following ODE, boundary value problem describe the action of
catalyst in a reactor
2 ( 1 y )

y=2 y exp [ 1+0.1 ( 1 y ) ]


where x=0
y=0
x=1
y=1
=1.0
Obtain the set of algebraic equations using finite diff. tech. and find the
temp profile (50).

function catalyst
solinit=bvpinit(linspace(0,1,5),[1 0]);
sol=bvp4c(@twoode,@twobc,solinit);
x=linspace(0,1);
y=deval(sol,x);
plot(x,y(1,:));
function dydx=twoode(x,y)
dydx=[y(2)
y(1)*exp((2-2*y(1))./(1.1-0.1*y(1)))];
function res=twobc(ya,yb)
res=[ya(2)
yb(1)-1];

QUESTION-12
The following ODE, boundary value problem describe heat transfer
in a straight fin of uniform cross section
d2y/dx2 +4y=0
where x=0
y=1
x=1
dy/dx=0.05y
Obtain the set of algebraic equations using finite diff. tech. and find the
temp profile (100).

function heat
solinit=bvpinit(linspace(0,1,5),[1 0]);
sol=bvp4c(@twoode,@twobc,solinit);
x=linspace(0,1);
y=deval(sol,x);
plot(x,y(1,:));
function dydx=twoode(x,y)
dydx=[y(2)
((-4*y(1))+(x^2))]
function res=twobc(ya,yb)
res=[ya(1)-1
yb(2)+0.05.*yb(1)];

QUESTION-13
Try to solve the third order differential equation

d3y/dx3 = 6xy +2 d2y/dx2

boundary conditions are


1.
Y=2
at x=0
2.
Y=0
at x=5
3.

dy
dx

=0 at

x=5

function thirdorder
solinit=bvpinit(linspace(0,5,5),[1 0 0]);
sol=bvp4c(@twoode,@twobc,solinit);
x=linspace(0,5);
y=deval(sol,x);
plot(x,y(1,:));
function dydx=twoode(x,y)
dydx=[y(2)
y(3)
2*y(3) + (6*x*y(1))];
function res=twobc(ya,yb)
res=[ya(1)-2
yb(1)
yb(2)];

QUESTION-14

The stiff system is provided by the van der Pol equations in


relaxation oscillation. The limit cycle has portions where the solution
components change slowly and the problem is quite stiff, alternating with
regions of very sharp change where it is not stiff.

[T,Y] = ode15s(@vdp1000,[0 3000],[2 0]);


plot(T,Y(:,1),'-o')

QUESTION-15
Solve these equations using Newton-Raphson technique starting
with
X(1)=[1 1]T
F1(X)= 2x12-5x22-3 = 0
F2(X)= 3x12+2x22-26=0

function newtonraphson
x0 = [0; 0];
[x,fval] = fsolve(@myfun,x0)
function F = myfun(x)
F = [(2*(x(1)^2) - 5* x(2)^2 - 3);
( 3*(x(1)^3) + 2*x(2)^2 - 26)];

QUESTION-16

The following ODE, boundary value problem describe heat transfer


in a straight fin of uniform cross section
d2t/dx2 -m2t=0
where x=0
t=1
x=1
dt/dx=-(bi)t
t is the dimensionless temperature at any positioning the fin
x dimensionless
Bi=biot number=0.05
M= constant 2.13
Obtain the set of algebraic equations using finite diff. tech. and find the
temp profile (20).

function heat
solinit=bvpinit(linspace(0,1,20),[1 0]);
sol=bvp4c(@twoode,@twobc,solinit);
x=linspace(0,1);
y=deval(sol,x);
plot(x,y(1,:));
function dydx=twoode(x,y)
dydx=[0.05*y(1)
-4.53*y(1)];
function res=twobc(ya,yb)
res=[ya(1)-1
yb(2)+0.05*yb(1)];

You might also like