0% found this document useful (0 votes)
34 views7 pages

Exam Question

R CODING
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)
34 views7 pages

Exam Question

R CODING
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

Applied Computational Methods in Mechanical Engineering

Exam Question

You are given a system of linear equations representing a simplified mechanical model:

Task:

Using R programming, solve for the unknowns (x), (y), and (z).

Instructions:

• Define the coefficient matrix and the constants vector in R.

• Use appropriate R functions to solve the system.

• Display the solution vector.

• Comment briefly on the physical interpretation of the solution in the context of


mechanical systems (e.g., forces, displacements, or thermal balances).

[10 MARKS]
Applied Computational Methods in Mechanical Engineering

To solve a system of 3 linear equations using R programming.

Code Breakdown:

▪ matrix(...) creates a matrix.


▪ c(...) is a list of numbers that go into the matrix.
▪ nrow = 3 means the matrix will have 3 rows.
▪ byrow = TRUE tells R to fill the matrix row by row (left to right across each row).
▪ This matrix A contains the coefficients of the variables (x, y, z) from the system of
equations.

▪ This creates a vector B with the constants from the right-hand side of the equations.
▪ These are the values that each equation equals.

▪ solve(A, B) tells R to solve the equation Ax = B.


▪ It calculates the values of x, y, and z that satisfy all three equations.
▪ The result is stored in the variable solution.

▪ The first print() shows a message so you know what the output means.
▪ The second print(solution) displays the actual values of x, y, and z.
Applied Computational Methods in Mechanical Engineering

R Script:

#Let us define the coefficients of matrix A

A<-matrix(c(2,1,-2,

3,-3,-1,

1,-2,3), nrow=3, byrow= TRUE)

#Let us Define the coefficients of vector B

B<-c(-1,5,6)

#Let us solve the system of equations Ax=B and

solution<- solve(A, B)

print("Solution vector (x, y, z):")

print(solution)
Applied Computational Methods in Mechanical Engineering

MARKING RUBRIC

Step Requirement Marks Full Marks Partial Marks No Marks

1 Define 2 Both correctly Only one correct Both


coefficient defined with OR minor syntax missing/incorrect
matrix A and proper syntax errors
constants
vector b in R

2 Use correct R 3 Correct use of Attempted but Incorrect method


function to solve() with with minor or missing
solve system arguments in mistakes (e.g.,
(solve(A, b)) right order wrong order, small
syntax issues)

3 Display 2 Correctly prints Shows attempt but Not attempted


solution vector or displays the unclear/incorrect
solution (e.g., output method
print(solution))

4 Physical 3 Clear, correct Vague or partially No interpretation


interpretation explanation correct / irrelevant
in mechanical (forces, interpretation answer
context displacements,
or temperatures
with reference
to solution)
Applied Computational Methods in Mechanical Engineering

MEMORANDUM

R-Script:

# Define the coefficient matrix A

A <- matrix(c(3, 2, 1,

1, 4, 2,

1, 1, 1), nrow = 3, byrow = TRUE)

# Define the constants vector B

b <- c(10, 15, 8)

# Solve the system Ax = B

solution <- solve(A, B)

# Display the solution

print("Solution vector (x, y, z):")

print(solution)

Interpretation:

In mechanical engineering, systems of linear equations often model equilibrium or


compatibility conditions, where the unknowns may represent forces, displacements, or
temperatures (FEA and Thermal analysis). If interpreted as forces, the solution gives the
magnitudes needed to maintain equilibrium; if as displacements, it describes nodal
deformations under applied loads; and if as temperatures, it reflects steady-state thermal
balance. In this case, the solution x=1, y=2, and z=5 provides the consistent set of values
that simultaneously satisfy all three equilibrium equations.
Applied Computational Methods in Mechanical Engineering
Applied Computational Methods in Mechanical Engineering

Each and every code line explain in detail

You might also like