Answer All Questions:: Solution
Answer All Questions:: Solution
clear
clc
syms x
y= x^6 - x^5 - 6*x^4 + 4*x^3 - 12*x^2
p=[1 -1 -6 4 -12 0 0];
roots(p)
2. Write a MATLAB program to evaluate a function f(x,y) for any two user-specified values
x and y. The function f(x,y) is defined as follows.
Solution:
3. Suppose that we are writing a program which reads in a numerical grade and assigns a
letter grade to it according to the following table:
Solution:
5. Use three input values: 3, 4, and 5, to calculate the mean and standard deviation of these values using
Matlab Program.
clear
clc
% Define variables:
% n -- The number of input samples
% std_dev -- The standard deviation of the input samples
% sum_x -- The sum of the input values
% x -- An input data value
% xbar -- The average of the input samples
x1=[3 4 5];
x=[3 4 5];
n=length(x)
x_bar = sum(x)/length(x)
6. Develop a Matlab Program to know the level of the student in the academic semester and
year automatically.
clear
clc
% Age of the student in year
age=input('Input the target age: ')
if age>=25
disp('This student already graduated')
elseif age>=24
disp('This student study in level 10 at the 4th year')
elseif age>=23.5
disp('This student study in semester 9 at the 4th year')
elseif age>=23
disp('This student study in semester 8 at the 3rd year')
elseif age>=22.5
disp('This student study in semester 7 at the 3rd year')
elseif age>=22
disp('This student study in semester 6 at the 2nd year')
elseif age>=21.5
disp('This student study in semesrae 5 at the 2nd year')
elseif age>=21
disp('This student study in semester 4 at the 1st year')
elseif age>=20.5
disp('This student study in semester 3 at the 1st year')
else
disp('This student study in the Preparatory Year or not
enter the university yet')
end
Tutorial CSC209 Controls & Loops
The Output: 1 * 1 = 1
1 * 2 = 2
1 * 3 = 3
End of inner loop
2 * 1 = 2
2 * 2 = 4
2 * 3 = 6
End of inner loop
3 * 1 = 3
3 * 2 = 6
3 * 3 = 9
End of inner loop
End of outer loop
for a = 10:20
fprintf('value of a: %d\n', a);
end
No output