0% found this document useful (0 votes)
213 views28 pages

3 Topic 2 Fundamentals of Computer Aided Mathematical Calculations

The document provides information about computer programming and software. It discusses topics like structured programming, flowcharts, pseudocode, logical representations including sequence, selection, and repetition structures, and modular programming. It provides examples to illustrate concepts like an algorithm for solving a quadratic equation and using a function to implement Euler's method. Modular programming is said to have advantages like independent testing, easier debugging, and facilitating program maintenance and modification.

Uploaded by

Vincent Mendez
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)
213 views28 pages

3 Topic 2 Fundamentals of Computer Aided Mathematical Calculations

The document provides information about computer programming and software. It discusses topics like structured programming, flowcharts, pseudocode, logical representations including sequence, selection, and repetition structures, and modular programming. It provides examples to illustrate concepts like an algorithm for solving a quadratic equation and using a function to implement Euler's method. Modular programming is said to have advantages like independent testing, easier debugging, and facilitating program maintenance and modification.

Uploaded by

Vincent Mendez
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/ 28

ULYSSA MAE B.

SERRANO
PROGRAMMING AND SOFTWARE

OBJECTIVE
•To learn how to create well
documented program files by employing
structured programming to implement
logic and repetition
PROGRAMMING

1. Are you familiar with any Computer Programs? If yes, lets


list down all computer program you know?

2. What is Computer Program?


PROGRAMMING

COMPUTER PROGRAMS – are merely a set of instructions that direct the


computer to perform a certain task.

Programming Topics:
1. Simple information representation (constants, variables & type
declarations)
2. Advanced information rep. (data structure, arrays and records)
3. Mathematical formulas (assignment, priority rules and intrinsic functions)
4. Input/Output
5. Logical representation (sequence, selection & repetition)
6. Modular programming (functions and subroutines)
PROGRAMMING

STRUCTURED PROGRAMMING – set of rules that prescribe good style


habits for the programmer. Its rule impose enough constraint to
render the resulting codes for superior to unstructured versions

NUMERICAL ALGORITHM can be composed using the three


fundamental control structures: SEQUENCE, SELECTION AND
REPETITION. By limiting ourselves to these structures, the resulting
computer code will be clearer and easier to follow.
PROGRAMMING

FLOWCHART – a visual or graphical representation of an algorithm. The


flowchart employs a series of blocks and arrows, each of which represents
a particular operation or step in the algorithm (Fig. 2.1). The arrows
represent the sequence in which the operations are implemented.

Three reasons to study flowchart:


1. They are still used for expressing and communicating algorithms
2. Even if they are not employed routinely, there will be times when they
will prove useful in planning, unraveling, or communicating the logic of
your own or someone else’s program.
3. And most important they are excellent pedagogical tools
PROGRAMMING
PROGRAMMING

PSEUDOCODE – an alternative approach to express an algorithm that


bridges the gap between flow charts and computer code. This
technique uses code-like statements in place of the graphical symbols
of the flowchart. Keywords such as IF, DO, INPUT, etc. are capitalized,
where as the conditions, processing steps, and tasks are in lower
case.

Advantage: easier to develop a program with it than with a flowchart,


easier to modify and share with others. However, because of their
graphic form, flowcharts sometimes are better suited for visualizing
complex algorithms
PROGRAMMING

LOGICAL REPRESENTATION:
Sequence Structure: expresses the trivial idea that unless you direct
it otherwise, the computer code is to be implemented one instruction
at a time. As in Fig. 2.2, the structure can be expressed generically as
a flowchart or as pseudocode.
PROGRAMMING

LOGICAL REPRESENTATION:
Selection: In contrast to the step-by-step
sequence structure, selection provides a
means to split the program’s flow into
branches based on the outcome of a
logical condition. Fig. 2.3 shows the two
most fundamental ways for doing this.

The single-alternative decision or IF/THEN


structure (Fig 2.3a)
The double-alternative decision, or
IF/THEN/ELSE (Fig. 2.3 b)
PROGRAMMING

