MatLab Activity#5
MatLab Activity#5
ACTIVITY #5
MATLAB® is a programming platform designed
specifically for engineers and scientists to
analyze and design systems and products that
transform our world. The heart of MATLAB is
the MATLAB language, a matrix-based language
allowing the most natural expression of
computational mathematics.
NEXT PAGE
www.mathworks.com
PAGE 01
TABLE OF CONTENTS
PROBLEM 01
A truss is a structure made of members
joined at their ends. Use MATLAB to
calculate the forces and reactions for the
truss in figure.
PAGE 02
PROBLEM 02
A food company manufactures the five types of
1.0 lb trail mix packages that have the following
composition and cost: Using the information in
the table, determine the cost per pound of each
of the ingredients using MATLAB.
PAGE 03
PROBLEM 03
Write a MATLAB program that will solve the
system of linear equations using Gauss –
Jacobi Method. Show each iteration in table.
PAGE 04
PROBLEM 04
Write a MATLAB program that will solve the
system of linear equations using Gauss – Seidel
Method. Show each iteration in table.
01 PROBLEM STEP-BY-STEP
To determine the reaction forces of the truss in the given problem, a code is
made by utilizing the Matrix solving capability of the MatLab. To do that just
follow this simple steps.
To determine the reaction forces of the truss in the given problem, a code is
made by utilizing the Matrix solving capability of the MatLab. To do that just
follow this simple steps.
To determine the reaction forces of the truss in the given problem, a code is
made by utilizing the Matrix solving capability of the MatLab. To do that just
follow this simple steps.
CODE
EXPLANATION
The 3rd and 4th line
clears all the existing
variables and erases
everything in the
command window.
CODE
EXPLANATION
After assigning the
values into arrays,
these variables should
be put in together as
one matrix along with
its equivalent values
assigned in variable C.
The code ‘format longG’ presents the answer in a value with more
than 4 decimal places which we need to come up in a more exact
answer.
01 PROBLEM STEP-BY-STEP
CODE
EXPLANATION
In addition, by
assigning a new
variable F to the
function inv(T)*C, the
desired answer should
be attained.
CODE
EXPLANATION
And lastly, the
command disp(T)
shows the tabulation of
the variable T.
To determine the cost of the products in the given problem, a code is made by
utilizing the Matrix solving capability of the MatLab. To do that just follow this
simple steps.
To determine the cost of the products in the given problem, a code is made by
utilizing the Matrix solving capability of the MatLab. To do that just follow this
simple steps.
CODE
EXPLANATION
The variables A, B, C, D
and E assign values
into matrix which are
the equations of the
total products in a set.
The variable ‘COST’ is the total price of the products in each set and
also by assigning another variable ‘T’, the variables A, B, C, D, and E
are made into matrix.
02 PROBLEM STEP-BY-STEP
CODE
EXPLANATION
Using ‘format longG’,
the variable to be
present is in a long
decimal place to gain
the exact values.
CODE
EXPLANATION
To present the attained
values, a new variable
‘L’ is assigned to the
command ‘array2table’
along with the options
to change names of the
rows and columns of And lastly, to display the tabulated
the table. data, the command ‘disp(L)’ should be
used.
02 PROBLEM STEP-BY-STEP
CODE
EXPLANATION
To solve the system of linear equations in the given problem, a code is made by
utilizing loops and Matrices of the MatLab which follows the method of Gauss-
Jacobi in solving linear equations. To do that just follow this simple steps.
To solve the system of linear equations in the given problem, a code is made by
utilizing loops and Matrices of the MatLab which follows the method of Gauss-
Jacobi in solving linear equations. To do that just follow this simple steps.
CODE
EXPLANATION
The values of the
coefficients of the
linear equations and
the constants are
defined into matrix ‘A’
and matrix ‘b’,
respectively.
The succeeding line initiates the solution vector ‘xsub0’ into zeros.
The other lines limit the answers up to 20 iterations with specific
tolerance of 1E-4 to define the convergence of the answer.
The variable ‘iteration’ is where the value initiates and the ‘error’ is
for convergence check.
03 PROBLEM STEP-BY-STEP
CODE
EXPLANATION
The ‘while’ loop
command repeats as
long as it satisfies the
operation. And within
the ‘while’ loop
command, a ‘for’ loop
command is placed The succeeding lines after the ‘for’ loop
with the formula for the calculates the error between the
Gauss-Jacobi. current and the previous solutions.
03 PROBLEM STEP-BY-STEP
CODE
EXPLANATION
Afterwards, the
iterations values are
stored in array and its
succeeding code
updates the iteration
counter and the current
solution vector for the The presentation of data involves
next variable is solved. assigning a new variable ‘K’ to k which
stores the iteration value. Afterwards,
new variable ‘C’ is introduced to
command ‘array2table’ with various
options for changing the names.
03 PROBLEM STEP-BY-STEP
CODE
EXPLANATION
This is the result of the
code, after some
specific number of
iterations it reached
the values 5, -2, 2.5
and -1 for x1, x2, x3,
and x4, respectively.
04 PROBLEM STEP-BY-STEP
To solve the system of linear equations in the given problem, a code is made by
utilizing loops and Matrices of the MatLab which follows the method of Gauss-
Seidel in solving linear equations. To do that just follow this simple steps.
To solve the system of linear equations in the given problem, a code is made by
utilizing loops and Matrices of the MatLab which follows the method of Gauss-
Seidel in solving linear equations. To do that just follow this simple steps.
CODE
EXPLANATION
The "clc" is a command
use to clear the
command window.
"clear" is used to clear
your workspace,
removing all the saved
variables from memory.
CODE
EXPLANATION
This line initializes the
solution vector xsub0
to zeros.It represents
the initial guess for the
solution.
CODE
EXPLANATION
These lines initialize
the iteration counter
and the error for
convergence check.
CODE
EXPLANATION
These lines calculate
the error between the
current and previous
solutions, update the
error variable, and
display the current
iteration and solution in
the table.
This updates the iteration counter and the current solution vector for
the next iteration.
04 PROBLEM STEP-BY-STEP
CODE
EXPLANATION
These lines display the
final solution and the
number of iterations
taken to reach the
solution.
PROOF OF
COLLABORATION
DISTRIBUTION
OF WORKS
CODE: MOSTAJO, WARREN
CARANDANG, JUSTINE DAVE
BOLANO, RALPH AIRON JAY
CDESIGN: PALISOC, NORVIN
TEMPLANZA, JUSTIN