Professional Documents
Culture Documents
Matlab Report
Matlab Report
Matlab Report
QUESTION NO 1
I created a script file using .m extension and the code is pasted below.
function displayStudentGrades ()
% Ask/prompt the user to enter a numeric grade
numericGrade = input('enter numeric grade : ');
OUTPUT
QUESTION NO 2
function trianglecalculations ()
%prompt the user to input triangle sides
a = input('Enter the length of side a : ');
b = input('Enter the length of side b : ');
c = input('Enter the length of side c : ');
% calculation of perimeter
p = (a + b +c);
% Results
fprintf('Area: %.2f\n' , Area);
fprintf('Semi Perimeter : %.2f\n' , s);
fprintf('Perimeter: %.2f\n' , p);
OUTPUT
QUESTION NO 3
OUTPUT
QUESTION NO 4
function result = custom_function()
% Get user input for x
x = input('Enter the value for x: ');
OUTPUT
QUESTION NO 5
Part 1
% Define the function to integrate
f = @(x) sqrt(4 - x.^2);
% Integration limits
a = 0; % Lower limit
b = 2; % Upper limit
% Number of subintervals
n = 8;
% Simpson's 1/3 rule
h = (b - a) / n;
x = a:h:b;
y = f(x);
integral_1_3 = (h/3) * (y(1) + 4*sum(y(2:2:end-1)) + 2*sum(y(3:2:end-2)) +
y(end));
% Simpson's 3/8 rule
h_3_8 = (b - a) / (3 * n);
x_3_8 = a:h_3_8:b;
y_3_8 = f(x_3_8);
integral_3_8 = (3*h_3_8/8) * (y_3_8(1) + 3*sum(y_3_8(2:3:end-1)) +
3*sum(y_3_8(3:3:end-2)) + 2*sum(y_3_8(4:3:end-3)) + y_3_8(end));
% Display results
fprintf('Integration using Simpson''s 1/3 rule: %.6f\n', integral_1_3);
fprintf('Integration using Simpson''s 3/8 rule: %.6f\n', integral_3_8);
Output
Part 2
% Define the function
f = @(x) (sqrt(1 - exp(-x))) / x;
% Define the limits of integration
a = 0;
b = 2;
% Number of intervals (n=8)
n = 8;
% Simpson's 1/3 rule
h = (b - a) / n;
x = a:h:b;
y = f(x);
S1_3 = h/3 * (y(1) + 4*sum(y(2:2:end-1)) + 2*sum(y(3:2:end-2)) + y(end));
% Simpson's 3/8 rule (for the remaining interval)
h_3_8 = (b - x(end-2)) / 3;
y_3_8 = f(x(end-2):h_3_8:b);
S3_8 = 3 * h_3_8 / 8 * (y_3_8(1) + 3*sum(y_3_8(2:end-1)) + y_3_8(end));
% Total integration using both rules
total_integration = S1_3 + S3_8;
% Display the results
fprintf('Simpson 1/3 rule result: %.6f\n', S1_3);
fprintf('Simpson 3/8 rule result: %.6f\n', S3_8);
fprintf('Total integration result: %.6f\n', total_integration);
OUTPUT
QUESTION NO 6
% Get user input for x
x = input('Enter the value of x: ');
% Calculate f(x)
result = sqrt(x + 1);
OUTPUT
QUESTION NO 7
%According to my cms number 403566
m = 6;
l = 6;
k = 5;
h = (m + l) / 100; % Step Size
x = m + k : h : m + k + 2;
y = m * x ./ (l * x + 1 ./ x.^k);
if m <= 0 || m < 4
m = 2;
end
if l <= 0 || l < 4
l = 2;
end
r1 = rem(m, 4);
r2 = rem(l, 4);
if r1 == 0
plot(x, y, 'yellow-.'), xlabel('x'), ylabel('y'), title('My Graph'), legend('y');
elseif r1 == 1
plot(x, y, 'red--'), xlabel('x'), ylabel('y'), title('My Graph'), legend('y');
elseif r1 == 2
plot(x, y, 'green:'), xlabel('x'), ylabel('y'), title('My Graph'), legend('y');
elseif r1 == 3
plot(x, y, 'black-'), xlabel('x'), ylabel('y'), title('My Graph'), legend('y');
end
if r2 == 0
plot(x, y, 'yellow-.'), xlabel('x'), ylabel('y'), title('My Graph'), legend('y');
elseif r2 == 1
plot(x, y, 'red--'), xlabel('x'), ylabel('y'), title('My Graph'), legend('y');
elseif r2 == 2
plot(x, y, 'green:'), xlabel('x'), ylabel('y'), title('My Graph'), legend('y');
elseif r2 == 3
plot(x, y, 'black-'), xlabel('x'), ylabel('y'), title('My Graph'), legend('y');
end
OUTPUT