0% found this document useful (0 votes)
36 views8 pages

Computational Lab

The document contains details about Ayush Kumar Bhardwaj, a student with roll number 21CE8009 and registration number 21U10151 studying in the Department of Civil Engineering at the National Institute of Technology-Durgapur. It lists his name, roll number, and registration number.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views8 pages

Computational Lab

The document contains details about Ayush Kumar Bhardwaj, a student with roll number 21CE8009 and registration number 21U10151 studying in the Department of Civil Engineering at the National Institute of Technology-Durgapur. It lists his name, roll number, and registration number.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

NATIONAL INSTITUTE OF TECHNOLOGY-DURGAPUR

DEPARTMENT OF CIVIL ENGINEERING


NAME - AYUSH KUMAR BHARDWAJ
ROLL NO. – 21CE8009
REG. NO. - 21U10151

Solution:

*INPUT*
% Input for Matrix A
rows_A = input('Enter the number of rows for Matrix A: ');
cols_A = input('Enter the number of columns for Matrix A: ');
A = zeros(rows_A, cols_A);

for i = 1:rows_A
for j = 1:cols_A
A(i, j) = input(sprintf('Enter element at position (%d, %d) for Matrix A: ', i,
j));
end
end

% Input for Matrix B


rows_B = input('Enter the number of rows for Matrix B: ');
cols_B = input('Enter the number of columns for Matrix B: ');
B = zeros(rows_B, cols_B);

for i = 1:rows_B
for j = 1:cols_B
B(i, j) = input(sprintf('Enter element at position (%d, %d) for Matrix B: ', i,
j));
end
end

% Perform operations
C = A + B;
D = A - B;
E = A * B;
F = B * A;
trace_A = trace(A);
transpose_B = B';
scalar_factor = input('Enter the scalar factor: ');
% Calculate results
Z = scalar_factor * B;
Y = B * Z;
rank_B = rank(B);
eigenvalues_A = eig(A);
inverse_B = inv(B);

% Display results
disp('Addition of Matrix A and B:');
disp(C);
disp('Subtraction of Matrix A and B:');
disp(D);
disp('Product A * B:');
disp(E);
disp('Product B * A:');
disp(F);
disp('Trace of Matrix A:');
disp(trace_A);
disp('Transpose of Matrix B:');
disp(transpose_B);
disp('Scaled Matrix B:');
disp(Z);
disp('Result of B * scaled B:');
disp(Y);
disp('Rank of Matrix B:');
disp(rank_B);
disp('Eigenvalues of Matrix A:');
disp(eigenvalues_A);
disp('Inverse of Matrix B:');
disp(inverse_B);

*OUTPUT*
Solution:

*INPUT*

% Initializing variables
total_sum = 0;

% Loop for summing 12 numbers


for i = 1:12
user_input = input(['Enter number ' num2str(i) ' for sum: ']);
total_sum = total_sum + user_input;
end
disp(['(1) The sum of the twelve numbers is: ' num2str(total_sum)]);

% Computing decimal sum


sum_decimal = 1.5 + 3.2 + 4.1 + 7.9;
disp(['(2) sumDecimal = ' num2str(sum_decimal)]);

% Loop for product of 7 numbers


total_prod = 1;
for i = 1:7
input_prod = input(['Enter number ' num2str(i) ' for product: ']);
total_prod = total_prod * input_prod;
end
disp(['(3) The product of the 7 numbers is: ' num2str(total_prod)]);

% Division operation
numerator = input('Enter the numerator: ');
denominator = input('Enter the denominator: ');

if denominator == 0
disp('Division by zero is undefined.');
else
result = numerator / denominator;
remainder = mod(numerator, denominator);

disp(['(4) The result of ' num2str(numerator) ' / '


num2str(denominator) ' is: ' num2str(result)]);
disp(['(5) The remainder of ' num2str(numerator) ' / '
num2str(denominator) ' is: ' num2str(remainder)]);
end

% Cubic operation
x_value = input('Enter the value for x: ');
y_value = input('Enter the value for y: ');
cubic_result = (x_value - y_value)^3;
disp(['(6) The result of (' num2str(x_value) ' - ' num2str(y_value)
')^3 is: ' num2str(cubic_result)]);

% Selection operation
L = 3.1;
m = -1.5;
n = pi / 2;
x_val = 2 / pi;
y_val = 3^(1/2);

disp('Enter the choice for the operation you need:');


disp('1. L^2 + mn + x');
disp('2. sin(n) + (y/n)');
disp('3. 1/(cos(n) + ln(x))');
disp('4. (L+n)/(x+y)');
disp('5. (L+n)^3/m');
choice = input('Enter the choice: ');

fprintf('(7) Solution for the choice is: ');


switch choice
case 1
result_choice = L^2 + m*n + x_val;
disp(result_choice);
case 2
result_choice = sin(n) + (y_val/n);
disp(result_choice);
case 3
result_choice = 1/(cos(n) + log(x_val));
disp(result_choice);
case 4
result_choice = (L+n)/(x_val+y_val);
disp(result_choice);
case 5
result_choice = ((L+n)^3)/m;
disp(result_choice);
end

% Sum of first n integers