LOGICAL REPRESENTATION:
Selection:
Although the IF/THEN and the IF/THEN/ELSE
constructs are sufficient to construct any
numerical algorithm, two other variants are
commonly used. Suppose that the ELSE clause of
an IF/THEN/ELSE contains another IF/THEN. For
such cases, the ELSE and the IF can be combined
in the IF/THEN /ELSEIF structure shown in Fig.
2.4a. Notice in Fig 2.4a there is a chain or
“cascade” of decisions.

The CASE structure is a variant on this type of


decision making (Fig. 2.4b). Rather than testing
individual conditions, the branching is based on
the value of a single test expression.
PROGRAMMING

LOGICAL REPRESENTATION:
Repetition: provides a means to implement instructions repeatedly. The resulting
constructs, called loops, come in two “flavors” distinguished by how they are
terminated.
The first and most fundamental type is called a decision loop because it
terminates based on the result of a logical condition. Fig. 2.5 shows the most
generic type of decision loop, the DOEXIT construct, also called break loop.
If the first block is not included, the structure is sometimes called a pretest
loop because the logical test is performed before anything occurs. Alternatively, if
the second block is omitted, it is called a posttest loop. Because both blocks are
included, the general case in Fig 2.5 is sometimes called a midtest loop.
The break loop in Fig 2.5 is called a logical loop because it terminates on a
logical condition. In contrast, a count-controlled or DOFOR loop (Fig 2.6) performs
a specified number of repetitions, or iterations
PROGRAMMING

LOGICAL REPRESENTATION:
Repetition:
PROGRAMMING

LOGICAL REPRESENTATION:
Repetition:
PROGRAMMING

LOGICAL REPRESENTATION:
Repetition:
The index (i in Fig. 2.6) is a variable that is set at an initial value of
start. The program then tests whether the index is less than or equal
to the final value, finish. If so, it executes the body of the loop, and
then cycles back to the DO statement. Every time the ENDDO
statement is encountered, the index is automatically increased by the
step. Thus, the index acts as a counter. Then, when the index is
greater than the final value (finish), the computer automatically exits
the lopp and transfers control to the line following the ENDDO
statement.
PROGRAMMING

EXAMPLE 2.1: Algorithm for Roots of Equation


The roots of quadratic equation:
𝑎𝑥 2 + 4𝑥 + 𝑐 = 0
Can be determined with the quadratic formula,
−𝑏± 𝑏2 −4𝑎𝑐
Eq. 2.1 𝑥=
2𝑎
Develop an algorithm that does the following:
1. Prompts the user for the coefficients, a, b and c
2. Implements the quadratic formula, guarding against all eventualities (ex.
Avoiding division by zero and allowing for complex roots)
3. Displays the solution, that is, the values of x
4. Allows the user the option to return to step 1 and repeat the process
PROGRAMMING

EXAMPLE 2.1: Algorithm for Roots of Equation


SOLUTION: 1st refine the algorithm rather trying to work out all the
details the first time around.
PROGRAMMING

Eq. 2.2

where n= number of iterations of the loop.


PROGRAMMING

MODULAR PROGRAMMING – a computer program that can be divided


into small subprograms, or modules that can be developed and tested
separately.
The most important attribute of modules is that they be as
independent and self-contained as possible. In addition, they are
typically designed to perform a specific, well-defined function and
have one entry and one exit point. As such, they are usually short
(generally 50 to 100 instructions in length) and highly focused.
Excel macros and MATLAB functions are designed to receive some
information, perform a calculation, and return results.
PROGRAMMING

In addition, it should be mentioned that much of the programming related to


software packages like Excel and MATLAB involves the development of subprograms. Excel
macros and MATLAB functions are designed to receive some information, perform
calculation and return results. Thus, modular thinking is also consistent with how
programming is implemented in package environments.
Modular programming has a number of advantages. The use of small, self-
contained units makes the underlying logic easier to devise and to understand for both the
developer and the user. Development is facilitated because each module can be perfected
in isolation. In fact, for large projects, different programmers can work on individual
parts. Modular design also increases the ease with which a program can be debugged and
tested because errors can be more easily isolated. Finally, program maintenance and
modification are facilitated. This is primarily due to the fact that new modules can be
developed to perform additional tasks and then easily incorporated into the already
coherent and organized scheme.
While all these attributes are reason enough to use modules, the most important reason
related to numerical engineering problems solving is that they allow you to maintain your
own library of useful modules for later use in other programs.
PROGRAMMING

