0% found this document useful (0 votes)
58 views32 pages

MatLab Activity#5

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)
58 views32 pages

MatLab Activity#5

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/ 32

LAB

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.

Open the MatLab


application on your
desktop.
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.

After opening, select


new, and select new
live script. This is
where codes went to
do solving in the
problem given.
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.

After creating a new


live script, enter the
following codes, each
of these are crucial in
solving the reaction
forces. The code will
be explained in the
next slides.
01 PROBLEM STEP-BY-STEP

CODE
EXPLANATION
The 3rd and 4th line
clears all the existing
variables and erases
everything in the
command window.

The succeeding variables of C1 up to C12 assign values into arrays or


matrix which are the equations of the reaction forces of the truss
01 PROBLEM STEP-BY-STEP

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.

To present the answer attained, a new variable ‘T’ should be defined


as ‘array2table’ and by placing the variable F in it and adding various
options such as ‘RowNames’ and ‘VariableNames’ to name the rows
and columns of our table.
01 PROBLEM STEP-BY-STEP

CODE
EXPLANATION
And lastly, the
command disp(T)
shows the tabulation of
the variable T.

Here is the result of


the code provided.
02 PROBLEM STEP-BY-STEP

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.

Open the MatLab


application on your
desktop.
02 PROBLEM STEP-BY-STEP

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.

After opening, select


new, and select new
live script. This is
where codes went to
do solving in the
problem given.
02 PROBLEM STEP-BY-STEP

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.

By assigning a variable F to the expression ‘linsolve(T, COST)’, the


prices of each food per pound is calculated.
02 PROBLEM STEP-BY-STEP

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

Here is the result of the


code provided.
03 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-
Jacobi in solving linear equations. To do that just follow this simple steps.

Open the MatLab


application on your
desktop.
03 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-
Jacobi in solving linear equations. To do that just follow this simple steps.

After opening, select


new, and select new
live script. This is
where codes went to
do solving in the
problem given.
03 PROBLEM STEP-BY-STEP

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.

Open the MatLab


application on your
desktop.
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.

After opening, select


new, and select new
live script. This is
where codes went to
do solving in the
problem given.
04 PROBLEM STEP-BY-STEP

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.

These lines define the coefficient matrix A and the right-hand


side vector b for the given system of linear equations.
04 PROBLEM STEP-BY-STEP

CODE
EXPLANATION
This line initializes the
solution vector xsub0
to zeros.It represents
the initial guess for the
solution.

These lines set the maximum number of iterations


(maxIterations) and the tolerance for convergence (tolerance).
04 PROBLEM STEP-BY-STEP

CODE
EXPLANATION
These lines initialize
the iteration counter
and the error for
convergence check.

Using while-for statement it repeats the block of code


based on certain condition
04 PROBLEM STEP-BY-STEP

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

You might also like