0% found this document useful (0 votes)
31 views2 pages

Tutorial Questions On Matlab

The document contains a series of tutorial questions and answers related to MATLAB programming. It includes examples of using loops, user input, arithmetic expressions, and calculating the volume of a cylinder. Each question is accompanied by a corresponding MATLAB code solution.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views2 pages

Tutorial Questions On Matlab

The document contains a series of tutorial questions and answers related to MATLAB programming. It includes examples of using loops, user input, arithmetic expressions, and calculating the volume of a cylinder. Each question is accompanied by a corresponding MATLAB code solution.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

TUTORIAL QUESTIONS ON MATLAB

1. Write a MATLAB program using a while loop that computes the sum of positive
integers until it reaches the first sum greater than 100. The program should print the
computed sum and the number of integers summed.
Answer
total = 0;
num = 0;
while total <= 100
num = num + 1;
total = total + num;
end
disp(total)
disp(num)

2. Write a MATLAB program using a for loop that computes the sum of positive integers
from 1 to 100. The program should print the computed sum.
Answer
v = [1 : 100];
v_sum = 0;
for i = 1 : length(v)
v_sum = v_sum + v(i);
end
disp(v_sum)

3. Write a MATLAB program using a for loop that works through the string ‘Computer
Programming’ by printing the respective character in the string on a separate line.
Answer
a = 'Computer and Software Engineering';
for i = 1 : length(a)
disp(a(i))
end

4. Develop a MATLAB program that requests and accepts from a user two integers between
1 and 100. The program prints the result of the addition of the two integers when the user
provides the two integers in the correct range and prints ‘Incorrect Value’ when outside
range.
Answer
One = input("Enter a number between 1 and 100: ");
Two = input("Enter a number between 1 and 100: ");
if (One >= 1) && (One <= 100)
if (Two >= 1) && (Two <= 100)
disp(One + Two)
else
disp("Incorrect second value")
end
else
disp("Incorrect first value")
end

5. Convert the following arithmetic expressions into MATLAB expressions:


−𝑏±√𝑏 2 −4𝑎𝑐
i. 𝑥= 2𝑎
ii. 𝑦= √𝑥 2
−𝑥
𝑟
iii. 𝑥 = 𝐴(1 + )𝑛𝑡
𝑛
iv. 𝑎2 = 𝑏 2 + 𝑐 2 − 2𝑏𝑐 cos 𝐴
v. 𝑦 = 𝑎(𝑥 − ℎ)2 + 𝑘
𝑥2 𝑦2
vi. + 2=1
𝑎2 𝑏
vii. 𝑐𝑜𝑠2𝑥 = 1 − 2𝑠𝑖𝑛2 𝑥
Answer
i. x(1) = (-b + sqrt(b^2 – 4*a*c))/(2*a)
x(2) = (-b - sqrt(b^2 – 4*a*c))/(2*a)
ii. y = sqrt(x^2 - x)
iii. x = A*(1+r/n)^(n*t)
iv. a^2 = b^2 + c^2 – 2*b*c*cos(A)
v. y = a*(x-h)^2 + k
vi. (x^2/a^2) + (y^2/b^2) = 1
vii. Cos(2*x) = 1 – 2*(sin(x))^2

6. Develop a MATLAB program that computes and prints the volume of a cylinder, given
the radius and height of the cylinder to be 9m and 16m respectively.
Answer
radius = 9; height = 16;
volume = pi * radius^2 * height;
disp(volume)

You might also like