MODULAR PROGRAMMING
Example, Fig. 2.7 shows a function
developed to implement Euler’s method.
Notice that this function application and
the previous versions differ in how they
handle input/output. In the former
versions, input and output directly come
from (via INPUT statement) and to (via
DISPLAY statements) the user. In the
function, the inputs are passed into the
FUNCTION via its argument list
Function Euler(dt, ti, tf, yi)
and the output is returned via the
assignment statement
y = Euler(dt, ti, tf, yi)
PROGRAMMING

MODULAR PROGRAMMING
In addition, recognized how generic the routine has become. There
are no references to the specifics of the parachutist problem. For
example, rather than calling the dependent variable y for velocity,
the more generic label, y, is used within the function. Further, notice
that the derivative is not computed within the function by an explicit
equation. Rather, another function, dy, must be invoked to compute
it. This acknowledges the fact that we might want to use this function
for many different problems beyond solving for the parachutist’s
velocity.
EXCEL

EXCEL – spreadsheet produced by Microsoft, Inc. Spreadsheets are a special


type of mathematical software that allow the user to enter and perform
calculations on rows and columns of data. As such, they are a computerized
version of a large accounting worksheet on which large interconnected
calculations can be implemented and displayed. Because the entire
calculation is updated when any value on the sheet is changed,
spreadsheets are ideal for “what if?” sorts of analysis.
Excel has some built-in numerical capabilities including equation solving,
curve fitting and optimization. It also includes VBA as a macro language
that can be used to implement numerical calculations. Finally, it has
several visualization tools, such as graphs and three-dimensional surface
plots, that serve as valuable adjuncts for numerical analysis.
EXCEL
MATLAB

MATLAB – flagship software product of the MathWorks, Inc., which


was co-founded by the numerical analysts Cleve Moler and John N.
Little. As the name implies, MATLAB was originally developed as a
matrix laboratory. The major element of MATLAB is still the matrix.
Mathematical manipulations of matrices are very conveniently
implemented in an easy-to-use, interactive environment. To these
matrix manipulations, MATLAB has added a variety of numerical
functions, symbolic computations, and visualization tools.
Programs can be written as so-called M-files that can be used to
implement numerical calculations.
MATLAB

You should recognize that normal MATLAB use is closely related to programming.
For example, suppose that we wanted to determine the analytical solution to the
parachutist problem. This could be done with the following series of MATLAB
commands
>>g=9.81;
>>m=68.1;
>>cd=12.5;
>>tf=2;
>>v=g*m/cd*(1-exp(-cd/m*tf))
With the result being displayed as
v= 16.4217
Thus, the sequence of commands is just like the sequence of instructions in a
typical programming language.
MATHCAD

MATHCAD attempts to bridge the gap between spreadsheets like Excel and
notepads. It was originaaly developed by Allen Razdow of MIT who co founded
Mathsoft, Inc., which published the first commercial version in 1986.
MATHCAD is essentially an interactive notepad that allows engineers and
scientists to perform a number of common mathematical, data-handling, and
graphical tasks. Information and equations are input to a “whiteboard” design
environment that is similar in spirit to a page of paper. Unlike a programming tool
or spreadsheet, Mathcad’s interface accepts and displays natural mathematical
notation using keystrokes or menu palette clicks – with no programming required.
Because the worksheets contain live calculations, a single keystroke that changes
an input or equation instantly returns an updated result.
MATHCAD can perform tasks in either numeric or symbolic mode. In numeric
mode, Mathcad functions and operators give numeriocal responses, whereas in
symbolic mode results are given as general expressions or equations. Maple V, a
comprehensive symbolic math package, is the basis of the symbolic mode and was
incorporated into Mathcad in 1993
ASSIGNMENT #2:
INSTRUCTION: Write your solution in 1 whole long bond paper. All solution must
be hand written and submit it through google classroom. Follow the format given
(Deadline will be before the next meeting)

2.1 Write pseudocode to implement the flowchart depicted in Figure


P2.1. Make sure that proper indentation is included to make the
structure clear.

You might also like