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

Assignment1 GroupV1

Uploaded by

Erickson Yan
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 views13 pages

Assignment1 GroupV1

Uploaded by

Erickson Yan
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/ 13

UNIVERSITI MALAYSIA SARAWAK

FACULTY OF ENGINEERING
CIVIL ENGINEERING DEPARTMENT

KNS 1482 ENGINEERING PROGRAMMING


ASSIGNMENT 1 - PAIRS

LECTURER Ir Yunika Kirana Abdul Khalik

GROUP V1

1. ERICKSON YAN ANAK AMBU (97387)


GROUP MEMBERS
2. JASON ANAK MONG (101759)
Pseucode for question 1

% gravity_calculation.m (Name of the scripted file)

% The value of the gravitational constant declaration (in m^3 kg^-1 s^-2)
G = 6.673 * 10^-11;

% Enter the mass of the first object (in kg)


m1 = input('Enter the mass of the first object (in kg): ');
Enter the mass of the first object (in kg): 20

% Enter the mass of the second object (in kg)


m2 = input('Enter the mass of the second object (in kg): ');
Enter the mass of the second object (in kg): 45

% Enter the distance between the two objects (in metres)


r = input('Enter the distance between the two objects (in metres): ');
Enter the distance between the two objects (in metres): 100

% Determine the gravitational force by using the formula


F = G * (m1 * m2) / r^2;

% Show the answer of F


fprintf('The gravitational force between the objects is %.3e N/m', F);
The gravitational force between the objects is 6.006e-12 N/m>>
Result from the code

>> Gravity calculation

G = 6.673 * 10^-11

m1 = 20kg

m2 = 45kg

r = 100m

F = G * (m1 * m2) / r^2

F = 6.006e-12 N/m
Pseucode for question 2

% Define the array A


A = [7 9 5;
4 1 2;
5 6 8];
% a) Create array B by copying elements from the second and third columns of A
B = A(:, 2:3);

% b) Create array C by copying elements from the first and second rows of A
C = A(1:2, :);

% c) Calculate D = B * C using matrix multiplication


D = B * C;

% d) Use max function to create a vector containing the maximum values of each column of D
max_values = max(D);

% e) Use min function to create a vector containing the minimum values of each row of D
min_values = min(D, [], 2);

% f) Multiply the two vectors found in parts d and e


result = max_values * min_values;

% Display the results


disp('Array B:');
disp(B);

disp('Array C:');
disp(C);

disp('Array D (B * C):');
disp(D);

disp('Maximum values of each column of D:');


disp(max_values);

disp('Minimum values of each row of D:');


disp(min_values);
disp('Result of multiplying the two vectors:');
disp(result);

Result from the code

>> Array
Array B:
9 5
1 2
6 8

Array C:
7 9 5
4 1 2

Array D (B * C):
83 86 55
15 11 9
74 62 46

Maximum values of each column of D:


83 86 55

Minimum values of each row of D:


55
9
46

Result of multiplying the two vectors:


7869
Pseucode for question 3

% calculate_equation.m (Name of Scripted File)

% State the value of pi


piValue= pi;

% Cslculate the value of theta


theta = 32 / piValue;

% Calculate the first term inside the cosh^-1 function


innerValue = -(theta - 2 * piValue);

% Calculate the cosh^-1 of the inner value


coshInverse = acosh(-innerValue);

% Calculate the base term


base = -piValue * coshInverse;

% Calculate the exponent


exponent = -piValue / (2 - 7 * piValue);

% Calculate the value of y


y = -piValue * (base ^ exponent);

% Print the answer value


fprintf('The value of y is %.3f/n', y);
The value of y is -3.704/n>>
Result from the code

Π ≈ 3.141592653589793

Θ ≈ 10.1859

InnerValue = −(10.1859 − 2 × 3.141592653589793) ≈ −3.097

The value of y is -3.704


Pseucode for question 4

% Script: echoname.m
% This script prompts the user for their name and prints it in a sentence.

% Prompt the user for their name


name = input('What is your name? ', 's');

% Echo print the name in a sentence


fprintf('Wow, your name is %s!\n', name);

Result from the code


>> echoname
What is your name? Jason
Wow, your name is Jason!
Replace “Jason” with your actual name if you run the script.
Pseucode for question 5

% thirdside.m (Name of Scripted File)

% Enter the first side length (b)


b = input('Enter the first side: ');
Enter the first side: 3

% Enter the second side length (c)


c = input('Enter the second side: ');
Enter the second side: 5

% Enter the angle between the two sides (alpha) in degrees


alpha = input('Enter the angle between the two sides: ');
Enter the angle between the two sides: 30

% Convert the angle from degree to radians


alphaRad = alpha * (pi / 180);

% Calculate the third side length (a) by using the formula


a = sqrt(b^2 + c^2 - 2 * b * c * cos(alphaRad));

% Show the value in three decimal places


fprintf('The third side is %.3f/n', a);
The third side is 2.832/n>>
Result from the code

>> thirdside
Enter the first side: 3
Enter the second side: 5
Enter the angle between them: 30
The third side is 2.832
Pseucode for question 6

% Define matrices A and B


A = [1, 2, 3;
4, 5, 6;
7, 8, 9];
B = [9, 8, 7;
6, 5, 4;
3, 2, 1];

% a) Perform matrix multiplication


C = A * B;

% b) Find the maximum and minimum values in C


max_value = max(C(:));
min_value = min(C(:));

% c) Find the maximum and minimum for each row


max_each_row = max(C, [], 2);
min_each_row = min(C, [], 2);

% d) Find the maximum and minimum for each column


max_each_column = max(C);
min_each_column = min(C);

% Display results
disp('Matrix C:');
disp(C);

disp('Maximum value in C:');


disp(max_value);

disp('Minimum value in C:');


disp(min_value);

disp('Maximum values for each row of C:');


disp(max_each_row);

disp('Minimum values for each row of C:');


disp(min_each_row);
disp('Maximum values for each column of C:');
disp(max_each_column);

disp('Minimum values for each column of C:');


disp(min_each_column);

Result from the code

>> Matrices
Matrix C:
30 24 18
84 69 54
138 114 90

Maximum value in C:
138

Minimum value in C:
18

Maximum values for each row of C:


30
84
138

Minimum values for each row of C:


18
54
90

Maximum values for each column of C:


138 114 90

Minimum values for each column of C:


30 24 18

You might also like