Pre Solutions of Old Papers 1573360064915 1 1631425497745 1656220859798
Pre Solutions of Old Papers 1573360064915 1 1631425497745 1656220859798
docx
TA ZC 164 compre 17-18 Solutions.docx
TA ZC 164 EC-3 17-18 Solutions.docx
TA ZC 164 EC-3 17-18 Solutions.pdf
TA ZC164 EC-3R FIRST SEM 2018-2019-Revised solutions.docx
TA ZC164 EC-3R FIRST SEM 2018-2019-Revised Solutions.pdf
TA ZC164 EC-3R SECOND SEM 2017-2018-Solutions.docx
TA ZC164 EC-3R SECOND Semester 2018-19- Solutions.docx
TA ZC164 EC-II 2017-2018-Solutions.docx
CUMMINS-COMPRE SOLUTIONS.docx
MATLAB Old Paper+Solution.doc
Solutions-EC3M.docx
Birla Institute of Technology & Science, Pilani
Work-Integrated Learning Programmes Division
Second Semester 2018-2019
Mid-Semester Test
(EC-2 Make-up)
Solution
𝟏. 𝟐 −𝟑. 𝟒 𝟑. 𝟔
Q.2 The array d has the values [𝟎. 𝟖 𝟏. 𝟒 −𝟎. 𝟖] [3]
𝟏. 𝟓 𝟎. 𝟔 𝟓. 𝟎
Solution
(i) What is the size of array d and which command will you d= 3 x 3 , size(d)
use in MATLAB to determine it
(ii) What is the value of d(3,2) ? 0.6
(iii) What subscripts does d (?,?)=0.6 will contain ? 3,2
m=
20 21 3 4
22 23 7 8
9 10 11 12
(iii) What is result of following m (2,:) ? ans = 22 23 7 8, It will print second row
Q.4 What will be the result of the following commands in MATLAB [3]
(i) a=eye(3) It will print an Identity Matrix of 3 *3
(ii) b=zeros(2,3) It will print a 2*3 matrix consisting of all zero elements
(iii) clear and clc clear will clear workspace variables and clc will clear the screen
Q.5 Write a MATLAB program that prints the areas of a cylindrical pressure vessel used in chemical industry. The radius varies from 4 cm to 4.5
cm with 0.1 cm increments. Determine the areas of such varying radii with a constant height of 5 m. The Area of the cylinder is 𝐴𝑟𝑒𝑎 = 2𝜋𝑟ℎ +
𝜋𝑟 2 [3]
h=5;
%area=zeros(1,5)
r=4.0:0.1:4.5
for i=1:5
area(i)=2*pi*r(i)*h+pi*r(i)^2
end
fprintf('%The area of cylinders with varying r is %f\n',area(i));
ans =
logical
1
% Consider x as Income
if (x<500000)
tax1=0
elseif (x>500000 && x<1000000)
tax1=(x-500000)*0.10
elseif (x>1000000 && x<2000000)
tax1=(x-1000000)*0.20+500000*0.10
fprintf('The Tax for x is %.2f', x,tax1);
end
Q.8 The continuity equation in fluid dynamics for steady fluid flow through a stream tube equates the product of the density, velocity,
and area at two points that have varying cross-sectional areas. For incompressible flow, the densities are constant so the equation
𝐴1
is A1V1 = A2V2. If the areas and V1 are known, V2 can be found as 𝐴2 𝑉1.
Therefore, whether the velocity at the second point increases or decreases
depends on the areas at the two points. Write a script that will prompt the user
for the two areas in feet squared, and will print whether the velocity at the second
point will increase, decrease, or remain the same as at the first point [4]
% COMMENTS--- V2 will increase if A1 is greater that A2 that is V2 is more than V1 , Similarly viceversa, If Areas are same velocities
are same
Q.9. Water near the surface of a tropical ocean has a temperature of 298.2K (250oC), whereas water 700m beneath the surface has a
temperature of 280.2K (7.0oC). It has been proposed that the warm water be used as the hot reservoir and the cool water as the
cold reservoir of a heat engine. Find the maximum possible efficiency for such an engine. Analytical solution is give. Convert
the same into the necessary generalized function [4]
Solution:
Given data,
Th = 298.2 K
TI = 280.2 K
The maximum possible efficiency is the efficiency that a Carnot engine would have operating between these two temperatures. Substitute the value in the
corresponding formula,
η = (Th−TI)/Th
η = (298.2−280)/280)
η = 0.060 (6.0%)
Therefore, the maximum possible efficiency is 6 %
function eff=carnot(Th,Ti)
eff=(Th-Ti)/ Th * 100;
end
Birla Institute of Technology & Science, Pilani
Work-Integrated Learning Programmes Division
First Semester 2017-2018
Comprehensive Examination Test (EC-3 Regular)
Solutions
(a) 8.2
(b) 4 Round to nearest decimal or integer
(c) 729
(d) 4 Round toward positive infinity
(e) 1
Q.2 Using the zeros, ones, and eye commands create the following arrays
0 0 1 1
0 0 1 1
a) [ ]
0 0 0 0
1 1 1 1
Solution (a)
1 1 0 0 1
1 1 0 0 0
b) [ ]
1 1 0 0 0
1 1 0 0 0
Solution (b)
Q.3 A juice company manufactures one-gallon bottles of three types of juice blends using
orange, pineapple, and mango juice. The blends have the following compositions:
1 gallon orange blend: 3 quarts of orange juice, 0.75 quart of pineapple juice,
0.25 quart of mango juice.
1 gallon pineapple blend: 1 quart of orange juice, 2.5 quarts of pineapple
juice, 0.5 quart of mango juice. 1 gallon mango blend: 0.5 quart of orange juice, 0.5
quart of pineapple juice,3 quarts of mango juice.
How many gallons of each blend can be manufactured if 7,600 gallons of orange juice,
4,900 gallons of pineapple juice, and 3,500 gallons mango juice are available? Write a
system of linear equations and solve in MATLAB only steps
Solution
Set up Equations
X=3*x+0.75*y+0.25*z
Y=x+2.5*y+0.5*z
Z=0.5*x+0.5*y+3*z
MATLAB
a=[3,0.75,0.25;1,2.5,0.5;0.5,0.5,3]
b=[7600;4900;3500]
c=inv(a)* b
Ans [ x= 2246 gallons orange juice, y=933 gallons pineapple, z=636 gallons mango juice]
Q.4 Viscosity, μ, is a property of gases and fluids that characterizes their resistance to flow.
For most materials viscosity is highly sensitive to temperature. Below is a table that
gives the viscosity of SAE 10W oil at different temperatures (Data from B.R. Munson,
D.F. Young, and T.H. Okiishi, Fundamentals of Fluid Mechanics, 4th ed., John Wiley
and Sons, 2002). Determine an equation that can be fitted to data.
The straight line does not fit the point , Therefore the equation can be fitted as
ln(𝜇) = 𝑎2 𝑇 2 + 𝑎1 𝑇+𝑎0 .
The function can be fitted to the data using polyfit(x,y,2) second degree
polynomial, T is independent variable in 0K (C+273) and ln µ. Write the
Program that best fits the program with calculation of coefficients and display
the data points and function.
Q.5 Create a data in some other program on your computer. (% use a separate file
say data) such as excel, word and so forth. Copy the data set to the clipboard
using the windows and then use function uiimport to load the data set into
MATLAB
s=uiimport('C:\Users\BITS7\Documents\MATLAB\testexam.xlsx')
Q.7 Plot the function 𝑦 = 𝑒 −𝑥 𝑠𝑖𝑛𝑥 for x between 0 and 2 in steps of 0 1 . Create
the following plot types (a) stem plot (b) stair plot (c) bar plot . Be sure to
include titles and axis labels on all plots
x=0:0.1:2;
y=exp(-x)*sin(x);
stem(x,y);
bar(x,y);
title(‘stem and bar Plot’);
xaxis(‘x coordinate’)
yaxis(‘function’);
Q.8 Fluid flows in pipe networks can be analyzed in a manner similar to that used
for electric resistance networks. The Figure below shows a network with three
pipes. The volume flow rates in the pipes are q1, q2, and q3 . The pressures at the
pipe ends are pa, pb and pc, . The pressures at the junction is p1. Under certain
condition, the pressure flow rate relation in a pipe has the same form as the
voltage-current relation in a resistor.Thus, for the three pipes, we have
a. Set up these equations in a matrix form Ax=b suitable for solving for the
three flow rates q1, q2, q3, and the pressure p1 given the values of pressures
pa, pb and pc and the values of resistances R1, R2, and R3. Find expressions
of A and B
Birla Institute of Technology & Science, Pilani
Work-Integrated Learning Programmes Division
First Semester 2017-2018
Comprehensive Examination Test (EC-3 Regular)
Solutions
(a) 8.2
(b) 4 Round to nearest decimal or integer
(c) 729
(d) 4 Round toward positive infinity
(e) 1
Q.2 Using the zeros, ones, and eye commands create the following arrays
0 0 1 1
0 0 1 1
a) [ ]
0 0 0 0
1 1 1 1
Solution (a)
1 1 0 0 1
1 1 0 0 0
b) [ ]
1 1 0 0 0
1 1 0 0 0
Solution (b)
Q.3 A juice company manufactures one-gallon bottles of three types of juice blends using
orange, pineapple, and mango juice. The blends have the following compositions:
1 gallon orange blend: 3 quarts of orange juice, 0.75 quart of pineapple juice,
0.25 quart of mango juice.
1 gallon pineapple blend: 1 quart of orange juice, 2.5 quarts of pineapple
juice, 0.5 quart of mango juice. 1 gallon mango blend: 0.5 quart of orange juice, 0.5
quart of pineapple juice,3 quarts of mango juice.
How many gallons of each blend can be manufactured if 7,600 gallons of orange juice,
4,900 gallons of pineapple juice, and 3,500 gallons mango juice are available? Write a
system of linear equations and solve in MATLAB only steps
Solution
Set up Equations
X=3*x+0.75*y+0.25*z
Y=x+2.5*y+0.5*z
Z=0.5*x+0.5*y+3*z
MATLAB
a=[3,0.75,0.25;1,2.5,0.5;0.5,0.5,3]
b=[7600;4900;3500]
c=inv(a)* b
Ans [ x= 2246 gallons orange juice, y=933 gallons pineapple, z=636 gallons mango juice]
Q.4 Viscosity, μ, is a property of gases and fluids that characterizes their resistance to flow.
For most materials viscosity is highly sensitive to temperature. Below is a table that
gives the viscosity of SAE 10W oil at different temperatures (Data from B.R. Munson,
D.F. Young, and T.H. Okiishi, Fundamentals of Fluid Mechanics, 4th ed., John Wiley
and Sons, 2002). Determine an equation that can be fitted to data.
The straight line does not fit the point , Therefore the equation can be fitted as
ln(𝜇) = 𝑎2 𝑇 2 + 𝑎1 𝑇+𝑎0 .
The function can be fitted to the data using polyfit(x,y,2) second degree
polynomial, T is independent variable in 0K (C+273) and ln µ. Write the
Program that best fits the program with calculation of coefficients and display
the data points and function.
Q.5 Create a data in some other program on your computer. (% use a separate file
say data) such as excel, word and so forth. Copy the data set to the clipboard
using the windows and then use function uiimport to load the data set into
MATLAB
s=uiimport('C:\Users\BITS7\Documents\MATLAB\testexam.xlsx')
Q.7 Plot the function 𝑦 = 𝑒 −𝑥 𝑠𝑖𝑛𝑥 for x between 0 and 2 in steps of 0 1 . Create
the following plot types (a) stem plot (b) stair plot (c) bar plot . Be sure to
include titles and axis labels on all plots
x=0:0.1:2;
y=exp(-x)*sin(x);
stem(x,y);
bar(x,y);
title(‘stem and bar Plot’);
xaxis(‘x coordinate’)
yaxis(‘function’);
Q.8 Fluid flows in pipe networks can be analyzed in a manner similar to that used
for electric resistance networks. The Figure below shows a network with three
pipes. The volume flow rates in the pipes are q1, q2, and q3 . The pressures at the
pipe ends are pa, pb and pc, . The pressures at the junction is p1. Under certain
condition, the pressure flow rate relation in a pipe has the same form as the
voltage-current relation in a resistor.Thus, for the three pipes, we have
a. Set up these equations in a matrix form Ax=b suitable for solving for the
three flow rates q1, q2, q3, and the pressure p1 given the values of pressures
pa, pb and pc and the values of resistances R1, R2, and R3. Find expressions
of A and B
Birla Institute of Technology & Science, Pilani
Work-Integrated Learning Programmes Division
First Semester 2017-2018
Comprehensive Examination Test (EC-3 Regular)
Solutions
(a) 8.2
(b) 4 Round to nearest decimal or integer
(c) 729
(d) 4 Round toward positive infinity
(e) 1
Q.2 Using the zeros, ones, and eye commands create the following arrays
0 0 1 1
0 0 1 1
a) [ ]
0 0 0 0
1 1 1 1
Solution (a)
1 1 0 0 1
1 1 0 0 0
b) [ ]
1 1 0 0 0
1 1 0 0 0
Solution (b)
Q.3 A juice company manufactures one-gallon bottles of three types of juice blends using
orange, pineapple, and mango juice. The blends have the following compositions:
1 gallon orange blend: 3 quarts of orange juice, 0.75 quart of pineapple juice,
0.25 quart of mango juice.
1 gallon pineapple blend: 1 quart of orange juice, 2.5 quarts of pineapple
juice, 0.5 quart of mango juice. 1 gallon mango blend: 0.5 quart of orange juice, 0.5
quart of pineapple juice,3 quarts of mango juice.
How many gallons of each blend can be manufactured if 7,600 gallons of orange juice,
4,900 gallons of pineapple juice, and 3,500 gallons mango juice are available? Write a
system of linear equations and solve in MATLAB only steps
Solution
Set up Equations
X=3*x+0.75*y+0.25*z
Y=x+2.5*y+0.5*z
Z=0.5*x+0.5*y+3*z
MATLAB
a=[3,0.75,0.25;1,2.5,0.5;0.5,0.5,3]
b=[7600;4900;3500]
c=inv(a)* b
Ans [ x= 2246 gallons orange juice, y=933 gallons pineapple, z=636 gallons mango juice]
Q.4 Viscosity, μ, is a property of gases and fluids that characterizes their resistance to flow.
For most materials viscosity is highly sensitive to temperature. Below is a table that
gives the viscosity of SAE 10W oil at different temperatures (Data from B.R. Munson,
D.F. Young, and T.H. Okiishi, Fundamentals of Fluid Mechanics, 4th ed., John Wiley
and Sons, 2002). Determine an equation that can be fitted to data.
The straight line does not fit the point , Therefore the equation can be fitted as
ln(𝜇) = 𝑎2 𝑇 2 + 𝑎1 𝑇+𝑎0 .
The function can be fitted to the data using polyfit(x,y,2) second degree
polynomial, T is independent variable in 0K (C+273) and ln µ. Write the
Program that best fits the program with calculation of coefficients and display
the data points and function.
Q.5 Create a data in some other program on your computer. (% use a separate file
say data) such as excel, word and so forth. Copy the data set to the clipboard
using the windows and then use function uiimport to load the data set into
MATLAB
s=uiimport('C:\Users\BITS7\Documents\MATLAB\testexam.xlsx')
Q.7 Plot the function 𝑦 = 𝑒 −𝑥 𝑠𝑖𝑛𝑥 for x between 0 and 2 in steps of 0 1 . Create
the following plot types (a) stem plot (b) stair plot (c) bar plot . Be sure to
include titles and axis labels on all plots
x=0:0.1:2;
y=exp(-x)*sin(x);
stem(x,y);
bar(x,y);
title(‘stem and bar Plot’);
xaxis(‘x coordinate’)
yaxis(‘function’);
Q.8 Fluid flows in pipe networks can be analyzed in a manner similar to that used
for electric resistance networks. The Figure below shows a network with three
pipes. The volume flow rates in the pipes are q1, q2, and q3 . The pressures at the
pipe ends are pa, pb and pc, . The pressures at the junction is p1. Under certain
condition, the pressure flow rate relation in a pipe has the same form as the
voltage-current relation in a resistor.Thus, for the three pipes, we have
a. Set up these equations in a matrix form Ax=b suitable for solving for the
three flow rates q1, q2, q3, and the pressure p1 given the values of pressures
pa, pb and pc and the values of resistances R1, R2, and R3. Find expressions
of A and B
Birla Institute of Technology & Science, Pilani
Work-Integrated Learning Programmes Division
First Semester 2018-2019
Comprehensive Examination (EC-3 Regular)
fid:File Identifier
fopen: File opening [1]
compre.dat: File name in data type
‘r’: opened for reading [1]
b) What is the use of fscanf and fprintf in file handling? Give 1 example each
fscanf( fileID , formatSpec ) reads data from an open text file into column vector A and interprets
values in the file according to the format specified by [1]
min(a) will print the minimum values of the columns. It will print 1 and 2 in column
[1]
1 2 [1]
min(a,[],2) will print the minimum values of the columns. It will print 1 and 2 in row
[1]
1
3 [1]
5
Example
a=
18 11 16
19 20 11 [1]
ans =
7.0000 10.0000 9.0000 5.5000 6.0000 9.0000
g) >>a=eye(3);
>>sparse(a) which elements will it print ?
ans =
(1,1) 1
(2,2) 1
(3,3) 1 [1]
h) Construct an equivalent statement using single if statement in MATLAB for the following
block If x<y
If z<10
W=x*y*z
i) Accepts marks of the students as p and if p is greater than 50 print pass else print fail
j) Which command will you use to find the solution of simultaneous equation and how?
1000 288
2000 281
3000 269
5000 256
10000 223
Write a script that will load this data into a matrix, separate it into vectors, and then plot
the data with appropriate axis labels and a title. [4]
Solution
A=[1000,2000,3000,5000,10000];
T=[288, 281,269,256,223];
save atm.dat A T –ascii
load atm.dat
plot(A,T)
legend(‘Altitudes versus Temperature’)
xlabel(‘Altitude’)
ylabel(‘Temperature’)
TA ZC164 (EC-3 Regular) First Semester 2018-2019 Page 2
Solution
ans =
2.7947 + 6.5277i
2.7947 - 6.5277i (No marks , this is just output, only command is sufficient)
0.7053 + 0.4436i
0.7053 - 0.4436i
>> syms x
>> f=(@)x 𝑥 4 − 7𝑥 3 + 59𝑥 2 − 75𝑥 + 35
>> f(9) [1.5]
f(9)
ans = (No marks , this is just output, only command is sufficient)
5597
>> x=linspace(-1.5,6.7,20)
>> f=@(x) x.^4-7*x.^3+59*x.^2-75.*x+35 [1]
>> plot(x,f(x))
time=[0 1 2 3 4 5 6];
temperature=[300 150 75 35 12 5 2];
polyfit(time,temperature,1)
%% It does not describe correct description as at time=0
temperature should be 300
polyfit(time,temperature,2)
%% It does not describe correct description as at time=0
temperature should be 300
y=polyfit(time,temperature,3)
plot(time,temperature)
% now checking
time=[0 1 2 3 4 5 6];
y= y(1)*time.^3+y(2)*time.^2+y(3)*time+y(4)
time=[0 1 2 3 4 5 6];
y= y(1)*time.^3+y(2)*time.^2+y(3)*time+y(4)
plot(time,temperature,'b',time,y,'r')
time=linspace(0,10*pi,50)
x=cos(time);
y=sin(time)
z=sqrt(x.^2+y.^2)
figure(1)
plot3(x,y,z);
figure(2)
[X Y]=meshgrid(x,y);
surf(X Y z);
Give full marks only if steps are followed
Q.6 Write a function that will receive the temperature in deg oC and convert the temperature
to dego F and deg0 K. Use the standard conversion formula for deg C to deg F [4]
*********
Birla Institute of Technology & Science, Pilani
Work-Integrated Learning Programmes Division
1. A firm manufactures two types of products P1 and P2 and sells them on a profit of Rs. 3 on type P1 and Rs. 4 on type P2. Each product is processed on two machines A
and B. Type P1 requires 2 minutes of processing time on A and one minute on B; type P2 requires 3 minutes on A and 2 minutes on B. The machine A is available for not
more than 7 hours 30 minutes while machine B is available for 12 hours during any working day. Formulate the problem as an LPP.
2 Marks
ANSWER
clear
clc
c=[-3;-4;0;0];
A=[2 3 1 0;1 2 0 1;0 0 1 0;0 0 0 1];
b=[450;720;0;0];
Aeq=zeros(4,4);
Beq=zeros(4,1);
lb=zeros(4,1);
ub=[inf,inf,inf,inf];
x=linprog(c,A,b,Aeq,Beq,lb,ub)
2. A manufacturer produces three types of plastic fixtures. The time required for molding, trimming, and packaging is given in Table .1. (Times are given in hours per dozen
fixtures.) 2 Marks
Trimming 1 4,600
Packaging 2,400
How many dozen of each type of fixture should be produced to obtain a maximum profit? 2 marks
ANSWER
clear
clc
c=[-110;-160;-150;0;0;0];
A=[1 2 1.5 1 0 0;2/3 2/3 1 0 1 0; 0.5 1/3 0.5 0 0 1;0 0 0 1 0 0;0 0 0 0 1 0;0 0 0 0 0 1];
b=[12000;4600; 2400; 0;0;0];
Aeq=zeros(6,6);
Beq=zeros(6,1);
lb=zeros(6,1);
ub=[inf,inf,inf,inf,inf,inf];
x=linprog(c,A,b,Aeq,Beq,lb,ub)
Tutorial 2: Efficiency Problems:Use Functions
3. Calculate the maximum theoretical thermal efficiency of a coal-fired power station that heats steam to 500°C and cools it in a condenser at 35°C
The temperature of the gases in a car engine during combustion is 1700°C. The exhaust is expelled at 75°C. Calculate the maximum theoretical thermal efficiency of the
engine. 2 Marks
ANSWER
clear
clc
t1=1700 +273; % Temperature of steam in Kelvin
t2=75 + 273; % Temperature of the condenser in Kelvin
eff=1-(t2/t1); % maximum efficiency
efficiency=eff*100;
fprintf('Highest efficiency in percentage is %8.2f\n', efficiency)
4. Create a function in MATLAB to calculate the ideal air standard cycle efficiency based on the Otto cycle for a gas engine with a cylinder bore of 50 mm, a stroke of 75 mm
3
and a clearance volume of 21.3 cm .Take the inputs as Cylinder bore, clearance volume and get the outputs of compression ratio and efficiency. The calculations are done
as follows in the snapshot 2 Marks
Analytical Solution
As we know swept volume = 502 75 147200 m3 =147.2 cm3
4
3
Therefore the total cylinder volume = 147 + 21.3 = 168 cm
168.5
Compression ratio , rv = = 7.914 / 1
21.3
1
Then use the equation 1 1
rv
1
= 1-
7.9140.4
= 56.3 %
Solve using MATLAB function :It should be generalized program, any values inputed should give result
ANSWER
clc
% Inputs
a=input('Cylinder bore in mm');
b=input('Clearance Volume in cm');
% Calculations of cylinder volume
vol=(pi/4)*a^2*75/1000+b;
% Calculations of Compression ratio
CR=vol/b;
eff=(1-(1/CR^0.4))*100;
fprintf('compression ratio is %8.2f\n', CR);
fprintf('Efficiency is %8.2f\n', eff);
Tutorial 3: Gauss Siedel Iteration
5. Use Gauss Siedel iteration to find the values in x1, x2, x3 2 marks
4x1 + x2 - x3 = 3
2x1 + 7 x2 + x3 = 19
x1 - 3 x2 +12 x3 = 31
ANSWER
% find the values of given equation using gauss seidel iteration method
clear
clc;
f1=@(x,y,z) (1/4)*(3-y+z);
f2=@(x,y,z) (1/7)*(19-2*x-z);
f3=@(x,y,z) (1/12)*(31-x+3*y);
x=0;
y=0;
z=0;
for i=1:5
f1(x,y,z);
f2(x,y,z);
f3(x,y,z);
x= f1(x,y,z);
y= f2(x,y,z);
z= f3(x,y,z);
end
disp(x)
disp(y)
disp(z)
o o
6. A long column with thermal conductivity k = 1 W/m K is maintained at 500 K on three surfaces while the remaining surface is exposed to a convective environment with h =
10 W/m K and fluid temperature T. The cross sectional area of the column is 1 m by 1 m. Using a grid spacing x = y = 0.25 m, determine the steady-state temperature
2o
distribution in the column and the heat flow to the fluid per unit length of the column.
0
Refer Slide of Lecture 13 for Detailed explanation, run the code in matlab and Plot the temperature profile by changing the temperature on three surface to 510 k
2 Marks
Tutorial 4: Polynomials Solving
(a) Fit the data with a first-order polynomial. Make a plot of the points and the polynomial.
(b) Fit the data with a second-order polynomial. Make a plot of the points and the polynomial.
(c) Fit the data with a third-order polynomial. Make a plot of the points and the polynomial.
(d) Fit the data with a fifth-order polynomial. Make a plot of the points and the polynomial.
ANSWER
clear
clc
x=[1 2.2 3.7 6.4 9 11.5 14.2 17.8 20.5 23.2];
y=[12 9 6.6 5.5 7.2 9.2 9.6 8.5 6.5 2.2];
% Solution of (a)
p1=Polyfit(x,y,1);
plot(x,y)
title('first-order polynomial')
% Solution of (b)
P2=Polyfit(x,y,2);
plot(x,y)
title('second-order polynomial')
% Solution of (c)
P3=Polyfit(x,y,3);
plot(x,y)
title('Third-order polynomial')
% Solution of (d)
P=Polyfit(x,y,4);
plot(x,y)
title('fifth-order polynomial')
8. The temperature (in degrees Fahrenheit) was recorded every three hours for a day at a particular location. Using a 24-hour clock where midnight is
0, for example,
the data might be
Time 0 3 6 9 12 15 18 21
Temp 55.5 52.4 52.6 55.7 75.6 77.7 70.3 66.6
ANSWER
clear
clc
% Solution for a
x=[0:3:21];
y=[55.5 52.4 52.6 55.7 75.6 77.7 70.3 66.6];
p=polyfit(x,y,1);
curve=polyval(p,x);
xlabel('Time')
ylabel('Temperature')
plot(x,y, 'ro',y,curve)
title('Time Vs Temp');
% Values at 60 & 65.
polyval(p,60)
polyval(p,65)
Tutorial 5: Control Problems
9. If the transfer function is given below.Plot he Step response and Impulse response for the transfer function.
( )
2 Marks
ANSWER
% Step response
G=tf([2],[1 3 2]);
step(G)
hold on;
% Impulse response
% considering zeta = 0,0.2,0.4,0.6,…..1.8
t=0:0.2:10;
zeta=[0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8];
for n=1:10;
num=[0 0 1];
den=[1 3*zeta(n) 2];
[y(1:51,n),x,t]=step(num,den,t);
End
Plot(t,y)
grid;
title('Imuplse response');
ODE 45 Questions
10. Use ode45 to solve the initial value problem for a first order differential equation:
2 Marks
ANSWER
function f=myfun1(t,y)
f=-t*y/sqrt(2-y^2);
[tv1 f1]=ode45('myfun1',[0 5],1);
Plot(tv1,f)
11. Given dy/dx= 1+y2 , where y=0 when x=0 find y(0.2), y(0.4) and y(0.6) compare Runga Kutta 4th order with euler and modified euler method
using MATLAB 2 Marks
ANSWER
%Euler's Method
x=zeros(4,1);
y=zeros(4,1);
x(1)=0;
y(1)=1;
for i= 1:3
x(i+1)=x(i)+.2;
y(i+1)=y(i)+.2.*((y(i).^2)+1);
end
Eulers_Method_Result1=[x,y]
plot(x,y,'-*r');
hold on
% Moified Euler's Method
x=zeros(4,1);
y=zeros(4,1);
f=@(y,x)(1+y^2);
y(1)=1;
x(1)=0;
h=.2;
for i=1:3
x(i+1)=x(i)+h;
y(i+1)=y(i)+h*f(y(i),x(i));
y(i+1)=y(i)+((f(y(i),x(i))+f(y(i+1),x(i+1)))*h/2);
end
Modified_Eulers_Method_Results=[x,y]
plot(x,y,'-*b');
%Runge kutta 4th order method
x=zeros(4,1);
y=zeros(4,1);
x(1)=0;
y(1)=1;
h=.2;
f=@(x,y)y^2+1;
for i=1:3
x(i+1)=x(i)+h;
k1 = f(x(i),y(i));
k2 = f(x(i)+0.5*h,y(i)+0.5*h*k1);
k3 = f((x(i)+0.5*h),(y(i)+0.5*h*k2));
k4 = f((x(i)+h),(y(i)+k3*h));
y(i+1) = y(i) + (1/6)*(k1+2*k2+2*k3+k4)*h;
end
Runge_Kutta_4th_Order_Method_Result3=[x,y]
plot(x,y,'-*g');
xlabel('X')
ylabel('Y')
title('Comparison of RK4,Eulers and Modified Euler Methods')
Birla Institute of Technology & Science, Pilani
Work-Integrated Learning Programmes Division
Second Semester 2017-2018
Comprehensive Examination
(EC-3 REGULAR)
Q.1. a = 2; b = 3; c = 4; d = 5;
y1 = b/a*c + b^a - d;
y2 = b/a *(b -a) ^( b -a )*( b -a ); [4]
Solution:
y1 = b/a*c + b^a - d;
(a) y1= 3/2*4+ 3^2-5
Q.2. If the function f(x)=𝑥 3 − 12𝑥 + 40.25𝑥 − 36, Use the fminbnd with the interval 2 ≤ 𝑥 ≤
7. The format of fmind is x = fminbnd (function,xl,x2) , the value x is where the function
has minimum value and x1 and x2 is the interval. [4]
f=@(x) x^3-12*x+40.25*x-36
x=fminbnd(f,2,7)
{ x = 2.0000 in MATLAB}
Q.3. Write a MATLAB script that doubles the positive elements are divisible by 2 or 3 else if
the elements are negative assign them as zero. Take the same vector as a=[4,6,-9,1,3,2,1]
[4]
% Function script to double positive elements and assign zero to negative elements
function divisible=vector(a)
for i=1:7
if a(i) > 0 && a(i)%2==0 ||a(i)%3==0
divisible(i)=a(i)*a(i);
else
divisible(i)=0;
end
end
Output
vector([1,2,4,-8,4,2,3])
ans =
1 4 16 0 16 4 9
Q.4. An experiment is conducted to find the value of universal gas constant R for 1 mol of gas.
The gas follows ideal gas law PV=nRT, V in Volume in liters, P-atm, T is in 0K and n is
the number of mol of gas. Use the data below to determine R, by plotting V versus T/P and
fit to the linear equation. { Write only commands } [4]
V 0.8 0.6 0.4 0.2
T 28 39 57 69.5
P 1.7 1.98 2.5 4
n=1;
V=[0.8 0.6 0.4 0.2];
T=[28 39 57 69.5];
P=[1.7 1.98 2.5 3 4];
TdP=(T+273)./P;
p=polyfit(TdP,V,1);
R=p(1)/n
TdPplot=linspace(200,70,50)
Vplot=p(1)*TdPplot+p(2);
plot(TdP,V,'o',TdPplot,Vplot)
axis([50 220 0 1])
xlabel('T/P (K/atm)')
ylabel('V (L)’)
R=
0.006396799854418
Q.5. The resistance R in ohms of a conductor is given by R= E/I, where E is the potential in volts
and I is the current in amperes. Write a script that will (a) Call a function to prompt the
user for the potential and the current. And (b) Call a function that will print the resistance;
this will call a sub function to calculate and return the resistance. [4]
(ii)
% subfunction
n1=input(‘value of voltage’);
n2=input(‘value of current’);
fprintf(‘The resistance value is %.2f’,vector(n1,n2));
Q.6. The Wind Chill Factor (WCF) measures how cold it feels with a given air temperature (T,
in degrees Fahrenheit) and wind speed (V, in miles per hour). One formula for the WCF is
Create a table showing wind chill factors for temperatures ranging from –20 to 55 in steps
of 5, and wind speeds ranging from 0 to 55 in steps of 5. Write this to a file ‘wcftable.dat’.
[4]
%Script to print table of wind chill factors
% Print column headers
fprintf('%45s\n ', 'Wind Speeds')
for v = 0:5:55
fprintf('%7d', v)
end
fprintf('\nTemp\n')
for t = -20:5:55
fprintf('%3d', t)
for v = 0:5:55
fprintf('%7.1f',wcf(t,v));
end
fprintf('\n')
end
function WCF=wcf(t,v)
WCF=35.7+0.6*t-35.7*v.^0.16+0.43*v.^0.16;
end
Q.7. In product design, it is useful to gauge how important different features of the product would
be to potential customers. One method of determining which features are most important is
a survey in which people are asked for different features: “Is this feature important to you?”
The number of potential customers who responded Yes is then tallied. For example, a
company conducted such a survey for 10 different features; 200 people took part in the
survey. The data was collected into a file that might look like this:
1 2 3 4 5 6 7 8 9 10
30 83 167 21 45 56 55 129 69 55
A Pareto chart is a bar chart in which the bars are arranged in decreasing values. The bars
on the left in a Pareto chart indicate which are the most important features. Create a data
file, and then a subplot to display the data with a bar chart organized by question on the
left and a Pareto chart on the right [4]
>> questions=pareto(:,1)
>> responses=pareto(2,:)
>> bar(res)
Q.8. Find out the specific speed of a turbine of 10 MW capacity working under a head of 500m
and having the normal working speed of 300 RPM.
Write a function in MATLAB where if you enter the above three parameters the specific
speed should calculate. Suppose the 10 MW is replaced by 100 MW and so on the program
should be generalized for all inputs [4]
function specific_speed=turbinespeed(h,P,N)
specificspeed=N*sqrt(P)/h^(5/4);
end
h=input(‘Head’);
P=input(‘Power input’);
N=input(‘Specific Speed’);
fprintf(‘the specific speed of turbine is %f’,turbinespeed(h,P,N);
Q.9. Create a mesh, surface plot and contour plot of the function z=𝑒 𝑥+𝑖𝑦 for the interval -1≤
𝑥 ≤ 1 𝑎𝑛𝑑 − 2𝝅 ≤ 𝑦 ≤ 2𝝅. In each case plot the real part of z versus x and y [4]
close all
clear all
clc
[X,Y] = meshgrid(x,y);
% compute function
Z = real(exp(X + sqrt(-1)*Y));
Clf
surf(X,Y,Z);
shading interp
view(3)
xlabel(’x’);
ylabel(’y’);
label(’z’);
figure(2)
mesh(X,Y,Z+4,Z);
contour(X,Y,Z)
Q.10. A long column with thermal conductivity k = 1.2 W/moK is maintained at 500oK on three
surfaces while the remaining surface is exposed to a convective environment with h = 10
W/m2oK and fluid temperature T. The cross sectional area of the column is 1 m by 1 m.
Using a grid spacing x = y = 0.25 m, determine the steady-state temperature distribution
in the column and the heat flow to the fluid per unit length of the column.
Understand the Process by energy balance and Determine the Node temperatures using
MATLAB code [4]
The equation is divided by k(xy1) and simplified to
***********
Birla Institute of Technology & Science, Pilani
Work-Integrated Learning Programmes Division
Second Semester 2018-2019
Comprehensive Examination
(EC-3 REGULAR)
Q.1. Evaluate the values of i and m through hand calculation for the following script [4]
v = [3 1 5];
i = 1;
for j = v
i = i + 1;
if i = = 3
i = i + 2;
m = i + j;
end
end
Solution:
Initially v is assign the value [3 1 5] that is 1 row and 3 columns
i=1;
j will be assigned v vector
i=2
condition fails goes to loop
i=3 now
i=i+2 will make value of i=5
j will get 1 value as initially i=1
therefore m= then value of m will
m=5+1=6
Q.2. Create a multiplication table from 1 to 10 in MATLAB and write it to a spreadsheet. [4]
a = 1:10;
filename='multiplication.xlsx';
A = a .* a'
xlswrite(filename,A)
Please also check if somebody does alternate steps , give partial marks
Q.3. For the following data set x=[1 2 3 4 5 6 7 8] and y=[ 25 26 78 11 13 15 18 21] Create the
bar char, pie chart, stem chart. All the charts should appear in one figure window only. Use
subplot command [4]
x=[1 2 3 4 5 6 7 8]
y=[ 25 26 78 11 13 15 18 21]
x=[1 2 3 4 5 6 7 8]
y=[ 25 26 78 11 13 15 18 21]
subplot(2,2,1)
bar(x,y)
subplot(2,2,2)-/
pie(x,y)
subplot(2,2,3)
stem(x,y)
Q.4 The following program (writer.m) invites you to enter any number of names and marks from the
command line, and writes them as binary data to a file. To terminate the process just hit Enter for
the next name. Explain what task will each line do and overall output [4]
namelen = 10; % 10 bytes for name
fid = fopen(’marks.bin’, ’w’); % open for write only
str = ’?’; % not empty to start
while ~isempty(str)
str = input( ’Enter name: ’, ’s’ );
if ˜isempty(str)
if length(str) > namelen
name = str(1:namelen); %only first ten chars allowed
else
name = str;
name(length(str)+1:namelen) = ’ ’; %pad with blanks if.. too short
end
fwrite(fid, name);
mark = input( ’Enter mark: ’ );
fwrite(fid, mark, ’float’); % 4 bytes
for mark
end
end
fclose(fid);
Solution
Q.5 Write a MATLAB script that doubles the positive elements are divisible by 2 or 3 else if the
elements are negative assign them as zero. Take the same vector as a=[4,6,-9,1,3,2,1]
[4]
function divisible=vector(a)
for i=1:7
if a(i) > 0 && a(i)%2==0 ||a(i)%3==0
divisible(i)=a(i)*a(i);
else
divisible(i)=0;
end
end
(c) ans=1015
Q.7 The coefficient of variation is useful when comparing data sets that have quite different
means. The formula is CV = (standard deviation/mean) * 100%. A history course has two
different sections; their final exam scores are stored in two separate rows in a file. For
example
Create this data file, read the data into vectors, and then use the CV to compare the two
sections of this course. [4]
Q.8 Make a 3 D surface plot of the function z=0.5x2+0.5y2 in the domain −2 ≤ 𝑥 ≤ 2 𝑎𝑛𝑑
−2 ≤ 𝑦 ≤ 2 [4]
clear;
clc;
x=-2:0.1:2;
y=-2:0.1:2
z=0.5.*x^2+
0.5.*y^2;
plot3(x,y,z
)
title('Plot 3 Dimensional
figure');
xlabel('x axis');
ylabel('y axis');
zlabel('z axis');
grid on
Q.9 If there are two strings str1= ‘Non’ str2= ‘specific’. What will be the result of the following
command? [4]
Solution:
(i) a = 'Nonspecific
(ii) a=
2×8 char array 'Non '
'specific'
(iii) logical=0
(iv) logical=0
Q.10 Create a function in MATLAB to calculate the ideal air standard cycle efficiency based on the
Otto cycle for a gas engine with a cylinder bore of 40 mm, a stroke of 70 mm and a clearance
volume of 19.3 cm3.Take the inputs as Cylinder bore, clearance volume and get the outputs of
compression ratio and efficiency. The calculations are done as follows in the snapshot
𝜋
* Swept Volume= 4 × 402 × 70 *Total Cyl vol=Swept vol+clearance vol
* compression ratio is total cyl vol/clearance vol
* efficiency = 1- (1/comp ration ^0.4) *100
function Efficiency=ottocycle(d,S,VC)
% d is bore diameter ENTER IN MM
% S is stroke ENTER IN MM
%VC is clearance volume ENTER IN MM3
VS=(pi*d^2*S/4)*(1/1000) ;% conversion to cm
disp(VS);
r=(VC+VS)/VC; % no difference in unit as units are same
disp(r);
Efficiency=(1- (1/(r^0.4)))*100;
Best of Luck
***********
Birla Institute of Technology & Science, Pilani
Work-Integrated Learning Programmes Division
Second Semester 2017-2018
Mid-Semester Test (EC-2 Make-up)
randi([10,30],2,4)
mat =
2 3 4
3 4 5
(c) Using the linspace function, create the following vectors: –3 –6 –9 –12 –15
linspace(-3,-15,5)
(d) Create a 4 × 2 matrix of all zeros and store it in a variable. Then, replace the second
row in the matrix with a 3 and a 6.
a=zeros(4,2)
a(2,:)=[3,6]
z=[1,2;3,4]
eig(z)
Q.2. Evaluate the value of c if c=a.\b , a and b are matrices shown below [2]
3 1 1 3
a b
1 2 2 2
c=
-0.3333 3.0000
-2.0000 1.000
Solution:
Solution:
It will print 0 to 100 in the gap of 10 such as 0,10,20,20,40,50,60,70,80,90,100
kx 2
Q.4. The potential energy stored in a spring is where k is spring constant and x is
2
compression in the spring. The force required to compress the spring is kx. The following
table gives the data for five springs
Spring No 1 2 3 4 5
Force (N) 11 7 8 10 9
Spring Constant k (N/m) 1000 600 900 1300 700
Use MATLAB to find (i) compression x in each spring and (ii) Potential energy stored in
each spring
Solution:
>> % force f
>>f=[11, 7, 8, 10, 9]
>>k=[1000, 600, 900,1300,700]
>>x=f./k;
>>pe=k.*x.^2/2;
Q.5. Define the vector v = [2 3 4 5 6]. Then use the vector in a mathematical expression to create
the following vectors: {use single command for each expression} [4]
(a) a = [4 6 8 10 12 ]
(b) b = [8 27 64 125 216 ]
(c) c = [22 33 44 55 66 ]
(d) d = [1 1.5 2 2.5 3]
Solution:
a= v.*2;
b=v.^3;
c=v.^v;
d=a.^0.25
Q.6. Clouds are generally classified as high, middle, or low level. The height of the cloud is the
determining factor, but the ranges vary depending on the temperature. For example, in
tropical regions the classifications may be based on the following height ranges (given in
feet):
low 0–6500
middle 6500–20000
high > 20000
Write a script that will prompt the user for the height of the cloud in feet, and print the
classification. [4]
Script
% Cloud Classification
x=input('Enter the height of the cloud in feet')
if (x>=0 & x<6500)
disp('Low cloud')
elseif (x>=6500 & x<20000)
disp('Medium cloud')
elseif (x>2000)
disp('high cloud')
end
Solution
function average=overall_avg(x)
n=length(x);
sum=0;
for i=1:n
sum=sum+i;
average=sum/n;
end
>> overall_avg([1,2,3,4,5,6,7,8,9,10])
ans =
5.5000
********
1. Evaluate the output of the following MATLAB expressions, if a is the input vector containing the
following elements a=[1,2,3;4,5,6]
a. Convert the Vector into a matrix of 2 rows and 3 columns using reshape
b. Multiply all elements of second row and second column by two
c. Add the third row which contains average of all the columns
d. Add the fourth column containing average of all rows
e. Find the min value for each row and each column
2. The demand for water during a fire is often most important factor in the design of distribution
storage tanks and pumps. For communities with population less than 1,00,000 the demaond Q in
gallons/min can be calculated by
3. Using commands in MATLAB to plot a 3-D figure of the trajectory of a particle defined by the
following set of equations for x,y, and z.Use commands for proper labelling and title
x=t
y=t*cos(t)
z= e 0.2t
4. Consider the following steam table and determine the values using polyfit, polyval and interp1
commands using MATLAB
T, 0.01 5 10 15 20 25 30 35 40 45 50 55
deg C
P, bar 0.0061 0.0087 0.0123 0.0170 0.0234 0.0317 0.0425 0.0563 0.0738 0.0959 0.1.235 0.1576
5. The operations manager of a plant that manufactures tires wants to compare the actual inner
diameters of two grades of tires, each of which is expected to be 575 millimeters. A sample of five
tires of each grade was selected, and the results representing the inner diameters of the tires,
ranked from smallest to largest, are as follows:
Create a data file tire.xls in Excel and calculate the mean, median and std. dev in MATLAB and
export it to excel or write the computed values to excel
6. Construct an equivalent statement using single if statement in MATLAB for the following block
(a) If x<y
If z<10
W=x*y*z
(b) Accepts marks of the students as p and if p is greater than 50 print pass else print fail
3x1 7x 2 13x3 76
x 1 5x 2 3x 3 28
12x1 3x 2 - 5x 3 1
find the solution using Gauss-Seidal method. Use x1 , x2 , x3 1 0 1 as the initial guess.
𝑑𝑥
8. Consider the example 𝑑𝑡 = 3𝑒 −𝑡 with initial condition x(0)=0, Solve the following equation using
ODE45 in MATLAB
9. Create a function in MATLAB to calculate the ideal air standard cycle efficiency based on the Otto
cycle for a gas engine with a cylinder bore of 50 mm, a stroke of 75 mm and a clearance volume
of 21.3 cm3.Take the inputs as Cylinder bore, clearance volume and get the outputs of
compression ratio and efficiency. The calculations are done as follows in the snapshot
10. Explain the significance of MATLAB in your organization with specific examples, can you think of
a problem { Process control, optimization anything} in your department and try to solve in
MATLAB. Present your case for solving any one problem with stepwise methodology
TA ZC164 EC-3R SECOND SEM 2017-2018-Solutions.docx
TA ZC164 EC-3M SECOND SEM 2016-2017_revised
SOLUTIONS.docx TA ZC164 EC-3 M I SEM 2017-2018.docx TA ZC164
EC-3 I 2016-2017.docx
TA ZC164 EC-2M SECOND SEM 2017-2018 solutions.docx
TA ZC164 EC-2M I 2017-2018-Corrected.docx
TA ZC164 EC-2M FIRSTSEM 2017-2018-CorrecteD
SOLUTIONS.docx TA ZC 164 EC-3 17-18-Makeup.docx TA ZC 164
EC-3 17-18 Solutions.docx
POWTP ZC164 EC-3R FIRSTSEM 2017-2018.docx
POW TP 164 MAKE UP PAPER.docx
CUMMINS-MID SEM-SOLUTIONS.docx
CUMMINS-COMPRE.docx
CUMMINS-COMPRE Solutions-Final.docx
CUMMINS-COMPRE SOLUTIONS.docx
TA ZC164 Mid Sem -first Semester 2018-19.docx
TA ZC164 EC-II 2017-2018-Solutions.docx
Birla Institute of Technology & Science, Pilani
Work-Integrated Learning Programmes Division
Second Semester 2017-2018
Comprehensive Examination
(EC-3 REGULAR)
Q.1. a = 2; b = 3; c = 4; d = 5;
y1 = b/a*c + b^a - d;
y2 = b/a *(b -a) ^( b -a )*( b -a ); [4]
Solution:
y1 = b/a*c + b^a - d;
(a) y1= 3/2*4+ 3^2-5
f=@(x) x^3-12*x+40.25*x-36
x=fminbnd(f,2,7)
{ x = 2.0000 in MATLAB}
Q.3. Write a MATLAB script that doubles the positive elements are divisible by 2 or 3 else if
the elements are negative assign them as zero. Take the same vector as a=[4,6,-9,1,3,2,1]
[4]
% Function script to double positive elements and assign zero to negative elements
function divisible=vector(a)
for i=1:7
if a(i) > 0 && a(i)%2==0 ||a(i)%3==0
divisible(i)=a(i)*a(i);
else
divisible(i)=0;
end
end
Output
vector([1,2,4,-8,4,2,3])
ans =
1 4 16 0 16 4 9
Q.4. An experiment is conducted to find the value of universal gas constant R for 1 mol of gas. The
gas follows ideal gas law PV=nRT, V in Volume in liters, P-atm, T is in 0K and n is the
number of mol of gas. Use the data below to determine R, by plotting V versus T/P and
fit to the linear equation. { Write only commands } [4]
V 0.8 0.6 0.4 0.2
T 28 39 57 69.5
P 1.7 1.98 2.5 4
n=1;
V=[0.8 0.6 0.4 0.2];
T=[28 39 57 69.5];
P=[1.7 1.98 2.5 3 4];
TdP=(T+273)./P;
p=polyfit(TdP,V,1);
R=p(1)/n
TdPplot=linspace(200,70,50)
Vplot=p(1)*TdPplot+p(2);
plot(TdP,V,'o',TdPplot,Vplot)
axis([50 220 0 1])
xlabel('T/P (K/atm)')
ylabel('V (L)’)
R=
0.006396799854418
Q.5. The resistance R in ohms of a conductor is given by R= E/I, where E is the potential in volts
and I is the current in amperes. Write a script that will (a) Call a function to prompt the user
for the potential and the current. And (b) Call a function that will print the resistance;
this will call a sub function to calculate and return the resistance. [4]
(ii)
% subfunction
n1=input(‘value of voltage’);
n2=input(‘value of current’);
fprintf(‘The resistance value is %.2f’,vector(n1,n2));
Q.6. The Wind Chill Factor (WCF) measures how cold it feels with a given air temperature (T,
in degrees Fahrenheit) and wind speed (V, in miles per hour). One formula for the WCF is
WCF = 35.7 + 0.6 − 35.7 ( 0.16) + 0.43 ( 0.16)
Create a table showing wind chill factors for temperatures ranging from –20 to 55 in steps of
5, and wind speeds ranging from 0 to 55 in steps of 5. Write this to a file ‘wcftable.dat’.
[4]
%Script to print table of wind chill
factors % Print column headers
fprintf('%45s\n ', 'Wind Speeds')
for v = 0:5:55
fprintf('%7d', v)
end
fprintf('\nTemp\n' )
for t = -20:5:55
fprintf('%3d', t)
for v = 0:5:55
fprintf('%7.1f',wcf(t,v));
end
fprintf('\n')
end
Q.7. In product design, it is useful to gauge how important different features of the product
would be to potential customers. One method of determining which features are most
important is a survey in which people are asked for different features: “Is this feature
important to you?” The number of potential customers who responded Yes is then tallied.
For example, a company conducted such a survey for 10 different features; 200 people
took part in the survey. The data was collected into a file that might look like this:
1 2 3 4 5 6 7 8 9 10
30 83 167 21 45 56 55 129 69 55
A Pareto chart is a bar chart in which the bars are arranged in decreasing values. The bars on
the left in a Pareto chart indicate which are the most important features. Create a data file,
and then a subplot to display the data with a bar chart organized by question on the
left and a Pareto chart on the right [4]
Create a data file in command window
>> questions=pareto(:,1)
>> responses=pareto(2,:)
>> bar(res)
Q.8. Find out the specific speed of a turbine of 10 MW capacity working under a head of 500m
and having the normal working speed of 300 RPM.
Write a function in MATLAB where if you enter the above three parameters the specific
speed should calculate. Suppose the 10 MW is replaced by 100 MW and so on the program
should be generalized for all inputs [4]
function specific_speed=turbinespeed(h,P,N)
specificspeed=N*sqrt(P)/h^(5/4);
end
h=input(‘Head’);
P=input(‘Power input’);
N=input(‘Specific Speed’);
fprintf(‘the specific speed of turbine is %f’,turbinespeed(h,P,N);
Q.9. Create a mesh, surface plot and contour plot of the function z= + for the interval -1≤
≤ 1− 2 ≤ ≤ 2 . In each case plot the real part of z versus x and y [4]
close all
clear all
clc
[X,Y] = meshgrid(x,y);
% compute function
Z = real(exp(X + sqrt(-1)*Y));
Clf
surf(X,Y,Z);
shading interp
view(3)
xlabel(’x’);
ylabel(’y’);
label(’z’);
figure(2)
mesh(X,Y,Z+4,Z);
contour(X,Y,Z)
Q.10. A long column with thermal conductivity k = 1.2 W/moK is maintained at 500oK on three
surfaces while the remaining surface is exposed to a convective environment with h = 10
W/m2oK and fluid temperature T. The cross sectional area of the column is 1 m by 1 m.
Using a grid spacing x = y = 0.25 m, determine the steady-state temperature distribution
in the column and the heat flow to the fluid per unit length of the column.
Understand the Process by energy balance and Determine the Node temperatures using
MATLAB code [4]
The equation is divided by k(xy1) and simplified to
***********
Birla Institute of Technology & Science, Pilani
Work-Integrated Learning Programmes Division
Second Semester 2016-2017
Comprehensive Examination
(EC-3 Makeup)
syms x
y=x^2+6*x+5
a. int(y,x) b. int(x,y)
c. integrate(y,x) d. trapz(x,y)
Solution:
a. int(y,x)
ii. Which MATLAB command generates 50 uniform random numbers between -2 and
+2?
a. 10*rand(50)-2 c. 4*randn(50,1)-2
b. 2*rand(50,1)-2 d. 2*randn(50)-2
Solution:
b. 2*rand(50,1)-2
iii. Write the MATLAB commands to find a determinant for a 3*3 matrix
Solution:
>> a=[1,2,3;4,5,6;7,8,9]
>> det(a)
Solution:
>> x=[1,2,3]
>> y=[2,4,6]
>> z=cov(x,y)
v. What sign will be prefix for a function if you want to find a differential equation or a
integral for any function
Solution
>>@
Solution
ans =
100 80 85 91 95 85
(ii) >>a=eye(3);
>>sparse(a)
ans =
(1,1) 1
It will print non zero elements
(2,2) 1 or
(3,3) 1
TA ZC164 (EC-3 Make-up) Second Semester 2016-2017 Page 2
Q.3 Examine the following (i) and (ii) for loops and determine the value of b at the end of each
loop and also the number of times each loop executes [4]
(i) (ii)
b=0; b=0;
for i:-10:10 for i=10:-2:4
b=b+1; for j=2:2:i
end if j==6
break
end
b=b+j;
end
End
Solution
Q.4 Write a function called geomser that will receive values of r and n, and will calculate and
return the sum of the geometric series: 1 + r + r2 + r3 + r4 + ... + rn
The following examples of calls to this function illustrate what the result should be:
>> geomser(1,5)
ans = 6
>> disp(geomser(2,4))
31 [4]
Solution
function s=geomser(r,n)
v = [1,r*ones(1,n)];
p = cumprod(v);
s = sum(p);
end
Q.5 Create a mesh, surface plot and contour plot of the function
z= + for the interval -1≤ ≤ 1− 2 ≤ ≤ 2 . In each case plot the real part of
% Mesh Plot
close all
clear all
clc
[X,Y] = meshgrid(x,y);
% compute function
Z = real(exp(X + sqrt(-
1)*Y)); Clf
surf(X,Y,Z);
shading interp
view(3)
xlabel(’x’);
ylabel(’y’);
label(’z’);
figure(2)
mesh(X,Y,Z+4,Z);
contour(X,Y,Z)
Q.6 The open loop transfer function G(s)H(s) of a control system is [4]
( )( )=
( + 0.5)( 2 + 0.5 + 8)
Plot the root loci for the system using MATLAB
Solution
% Enter coefficients of
Numerator Num=[1];
Den=[1,1,8.25,4,0]
Rootlocus(num,den)
Q.7 For a project, some biomedical engineering students are designing a device that will monitor a
person’s heart rate while on a treadmill. The device will let the subject know when the target
heart rate has been reached. A simple calculation of the target heart rate (THR) for a
moderately active person is THR=(220−A)*0.6 where A is the person’s age. Write a
function that will calculate and return the THR [4]
Solution
Q.8 Using this polynomial, predict the accumulation over the range of 20 - 30 hours. Finally,
calculate the time derivative of the accumulation over the period 0-10 hours. [4]
Mass of A accumulated as a function of time:
Only write commands and write what we can get as far as analysis
Solution:
>> mass=[9,55,141,267,345,531];
>> time=[1,3,5,7,8,10];
>> coeff = polyfit(time,mass,2)
/* coeff =
5.0000 3.0000 1.0000
Q.9 Consider the system of reactions in a constant volume, constant temperature batch reactor.
A —- > D reaction 1
A + A —— > U reaction 2
where D is a desired product, U is undesired product and where k1 and k2 are the rate
constants for reactions 1 and 2. Let k1, k2 be given parameters, and the initial concentration
of A (ca0) be a design variable. The independent variable is time (tfin), and the dependent
variables are the concentration of the species, ca, cd, and cu. Note that in most design
situations k1 and k2 might be design parameters, adjusted via the temperature.
By writing the mass balance equations over the batch reactor, the system of differential
equations is the following: they are not linearly independent.
d(ca)/dt = -k1(ca) - k2(ca)2
d(cd)/dt = k1 (ca)
d(cu)/dt = k2 (ca)2
Solving this problem in Matlab involves two parts. First, write a function file that describes
the set of ODEs in terms of a single, combined matrix variable (the dependent variable).
Plot the concentration variables with respect to time
This script that might include other things like the initial conditions and other given
parameters. (The solution to a single ODE i s analogous, but the dependent variable is not a
matrix). [3 Marks- Algorithms 3 Marks- Code 3 Marks- Functions]
Solution
function dC_dt = exampleode(t,C)
global k1 k2 % variables that we wish to share with the main script
dC_dt(1) = -k1*C(1) -
k2*C(1)*C(1); dC_dt(2) = k1*C(1);
dC_dt(3) = k2*C(1)*C(1);
For any user specified value of x where x is a number < 1.0 . Use an if structure to
verify the value passed to the program is legal. If the value of x is legal, calculate
y(x), if not write suitable error message and quit.
Q.3. Create a matrix variable, mymat, which stores the following [5]
7 5 3
2 7
(i) 5 5 (iii) 8 5 2
8 3 3 5 7
(ii) 2 5 (iv) 2 5 8 2 5 8
7 8 7 5 3 7 5 3
5 3
Q.4. The number of bacteria Ns measured at different times t is given in the following table.
Determine an exponential function in the form [5]
NB= N e αt that best fits the data. Use the equation to estimate the number of bacteria
after 4.5 hr. Make a plot of the points and the equation.
t (hr) 1 2 3 4 5 6
NB 2000 4500 7500 15000 31000 64000
Q.5 A production facility is producing some nails that are supposed to have a diameter of
0.15 inch. At five different times, 10 sample nails were measured; their diameters were
stored in a file that has five lines and 10 diameters on each. First, create a data file to
simulate this data. Then, write a script to print the mean and standard deviation for each
of the five sets of sample nails. [5]
TA ZC164 (EC-3 Make-up) First Semester 2017-2018 Page 2
where the initial values are y1(0) = 1; y2(0) = y3(0) = 0. This equation can be
regarded as stiff equation. Solve the problem with ode45.
Q.7 The following list gives the measured gas mileage in miles per gallon for 22 cars of the
same model. Plot the absolute frequency histogram and the relative frequency
histogram. [5]
23 25 26 25 27 25 24 22 23 25 26
26 24 24 22 25 26 24 24 24 27 23
Q.8. Tables of materials properties list density, in units of kg/m3, when the international
system of units (SI) is used and list specific weight, in units of lb/in3, when the U.S.
customary system of units are used. [5]
Write a user-defined MATLAB function that converts density to specific weight. For
the function name and arguments, use [sw] = DenToSw (den).
The input argument den is the density of a material in kg/m3, and the output argument
sw is the specific weight in lb/in3. Use the function in the Command Window to:
(a) Determine the specific weight of steel whose density is 7860 kg/m3
(b) Determine the specific weight of titanium whose density is 4730 kg/m3
*********
Birla Institute of Technology & Science, Pilani
Work-Integrated Learning Programmes Division
Second Semester 2016-2017
Comprehensive Examination
(EC-3 Makeup)
syms x
y=x^2+6*x+5
a. int(y,x) b. int(x,y)
c. integrate(y,x) d. trapz(x,y)
ii. Which MATLAB command generates 50 uniform random numbers between -2 and
+2?
a. 10*rand(50)-2 c. 4*randn(50,1)-2
b. 2*rand(50,1)-2 d. 2*randn(50)-2
iii. Write the MATLAB commands to find a determinant for a 3*3 matrix
iv Which MATLAB command to find the covariance of x and y in MATLAB?
v. What sign will be prefix for a function if you want to find a differential equation or a
integral for any function
(ii) >>a=eye(3);
>>sparse(a)
TA ZC164 (EC-3 Make-up) Second Semester 2016-2017 Page 2
Q.3 Examine the following (i) and (ii) for loops and determine the value of b at the end of each
loop and also the number of times each loop executes [4]
(i) (ii)
b=0 b=0
for i:-10:10 for i:10:-2:4
b=b+1 for j=2:2:i
end if j==6
break
end
b=b+j
end
end
Q.4 Write a function called geomser that will receive values of r and n, and will calculate and
return the sum of the geometric series: 1 + r + r2 + r3 + r4 + ... + rn
The following examples of calls to this function illustrate what the result should be:
>> geomser(1,5)
ans = 6
>> disp(geomser(2,4))
31 [4]
Q.5 Create a mesh, surface plot and contour plot of the function
z= + for the interval -1≤ ≤ 1− 2 ≤ ≤ 2 . In each case plot the real part
Q.6 The open loop transfer function G(s)H(s) of a control system is [4]
( )( )=
( + 0.5)( 2 + 0.5 + 8)
Plot the root loci for the system using MATLAB
Q.7 For a project, some biomedical engineering students are designing a device that will
monitor a person’s heart rate while on a treadmill. The device will let the subject know
when the target heart rate has been reached. A simple calculation of the target heart rate
(THR) for a moderately active person is THR=(220−A)*0.6 where A is the person’s age.
Write a function that will calculate and return the THR [4]
TA ZC164 (EC-3 Make-up) Second Semester 2016-2017 Page 3
Q.8Using this polynomial, predict the accumulation over the range of 20 - 30 hours. Finally,
calculate the time derivative of the accumulation over the period 0-10 hours. [4]
Mass of A accumulated as a function of time:
Only write commands and write what we can get as far as analysis
Q.9 Consider the system of reactions in a constant volume, constant temperature batch reactor.
A —- > D reaction 1
A + A —— > U reaction 2
where D is a desired product, U is undesired product and where k1 and k2 are the rate
constants for reactions 1 and 2. Let k1, k2 be given parameters, and the initial
concentration of A (ca0) be a design variable. The independent variable is time (tfin), and
the dependent variables are the concentration of the species, ca, cd, and cu. Note that in
most design situations k1 and k2 might be design parameters, adjusted via the
temperature.
By writing the mass balance equations over the batch reactor, the system of differential
equations is the following: they are not linearly independent.
d(ca)/dt = -k1(ca) - k2(ca)2
d(cd)/dt = k1 (ca)
d(cu)/dt = k2 (ca)2
Solving this problem in Matlab involves two parts. First, write a function file that
describes the set of ODEs in terms of a single, combined matrix variable (the dependent
variable). Plot the concentration variables with respect to time
This script that might include other things like the initial conditions and other given
parameters. (The solution to a single ODE i s analogous, but the dependent variable is not
a matrix). [3 Marks- Algorithms 3 Marks- Code 3 Marks- Functions]
*********
Birla Institute of Technology & Science, Pilani
Work-Integrated Learning Programmes Division
Second Semester 2017-2018
Mid-Semester Test (EC-2 Make-up)
Solution:
A=randi([10,30],2,4)
Solution:
mat =
2 3 4
3 4 5
(c) Using the linspace function, create the following vectors: –3 –6 –9 –12 –15
Solution:
linspace(-3,-15,5)
(d) Create a 4 × 2 matrix of all zeros and store it in a variable. Then, replace the second
row in the matrix with a 3 and a 6.
Solution:
z=zeros(4,2)
z(2,:)=[6 3]
Solution:
Z=[1,2;3,4]
a=eig(Z)
1 2 2
2
C= -1/3 3
-2 1
solution:
Solution:
0 10 20 30 40 50 60 70 80 90 100
kx 2
Q.4. The potential energy stored in a spring is where k is spring constant and x is
2
compression in the spring. The force required to compress the spring is kx. The following
table gives the data for five springs
Spring No 1 2 3 4 5
Force (N) 11 7 8 10 9
Spring Constant k (N/m) 1000 600 900 1300 700
Use MATLAB to find (i) compression x in each spring and (ii) Potential energy stored in
each spring [4]
>> F=[11,7,8,10,9];
>> k=[1000,600,900,1300,700];
>> x=F./k;
>> e=0.5*k.*x.^2;
Q.5. Define the vector v = [2 3 4 5 6]. Then use the vector in a mathematical expression to create
the following vectors: {use single command for each expression} [4]
(a) a = [4 6 8 10 12 ]
(b) b = [8 27 64 125 216 ]
(c) c = [22 33 44 55 66 ]
(d) d = [1 1.5 2 2.5 3]
Solution
a=v.^2
b=v.^3
c=v.^v
d=v.*(1/2)
Q.6. Clouds are generally classified as high, middle, or low level. The height of the cloud is the
determining factor, but the ranges vary depending on the temperature. For example, in
tropical regions the classifications may be based on the following height ranges (given in
feet):
low 0–6500
middle 6500–20000
high > 20000
Write a script that will prompt the user for the height of the cloud in feet, and print the
classification. [4]
Solution:
Q.7. Write a function that will receive a matrix as an input argument, and will calculate and
return the overall average of all numbers in the matrix. Use loops, not built-in functions, to
calculate the average [4]
********
5 3 −3
A=[−2 2 3]
2 5 7
Q.2. Write the commands to solve the following and obtain Laplace transform respective for the
following equations
(a) t2e-t (b) 3 e -2t sin 4t [2]
Q.4. Solve the following system of three linear equations using MATLAB [2]
3x+ 2y+5z=7.5
-4.5x+2y+ 3z=5.5
-5x+ y-2.5z=4.5
Q.5. Examine the following for loops and determine the value of ires at the end of each of the
loops, and also the number of times each loop executes [2]
ires=0;
for index1=10:-2:4
for index2=2:2:index1
if index2==6
break
end
ires=ires+index2
end
end
TA ZC164 (EC-2 Make-up) First Semester 2017-2018 Page 2
Q.6. Examine the following for loop and determine the value of b at the end of each of the loops, and
also the number of times each loop executes [2]
b=0;
for i:-10:10
b=b+1;
end
Q.7. Write a function sumsteps2 that calculates and returns the sum of 1 to n in steps of 2, where n is an
argument passed to the function. For example, if 11 is passed, it will return 1 + 3 + 5 + 7 + 9 + 11.
Do this using a for loop. Calling the function will look like this:
Q.8. The steady-state heat conduction q from a cylindrical solid wall is determined by:
=2 ( 1 − 2)
1
( 2)
Where k is the thermal conductivity. 401 watts/0C/m of length L=300 cm with outer radius
r2= 5 cm and inner radius r1=3 cm. The external temperature is T2=20 0 C and the internal
temperature is T1=100 0C . Perform MATLAB command and calculate. [4]
a=[ 7 2 -3 1 0]
b=[-3 10 0 7 -2]
and c = [1 0 4 -6 5]
(a) Use the three vectors in a MATLAB command to create a 3 x 5 matrix in which the
rows are the vectors a,b and c
(b) Use the three vectors in a MATLAB command to create a 5 x3 matrix in which
the columns are the vectors a,b, and c
TA ZC164 (EC-2 Make-up) First Semester 2017-2018 Page 3
Q.10. The electrical circuit shown consists of resistors and voltage sources. Determine the current in each
resistor, using the mesh current method based on Kirchhoff’s voltage law. [6]
Kirchhoff’s voltage law states that the sum of the voltage around a closed circuit is zero. In the
mesh current method a current is first assigned for each mesh (i1, i2, i3, i4 in the figure). Then
Kirchhoff’s voltage law is applied for each mesh. This results in a system of linear equations for
the currents (in this solution gives the values of the mesh currents. The he current in a resistor that
belongs to two meshes is the sum of the currents in the corresponding meshes. It is convenient to
assume that all the currents are in the same direction (clockwise in this case). In the equation for
each mesh, the voltage source is positive if the current flows to the – pole, and the voltage of a
resistor is negative for current in the direction of the mesh current. For example the equation for
two meshes is shown. Write equations for other two meshes, arrange it in matrix form and write
the script to solve it for the current value
***********
Birla Institute of Technology & Science, Pilani
Work-Integrated Learning Programmes Division
First Semester 2017-2018
Mid-Semester Test (EC-2 Makeup)
Solutions
randi([10,30],2,4)
Q.2. Write the commands to solve the following and obtain Laplace transform respective for the
following equations
(a) t2e-t (b) 3 e -2t sin 4t [2]
(a) f=t^2*exp(-t)
laplace(f)
(b) f=3*exp(-2t)*sin(4*t)
laplace(f)
Q.3. Create a variable, pounds, to store a weight in pounds. Convert this to kilograms
and assign the result to a variable kilos. The conversion factor is 1 kilogram = 2.2 pounds.
[2]
>>pounds=input(‘weight in pound’);
>>kilos=2.2*pounds;
>>disp(kilos) 2 mar k
Q.4. Solve the following system of three linear equations using MATLAB [2]
3x+ 2y+5z=7.5
-4.5x+2y+ 3z=5.5
-5x+ y-2.5z=4.5
>> a=[3,2,5;-4.5,2,3;-5,1,-2.5]
2 mark
>> b=[7.5;5.5;4.5]
>> X=inv(a)* b
Q.5. Examine the following for loops and determine the value of ires at the end of each of the
loops, and also the number of times each loop executes [2]
ires=0;
for index1=10:-2:4
for index2=2:2:index1
if index2==6
break
end
ires=ires+index2
end
end
Q.6. Examine the following for loop and determine the value of b at the end of each of the loops, and
also the number of times each loop executes [2]
b=0;
for i:-10:10
b=b+1;
end
Q.7. Write a function sumsteps2 that calculates and returns the sum of 1 to n in steps of 2, where n is an
argument passed to the function. For example, if 11 is passed, it will return 1 + 3 + 5 + 7 + 9 + 11.
Do this using a for loop. Calling the function will look like this:
>> sumsteps2(11)
[4]
ans =
36
Q.8. The steady-state heat conduction q from a cylindrical solid wall is determined by:
=2 ( 1 − 2)
1
( 2)
Where k is the thermal conductivity. 401 watts/0C/m of length L=300 cm with outer radius
r2= 5 cm and inner radius r1=3 cm. The external temperature is T2=20 0 C and the internal
temperature is T1=100 0C . Perform MATLAB command and calculate. [4]
a=[ 7 2 -3 1 0]
b=[-3 10 0 7 -2]
and c = [1 0 4 -6 5]
(a) Use the three vectors in a MATLAB command to create a 3 x 5 matrix in which
the rows are the vectors a,b and c
(b) Use the three vectors in a MATLAB command to create a 5 x3 matrix in which
the columns are the vectors a,b, and c
Q.10. The electrical circuit shown consists of resistors and voltage sources. Determine the current in each
resistor, using the mesh current method based on Kirchhoff’s voltage law. [6]
Kirchhoff’s voltage law states that the sum of the voltage around a closed circuit is zero. In the
mesh current method a current is first assigned for each mesh (i1, i2, i3, i4 in the figure). Then
Kirchhoff’s voltage law is applied for each mesh. This results in a system of linear equations for
the currents (in this solution gives the values of the mesh currents. The he current in a resistor that
belongs to two meshes is the sum of the currents in the corresponding meshes. It is convenient to
assume that all the currents are in the same direction (clockwise in this case). In the equation for
each mesh, the voltage source is positive if the current flows to the – pole, and the voltage of a
resistor is negative for current in the direction of the mesh current. For example the equation for
two meshes is shown. Write equations for other two meshes, arrange it in matrix form and write
the script to solve it for the current value
***********
Birla Institute of Technology & Science, Pilani
Work-Integrated Learning Programmes Division
First Semester 2017-2018
Comprehensive Examination Test (EC-3 Regular)
For any user specified value of x where is a number < 1.0 . Use an if structure to
verify the value passed to the program is legal. If the value of x is legal, calculate
y(x), if not write suitable error message and quit.
7 5 3
2 7
(i) 5 5
8 3
(iii) 8 5 2
3 5 7
(ii) 2 5
7 8
5 3 (iv) 2 5 8 2 5 8
7 5 3 7 5 3
NB= N e αt that best fits the data. Use the equation to estimate the number of
bacteria after 4.5 hr. Make a plot of the points and the equation.
t (hr) 1 2 3 4 5 6
NB 2000 4500 7500 15000 31000 64000
Q.5 A production facility is producing some nails that are supposed to have a
diameter of 0.15 inch. At five different times, 10 sample nails were measured;
their diameters were stored in a file that has five lines and 10 diameters on
each. First, create a data file to simulate this data. Then, write a script to print
the mean and standard deviation for each of the five sets of sample nails.
where the initial values are y1(0) = 1; y2(0) = y3(0) = 0. This equation can
be regarded as stiff equation. Solve the problem with ode45.
Q.7 The following list gives the measured gas mileage in miles per gallon for 22
cars of the same model. Plot the absolute frequency histogram and the relative
frequency histogram.
23 25 26 25 27 25 24 22 23 25 26
26 24 24 22 25 26 24 24 24 27 23
8. Tables of materials properties list density, in units of kg/m3, when the international
system of units (SI) is used and list specific weight, in units of lb/in3, when the
U.S. customary system of units are used.
Write a user-defmed MATLAB function that converts density to specific weight. For
the function name and arguments, use [sw] = DenToSw (den).
The input argument den is the density of a material in kg/m3, and the output argument
sw is the specific weight in lb/in3. Use the function in the Command Window to:
(a) Determine the specific weight of steel whose density is 7860 kg/m3
(b) Determine the specific weight of titanium whose density is 4730 kg/m3
Birla Institute of Technology & Science, Pilani
Work-Integrated Learning Programmes Division
First Semester 2017-2018
Comprehensive Examination Test (EC-3 Regular)
Solutions
(a) 8.2
(b) 4 Round to nearest decimal or integer
(c) 729
(d) 4 Round toward positive infinity
(e) 1
Q.2 Using the zeros, ones, and eye commands create the following arrays
0 0 1 1
a) [0 0 1 1]
0 0 0 0
1 1 1 1
Solution (a)
1 1 0 0 1
b) [1 1 0 0
0]
1 1 0 0 0
1 1 0 0 0
Solution (b)
Q.3 A juice company manufactures one-gallon bottles of three types of juice blends using
orange, pineapple, and mango juice. The blends have the following compositions:
1 gallon orange blend: 3 quarts of orange juice, 0.75 quart of pineapple juice,
0.25 quart of mango juice.
1 gallon pineapple blend: 1 quart of orange juice, 2.5 quarts of pineapple
juice, 0.5 quart of mango juice. 1 gallon mango blend: 0.5 quart of orange juice, 0.5
quart of pineapple juice,3 quarts of mango juice.
How many gallons of each blend can be manufactured if 7,600 gallons of orange
juice, 4,900 gallons of pineapple juice, and 3,500 gallons mango juice are available?
Write a system of linear equations and solve in MATLAB only steps
Solution
Set up Equations
X=3*x+0.75*y+0.25*z
Y=x+2.5*y+0.5*z
Z=0.5*x+0.5*y+3*z
MATLAB
a=[3,0.75,0.25;1,2.5,0.5;0.5,0.5,3]
b=[7600;4900;3500]
c=inv(a)* b
Ans [ x= 2246 gallons orange juice, y=933 gallons pineapple, z=636 gallons mango juice]
Q.4 Viscosity, μ, is a property of gases and fluids that characterizes their resistance to
flow. For most materials viscosity is highly sensitive to temperature. Below is a table
that gives the viscosity of SAE 10W oil at different temperatures (Data from B.R.
Munson, D.F. Young, and T.H. Okiishi, Fundamentals of Fluid Mechanics, 4th ed.,
John Wiley and Sons, 2002). Determine an equation that can be fitted to data.
The straight line does not fit the point , Therefore the equation can be fitted as
ln( ) = + 2+.
2 1
0
The function can be fitted to the data using polyfit(x,y,2) second degree
polynomial, T is independent variable in 0K (C+273) and ln µ. Write the
Program that best fits the program with calculation of coefficients and display
the data points and function.
Q.5 Create a data in some other program on your computer. (% use a separate file
say data) such as excel, word and so forth. Copy the data set to the clipboard
using the windows and then use function uiimport to load the data set into
MATLAB
s=uiimport('C:\Users\BITS7\Documents\MATLAB\testexam.xlsx')
Q.7 Plot the function = − for x between 0 and 2 in steps of 0 1 . Create the following plot types (a) stem plot (b) stair plot (c) bar plot . Be sure to
include titles and axis labels on all plots
x=0:0.1:2;
y=exp(-x)*sin(x);
stem(x,y);
bar(x,y);
title(‘stem and bar Plot’);
xaxis(‘x coordinate’)
yaxis(‘function’);
Q.8 Fluid flows in pipe networks can be analyzed in a manner similar to that used
for electric resistance networks. The Figure below shows a network with three
pipes. The volume flow rates in the pipes are q1, q2, and q3 . The pressures at
the pipe ends are pa, pb and pc, . The pressures at the junction is p1. Under certain
condition, the pressure flow rate relation in a pipe has the same form as the
voltage-current relation in a resistor.Thus, for the three pipes, we have
a. Set up these equations in a matrix form Ax=b suitable for solving for the
three flow rates q1, q2, q3, and the pressure p1 given the values of pressures
pa, pb and pc and the values of resistances R1, R2, and R3. Find
expressions of A and B
Birla Institute of Technology & Science, Pilani
Work-Integrated Learning Programmes Division
First Semester 2017-2018
Comprehensive Test (EC-3 Regular)
Q.1. Calculate the efficiency of a power plant using function in MATLAB if the efficiencies of
the boiler, turbine and generator are 88, 40 and 98%, respectively.
Write the function as general so that for varying efficiency it should calculate the overall
efficiency. Formula to calculate the efficiency is
= +
The following data points are given Determine the constants m and b by curve-fitting the
equation to the data points. Make a plot of P versus t. In the plot show the data points with
markers and the curve-fitted equation with a solid line. (The curve fitting can be done by
writing the reciprocal of the equation and using a first-order polynomial.) [5]
t 1 3 4 7 8 10
P 2.1 4.6 5.4 6.1 6.4 6.6
Q.3 Create a mesh, surface plot and contour plot of the function z= + for the interval -1≤
Q.4 Solve the equation using MATLAB (only program no calculations) using Gauss
technique [5]
2 +3 + =9
+2 +3 =63 ++2 =8
Q.5 The xlswritefunction can write the contents of a cell array to a spreadsheet.A manufacturer
stores information on the weights of some parts in a cell array. Each row stores the part
identifier code followed by weights of some sample parts.To simulate this, create the
following cell array:
>>parts = {‘A22’, 4.41 4.44 4.39 4.39‘Z29’, 8.88 8.95 8.84 8.92}
y(1)= -2
Q.7 Using the zeros, ones, and eye commands create the following arrays
[5]
Q.8 The temperature dependence of vapor pressure p can be estimated by the
Antoine equation:
where ln is the natural logarithm, p is in mm Hg, T is in kelvins, and A, B, and C are material
constants. For toluene (C6H5CH3) in the temperature range
from 280 to 410 K the material constants are A= 16.0137 B = 3096.52, , and C = –53.67
Calculate the vapor pressure of toluene at 315 and 405 K in MATLAB [5]
Q.9 Write a script called prtemps that will prompt the user for a maximum Celsius value in the
range from –16 to 20; error-check to make sure it’s in that range. Then, print a table
showing degrees F and degrees C until this maximum is reached. The first value that
exceeds the maximum should not be printed. The table should start at 0 degrees F, and
increment by 5 degrees F until the max (in DEG C) is reached. Both temperatures should
be printed with a field width of 6 and one decimal place. The formula is C = 5/9* (F – 32).
For example, the execution of the script might look like this (the format should be exactly
like this): [5]
>> prtemps
F C
0.0 −17.8
5.0 −15.0
10.0 −12.2
15.0 −9.4
20.0 −6.7
25.0 −3.9
30.0 −1.1
35.0 1.7
40.0 4.4
45.0 7.2
Q.10 Write a function that will receive a name and department as separate strings and will
create and return a code consisting of the first two letters of the name and the last two
letters of the department. The code should be uppercase letters. For example,
>> namedept(‘Robert’,‘Mechanical’) [5]
ans =
ROAL
***********
Birla Institute of Technology & Science, Pilani
Work-Integrated Learning Programmes Division
First Semester 2017-2018
Comprehensive Examination
(EC-3 Makeup)
syms x
y=x^2+6*x+5
a. int(y,x) b. int(x,y)
c. integrate(y,x) d. trapz(x,y)
ii. Which MATLAB command generates 50 uniform random numbers between -2 and
+2?
a. 10*rand(50)-2 c. 4*randn(50,1)-2
b. 2*rand(50,1)-2 d. 2*randn(50)-2
iii. Write the MATLAB commands to find a determinant for a 3*3 matrix
iv Which MATLAB command to find the covariance of x and y in MATLAB?
v. What sign will be prefix for a function if you want to find a differential equation or a
integral for any function
vi Write command to create a sparse matrix of 2*3
(ii) >>a=eye(3);
>>sparse(a)
Q.3 Examine the following (i) and (ii) for loops and determine the value of b at the end of each
loop and also the number of times each loop executes [6]
(i) (ii)
b=0 b=0
for i:-10:10 for i:10:-2:4
b=b+1 for j=2:2:i
end if j==6
break
end
b=b+j
end
end
Q.4 Write a function called geomser that will receive values of r and n, and will calculate and
return the sum of the geometric series: 1 + r + r2 + r3 + r4 + ... + rn
The following examples of calls to this function illustrate what the result should be:
>> geomser(1,5)
ans = 6
>> disp(geomser(2,4))
31 [5]
Q.5 Create a mesh, surface plot and contour plot of the function
z= + for the interval -1≤ ≤ 1− 2 ≤ ≤ 2 . In each case plot the real part of
Q.6 The open loop transfer function G(s)H(s) of a control system is [5]
( )( )=
( + 0.5)( 2 + 0.5 + 8)
Plot the root loci for the system using MATLAB
Q.7 For a project, some biomedical engineering students are designing a device that will monitor a
person’s heart rate while on a treadmill. The device will let the subject know when the target
heart rate has been reached. A simple calculation of the target heart rate (THR) for a
moderately active person is THR=(220−A)*0.6 where A is the person’s age. Write a
function that will calculate and return the THR [5]
POW TP ZC164 (EC-3 Make-up) First Semester 2017-2018 Page 3
Q.8 Using this polynomial, predict the accumulation over the range of 20 - 30 hours. Finally,
calculate the time derivative of the accumulation over the period 0-10 hours. [5]
Mass of A accumulated as a function of time:
Only write commands and write what we can get as far as analysis
Q.9 Consider the system of reactions in a constant volume, constant temperature batch reactor.
A —- > D reaction 1
A + A —— > U reaction 2
where D is a desired product, U is undesired product and where k1 and k2 are the rate
constants for reactions 1 and 2. Let k1, k2 be given parameters, and the initial concentration
of A (ca0) be a design variable. The independent variable is time (tfin), and the dependent
variables are the concentration of the species, ca, cd, and cu. Note that in most design
situations k1 and k2 might be design parameters, adjusted via the temperature.
By writing the mass balance equations over the batch reactor, the system of differential
equations is the following: they are not linearly independent.
d(ca)/dt = -k1(ca) - k2(ca)2
d(cd)/dt = k1 (ca)
d(cu)/dt = k2 (ca)2
Solving this problem in Matlab involves two parts. First, write a function file that describes
the set of ODEs in terms of a single, combined matrix variable (the dependent variable).
Plot the concentration variables with respect to time
This script that might include other things like the initial conditions and other given
parameters. (The solution to a single ODE i s analogous, but the dependent variable is not a
matrix). [10]
*********
Birla Institute of Technology & Science, Pilani
Work-Integrated Learning Programmes Division
Second Semester 2017-2018
Comprehensive Test (EC-2 Regular)
1. Using the zeros, ones, and eye commands create the following arrays [3]
Solutions:
(a)
>> a=zeros(2,4)
a=
0 0 0 0
0 0 0 0
>> a(:,4:5)=ones
a=
0 0 0 1 1
0 0 0 1 1
>> a(1,1)=ones
a=
1 0 0 1 1
0 0 0 1 1
>> a(2,2)=ones
a=
1 0 0 1 1
0 1 0 1 1
(b)
>> a=zeros(4)
a=
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
>> a(:,3:4)=ones
a=
0 0 1 1
0 0 1 1
0 0 1 1
0 0 1 1
>> a(4,:)=ones
a=
0 0 1 1
0 0 1 1
0 0 1 1
1 1 1 1
>> a(3,:)=zeros
a=
0 0 1 1
0 0 1 1
0 0 0 0
1 1 1 1
(c) >> c=ones(4)
c=
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
>> c(:,3:5)=zeros
c=
1 1 0 0 0
1 1 0 0 0
1 1 0 0 0
1 1 0 0 0
>> c(1,5)=ones
c=
1 1 0 0 1
1 1 0 0 0
1 1 0 0 0
1 1 0 0 0
(b) sign(-11/5)+6
-11/5 gives -2.2 however sign will give +1 or –1ve only therefore -1+6=5
(c) fix(-13/5)+5
-13/5 gives -2.6 which truncated decimal point so -2+5=3
3. Tables of materials properties list density, in units of kg/m3, when the international
system of units (SI) is used and list specific weight, in units of lb/in3, when the U.S.
customary system of units are used.
Write a user-defined MATLAB function that converts density to specific weight. For the
function name and arguments, use [sw] = DenToSw (den).
The input argument den is the density of a material in kg/m3, and the output argument sw
is the specific weight in lb/in3. Use the function in the Command Window to:
(a) Determine the specific weight of steel whose density is 7860 kg/m3
(b) Determine the specific weight of titanium whose density is 4730 kg/m3 [4]
clear
clc
den=7860;
sw=dentosw(den);
disp('The specific weight of steel in lb/inch3
is'); disp(sw);
den=4730;
sw=dentosw(den);
disp('The specific weight of titanium in lb/inch3
is'); disp(sw);
% function file
function sw = dentosw(den)
sw=den*3.605/100000;
end
For any user specified value of x where x is a number < 1.0 . Use an if structure to verify
the value passed to the program is legal. If the value of x is legal, calculate y(x), if not
write suitable error message and quit.
P=[1,2,-3,7,-8,7]
Polyval(P,2)
1
a) 2
s (s + 4)
dy
b) dt + 3y = e-2t y(0) = 2
>> syms s
>> f=(1/s*(s^2+4));
>> ilpalace(f)
>>syms s
>>f=(2s+5)/(s+2)*(s+4);
>>ilapace(f)
7. The following functions describe the oscillations in electric circuits and the vibrations of
machines and structures. Plot these functions on the same plot. Because they are similar,
decide how best to plot and label them to avoid confusion [4]
( ) = . − . sin(3t+2)
( ) = . − . cos (5t-3)
8. Write a function called geomser that will receive values of r and n, and will calculate and
return the sum of the geometric series: 1 + r + r2 + r3 + r4 + ... + rn [4]
The following examples of calls to this function illustrate what the result should be:
>> geomser(1,5)
ans = 6
>> disp(geomser(2,4))
31
function s=geomser(r,n)
v = [1,r*ones(1,n)];
p = cumprod(v);
s = sum(p);
end
Birla Institute of Technology & Science, Pilani
Work-Integrated Learning Programmes Division
Second Semester 2017-2018
Comprehensive Test (EC-2 Regular)
1. Evaluate the output of the following MATLAB expressions, if a is the input vector containing the
following elements a=[1,2,3;4,5,6]
a. Convert the Vector into a matrix of 2 rows and 3 columns using reshape
b. Multiply all elements of second row and second column by two
c. Add the third row which contains average of all the columns
d. Add the fourth column containing average of all rows
e. Find the min value for each row and each column
2. The demand for water during a fire is often most important factor in the design of distribution
storage tanks and pumps. For communities with population less than 1,00,000 the demaond Q
in gallons/min can be calculated by
= 1020√ (1 − 0.01√ ) Where P is population in thousands. Set up vector P that starts at 10 and increments by 10 upto 200. Use
element by element computations to determine Q for each population in P
3. Using commands in MATLAB to plot a 3-D figure of the trajectory of a particle defined by the
following set of equations for x,y, and z.Use commands for proper labelling and title
x=t
y=t*cos(t)
z= e 0.2t
4. Consider the following steam table and determine the values using polyfit, polyval and interp1
commands using MATLAB
T, 0.01 5 10 15 20 25 30 35 40 45 50 55
deg C
P, bar 0.0061 0.0087 0.0123 0.0170 0.0234 0.0317 0.0425 0.0563 0.0738 0.0959 0.1.235 0.1576
5. The operations manager of a plant that manufactures tires wants to compare the actual inner
diameters of two grades of tires, each of which is expected to be 575 millimeters. A sample of
five tires of each grade was selected, and the results representing the inner diameters of the
tires, ranked from smallest to largest, are as follows:
Create a data file tire.xls in Excel and calculate the mean, median and std. dev in MATLAB and
export it to excel or write the computed values to excel
6. Construct an equivalent statement using single if statement in MATLAB for the following block
(a) If x<y
If z<10
W=x*y*z
(b) Accepts marks of the students as p and if p is greater than 50 print pass else print fail
9. Create a function in MATLAB to calculate the ideal air standard cycle efficiency based on the Otto
cycle for a gas engine with a cylinder bore of 50 mm, a stroke of 75 mm and a clearance volume
of 21.3 cm3.Take the inputs as Cylinder bore, clearance volume and get the outputs of
compression ratio and efficiency. The calculations are done as follows in the snapshot
10. Explain the significance of MATLAB in your organization with specific examples, can you think of
a problem { Process control, optimization anything} in your department and try to solve in
MATLAB. Present your case for solving any one problem with stepwise methodology
Birla Institute of Technology & Science, Pilani
Work-Integrated Learning Programmes Division
Second Semester 2017-2018
Comprehensive Test (EC-2 Regular)
1. Evaluate the output of the following MATLAB expressions, if a is the input vector containing the
following elements a=[1,2,3;4,5,6]
a. Convert the Vector into a matrix of 2 rows and 3 columns using reshape
b. Multiply all elements of second row and second column by two
c. Add the third row which contains average of all the columns
d. Add the fourth column containing average of all rows
e. Find the min value for each row and each column
Solutions:
1a) a=[1,2,3;4,5,6]
The vector is 2 rows and three colums already so no command needed
1b) a(2,:)*2 for row and a (:,2)*2 for column
1c) a(3,:)=mean(a)
= 1020√ (1 − 0.01√ ) Where P is population in thousands. Set up vector P that starts at 10 and increments by 10 upto 200. Use
element by element computations to determine Q for each population in P
Solution
clear,
clc
P=10:10:200;
Q=1020*sqrt(P).*(1-.01*sqrt(P))
3. Using commands in MATLAB to plot a 3-D figure of the trajectory of a particle defined by the
following set of equations for x,y, and z.Use commands for proper labelling and title
x=t
y=t*cos(t)
z= e 0.2t
Solution
clear;
clc;
t=0:0.1:10*pi;
x=t;
y=t.*cos(t);
z=exp(0.2*t)
;
plot3(x,y,z)
title('Plot 3 Dimensional
figure'); xlabel('x axis');
ylabel('y axis');
zlabel('z axis');
grid on
4. Consider the following steam table and determine the values using polyfit, polyval and interp1
commands using MATLAB
T, 0.01 5 10 15 20 25 30 35 40 45 50 55
deg C
P, bar 0.0061 0.0087 0.0123 0.0170 0.0234 0.0317 0.0425 0.0563 0.0738 0.0959 0.1.235 0.1576
Solution
T=[0.01,5:5:55]
P=[0.061,0.087,0.0123,0.0170,0.0234,0.0317,0.0425,0.0563,0.0738,0.0959,0.1235,0.1576]
(a) q=interp1(T,P,27)
(b) q=interp1(P,T,0.0465)
(c) q=polyfit(T,P,2) m=polyval(q,70)
(d) q=polyfit(P,T,2) m=polval(q,0.2)
(e) TK=T+273 m=polyfit(TK,P,2)
5. The operations manager of a plant that manufactures tires wants to compare the actual inner
diameters of two grades of tires, each of which is expected to be 575 millimeters. A sample of
five tires of each grade was selected, and the results representing the inner diameters of the
tires, ranked from smallest to largest, are as follows:
Create a data file tire.xls in Excel and calculate the mean, median and std. dev in MATLAB and
export it to excel or write the computed values to excel
Solution:
[s,x]=xlsread('Tire.xlsx');
s(:,6)=mean(s,2);
k=s(1:2,1:5);
s(:,7)=median(k,2);
m=s(1:2,1:5);
s(:,8)=std(m,0,2);
xlswrite('Tire.xlsx',s);
6. Construct an equivalent statement using single if statement in MATLAB for the following block
(a) If x<y
If z<10
W=x*y*z
(b) Accepts marks of the students as p and if p is greater than 50 print pass else print fail
8. Consider the example = 3 − with initial condition x(0)=0, Solve the following equation using ODE45 in MATLAB
tspan = [0
5]; x0 = 0;
[t,y] = ode45(@(t,x) 3*exp(-t), tspan,
x0); figure(1);
plot(t,y,'-o');
9. Create a function in MATLAB to calculate the ideal air standard cycle efficiency based on the Otto
cycle for a gas engine with a cylinder bore of 50 mm, a stroke of 75 mm and a clearance volume
of 21.3 cm3.Take the inputs as Cylinder bore, clearance volume and get the outputs of
compression ratio and efficiency. The calculations are done as follows in the snapshot
function Efficiency=ottocycle(d,S,VC)
% d is bore diameter ENTER IN MM
% S is stroke ENTER IN MM
%VC is clearance volume ENTER IN MM3
VS=(pi*d^2*S/4)*(1/1000) ;% conversion to
cm disp(VS);
r=(VC+VS)/VC; % no difference in unit as units are same
disp(r);
Efficiency=(1- (1/(r^0.4)))*100;
end
10. Explain the significance of MATLAB in your organization with specific examples, can you think of
a problem { Process control, optimization anything} in your department and try to solve in
MATLAB. Present your case for solving any one problem with stepwise methodology
Apart from MATLAB Significance one plant example with step wise methodology was desired
Birla Institute of Technology & Science, Pilani
Work-Integrated Learning Programmes Division
Second Semester 2017-2018
Comprehensive Test (EC-2 Regular)
1. Evaluate the output of the following MATLAB expressions, if a is the input vector containing the
following elements a=[1,2,3;4,5,6]
a. Convert the Vector into a matrix of 2 rows and 3 columns using reshape
b. Multiply all elements of second row and second column by two
c. Add the third row which contains average of all the columns
d. Add the fourth column containing average of all rows
e. Find the min value for each row and each column
2. The demand for water during a fire is often most important factor in the design of distribution
storage tanks and pumps. For communities with population less than 1,00,000 the demaond Q
in gallons/min can be calculated by
= 1020√ (1 − 0.01√ ) Where P is population in thousands. Set up vector P that starts at 10 and increments by 10 upto 200. Use
element by element computations to determine Q for each population in P
3. Using commands in MATLAB to plot a 3-D figure of the trajectory of a particle defined by the
following set of equations for x,y, and z.Use commands for proper labelling and title
x=t
y=t*cos(t)
z= e 0.2t
4. Consider the following steam table and determine the values using polyfit, polyval and interp1
commands using MATLAB
T, 0.01 5 10 15 20 25 30 35 40 45 50 55
deg C
P, bar 0.0061 0.0087 0.0123 0.0170 0.0234 0.0317 0.0425 0.0563 0.0738 0.0959 0.1.235 0.1576
5. The operations manager of a plant that manufactures tires wants to compare the actual inner
diameters of two grades of tires, each of which is expected to be 575 millimeters. A sample of
five tires of each grade was selected, and the results representing the inner diameters of the
tires, ranked from smallest to largest, are as follows:
Create a data file tire.xls in Excel and calculate the mean, median and std. dev in MATLAB and
export it to excel or write the computed values to excel
6. Construct an equivalent statement using single if statement in MATLAB for the following block
(a) If x<y
If z<10
W=x*y*z
(b) Accepts marks of the students as p and if p is greater than 50 print pass else print fail
9. Create a function in MATLAB to calculate the ideal air standard cycle efficiency based on the Otto
cycle for a gas engine with a cylinder bore of 50 mm, a stroke of 75 mm and a clearance volume
of 21.3 cm3.Take the inputs as Cylinder bore, clearance volume and get the outputs of
compression ratio and efficiency. The calculations are done as follows in the snapshot
10. Explain the significance of MATLAB in your organization with specific examples, can you think of
a problem { Process control, optimization anything} in your department and try to solve in
MATLAB. Present your case for solving any one problem with stepwise methodology
Birla Institute of Technology & Science, Pilani
Work-Integrated Learning Programmes Division
First Semester 2018-2019
Mid-Semester Test (EC-2 Regular)
i. (6/12)+4
ii. sign(-11/5)+6
iii. fix(-13/5)+5
iv. vec=9:-2:1
(c) Using the linspace function, create the following vectors: –4 –8 –12 –16 –20
(d) Evaluate the value of c if c=a.\b , a and b are matrices shown below
Q.2 Evaluate the output of the following MATLAB expressions, if a is the input vector
containing the following elements a=[1,2,3;4,5,6] [ 5 Marks]
a. Convert the Vector into a matrix of 2 rows and 3 columns using reshape
b. Multiply all elements of second row and second column by two
c. Add the third row which contains average of all the columns
d. Add the fourth column containing average of all rows
e. Find the min value for each row and each column
(i) (ii)
b=0 b=0
for i=-10:10 for i=10:-2:4
b=b+1 for j=2:2:i
end if j==6
break
end
b=b+j
end
end
Q.4 The number of combinations C n,r of taking r objects out of n objects is given by [ 5 Marks]
!
, = !( − )!
(a) Determine how many combinations are possible in a lottery game for selecting 6
numbers that are drawn out of 49 ?
(b) Using the formula, determine the probability of guessing two out of six drawn numbers
6,2 43,4
49,6
Q.5 Write the commands to find the following from the data set [ 5 Marks]
mat=[4,5,6,7,8;10,11,12,13]
********
randi([10,30],2,4)
mat =
2 3 4
3 4 5
(c) Using the linspace function, create the following vectors: –3 –6 –9 –12 –15
linspace(-3,-15,5)
(d) Create a 4 × 2 matrix of all zeros and store it in a variable. Then, replace the second
row in the matrix with a 3 and a 6.
a=zeros(4,2)
a(2,:)=[3,6]
z=[1,2;3,4]
eig(z)
Q.2. Evaluate the value of c if c=a.\b , a and b are matrices shown below [2]
c=
-0.3333 3.0000 -
2.0000 1.000
Solution:
Solution:
It will print 0 to 100 in the gap of 10 such as 0,10,20,20,40,50,60,70,80,90,100
kx 2
Q.4. The potential energy stored in a spring is where k is spring constant and x is
2
compression in the spring. The force required to compress the spring is kx. The following
table gives the data for five springs
Spring No 1 2 3 4 5
Force (N) 11 7 8 10 9
Spring Constant k (N/m) 1000 600 900 1300 700
Use MATLAB to find (i) compression x in each spring and (ii) Potential energy stored in
each spring
Solution:
Q.5. Define the vector v = [2 3 4 5 6]. Then use the vector in a mathematical expression to create
the following vectors: {use single command for each expression} [4]
(a) a = [4 6 8 10 12 ]
(b) b = [8 27 64 125 216 ]
(c) c = [22 33 44 55 66 ]
(d) d = [1 1.5 2 2.5 3]
Solution:
a= v.*2;
b=v.^3;
c=v.^v;
d=a.^0.25
Q.6. Clouds are generally classified as high, middle, or low level. The height of the cloud is the
determining factor, but the ranges vary depending on the temperature. For example, in
tropical regions the classifications may be based on the following height ranges (given in
feet):
low 0–6500
middle 6500–20000
high > 20000
Write a script that will prompt the user for the height of the cloud in feet, and print the
classification. [4]
Script
% Cloud Classification
x=input('Enter the height of the cloud in feet')
if (x>=0 & x<6500)
disp('Low cloud')
elseif (x>=6500 & x<20000)
disp('Medium cloud')
elseif (x>2000)
disp('high cloud')
end
Solution
function average=overall_avg(x)
n=length(x);
sum=0;
for i=1:n
sum=sum+i;
average=sum/n;
end
>> overall_avg([1,2,3,4,5,6,7,8,9,10]
) ans =
5.5000
********