n_value = input('Enter a positive integer n: ');
if ~isnumeric(n_value) || n_value <= 0 || mod(n_value, 1) ~= 0
disp('Please enter a positive integer.');
else
sum_integers = n_value * (n_value + 1) / 2;
fprintf('(8) The sum of the first %d integers is: %d\n', n_value,
sum_integers);
end

% Summation condition
total_sum = 0;
for i = 1:100
if mod(i,5)==0 && mod(i,8)~=0
total_sum = total_sum + i;
end
end
fprintf('(9) The summation is: %d\n', total_sum);

% Cubic summation
n_value = input('Enter the value of n: ');
total_sum = 0;
for i = 1:n_value
cube_val = i^3;
total_sum = total_sum + cube_val;
end
fprintf('(10) The summation is: %d\n', total_sum);

% Cone volume calculation


r1 = input('Enter the radius of cone 1: ');
h1 = input('Enter the height of cone 1: ');
r2 = input('Enter the radius of cone 2: ');
h2 = input('Enter the height of cone 2: ');

volume1 = (1/3) * pi * (r1^2) * h1;


volume2 = (1/3) * pi * (r2^2) * h2;

difference_volume = volume1 - volume2;

fprintf('(11) Volume of cone 1 is: %f\n', volume1);


fprintf(' Volume of cone 2 is: %f\n', volume2);
fprintf(' The difference in volume is: %f\n', difference_volume);

*OUTPUT*
Solution:

*INPUT*

% Parameters for Beam 1


L_beam1 = input('(1) Enter the length of the beam (L): ');
E_beam1 = input(' Enter the Young''s modulus of the material (E): ');
I_beam1 = input(' Enter the flexural rigidity of the beam (I): ');

deflection_center_beam1 = (5 / (384 * E_beam1 * I_beam1)) * (L_beam1^4);


rotation_ends_beam1 = (1 / (8 * E_beam1 * I_beam1)) * (L_beam1^3);
fprintf('(1a) Deflection at center: %f\n', deflection_center_beam1);
fprintf('(1b) Rotations at ends: %f\n\n', rotation_ends_beam1);

% Parameters for Cantilever Beam 2


L_beam2 = input('(2) Enter the length of the cantilever beam (L): ');
E_beam2 = input(' Enter the Young''s modulus of the material (E): ');
I_beam2 = input(' Enter the flexural rigidity of the beam (I): ');

deflection_center_beam2 = (1 / (48 * E_beam2 * I_beam2)) * (L_beam2^3);


rotation_center_beam2 = (1 / (16 * E_beam2 * I_beam2)) * (L_beam2^2);
deflection_free_end_beam2 = (1 / (6 * E_beam2 * I_beam2)) * (L_beam2^3);
rotation_free_end_beam2 = (1 / (2 * E_beam2 * I_beam2)) * (L_beam2^2);

fprintf('(2a) Deflection at center: %f\n', deflection_center_beam2);


fprintf('(2b) Rotation at center: %f\n', rotation_center_beam2);
fprintf('(2c) Deflection at free end: %f\n', deflection_free_end_beam2);
fprintf('(2d) Rotation at free end: %f\n\n', rotation_free_end_beam2);

% Parameters for Fixed Beam 3


L_beam3 = input('(3) Enter the length of the fixed beam (L): ');
E_beam3 = input(' Enter the Young''s modulus of the material (E): ');
I_beam3 = input(' Enter the flexural rigidity of the beam (I): ');

deflection_025L_beam3 = (1 / (324 * E_beam3 * I_beam3)) * (35 * L_beam3^4 - 48 * 0.25^2 *


L_beam3^2 + 16 * 0.25^3 * L_beam3);
deflection_075L_beam3 = (1 / (324 * E_beam3 * I_beam3)) * (35 * L_beam3^4 - 48 * 0.75^2 *
L_beam3^2 + 16 * 0.75^3 * L_beam3);
rotation_075L_beam3 = (1 / (162 * E_beam3 * I_beam3)) * (9 * L_beam3^3 - 36 * 0.75 *
L_beam3^2 + 32 * 0.75^2 * L_beam3);

fprintf('(3a) Deflection at 0.25L: %f\n', deflection_025L_beam3);


fprintf('(3b) Deflection at 0.75L: %f\n', deflection_075L_beam3);
fprintf('(3c) Rotation at 0.75L: %f\n\n', rotation_075L_beam3);

% Parameters for Beam 4


L_beam4 = input('(4) Enter the length of the beam (L): ');
E_beam4 = input(' Enter the Young''s modulus of the material (E): ');
I_beam4 = input(' Enter the flexural rigidity of the beam (I): ');
location = input(' Enter the location where you want to find deflection and rotation
(between 0 and L): ');
deflection_location_beam4 = (1 / (6 * E_beam4 * I_beam4)) * (location^2 * (3 * L_beam4 -
location));
rotation_location_beam4 = (1 / (2 * E_beam4 * I_beam4)) * (location * (L_beam4 -
location)^2);

fprintf('(4a) Deflection at %f: %f\n', location, deflection_location_beam4);


fprintf('(4b) Rotation at %f: %f\n\n', location, rotation_location_beam4);

*OUTPUT*

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy