









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A portion of lecture notes from a computer methods course, specifically focusing on numerical methods lecture 3. The lecture covers solving systems of linear equations symbolically using mathcad and finding roots of equations using various methods such as incremental search, bisection method, and false position method.
Typology: Study notes
1 / 15
This page cannot be seen from the preview
Don't miss anything!










Lecture covers two things:
Let’s take a look at a very powerful tool in Mathcad that started a revolution in computational analysis. It started in the late 1980’s when I was an undergraduate. A company called Wolfram created a computer program called Mathematica. This was the first computer code that could solve algebraic and calculus equations symbolically. That is, if I had an equation that said x*y = z, Mathematica could tell me that y = z / x, without ever needing me to assign numbers to x, y, or z. It also was able to solve integrals, dif- ferential equations, and derivatives symbolically. This was an incredible advance, and opened the doors to a whole new world of programming, numerical methods, pure mathematics, engineering, and science.
Since then, a competing code called Maple was developed and sold itself to other software companies to include in their programs.
The end result: Mathcad uses Maple as a solving engine in the background (you don’t see it) to solve problems symbolically. Here we will look at a brief example of how to use this capability in the context of solving a system of linear equations.
Example : The structural system below is something you will see in CES 3102 or CES 4141. r1 and r2 are labels that indicate how the ends of the beam are allowed to move. Q and W represent the external loads (a couple and a distributed load, respectively), and material properties are given as E and I. L is the length of the beam. The goal is to solve for the amount or rotation at r1, and the deflection at r2 that occurs for thegiven loads. This would help us to solve for internal stresses, allowing us to design the beam to sur- vive these internal forces.
Solution : The way we learn to solve this problem in CES 4141 is using a Matrix-based solution proce- dure. The generic form of the solution is K * r = R K is a 2 x 2 ‘stiffness’ matrix that contains information about the structures shape, boundary conditions and material properties. THe information needed is L, E, and I
r is a 2 x 1 vector that contains the unknown rotation and displacement quantities sought.
R is a 2 x 1 vector that contains only information about the external loads (W and Q for this problem).
r1 r
E = 4000 ksi I = 1400 in^
Solution continued : So we will have K as a known 2 x 2 stiffness matrix We will have R as a known 2 x 1 load vector We will solve for the unknown displacement vector r
We will not go into any detail on HOW we fill in the values for K and R, that’s for another class. Here we will just consider how to solve the ssytem of matrix equations symbolically.
Define Load Vector R as a Define Stiffness K as a function of E, I, L function of Q, W, L
2
2
12 E⋅ ⋅I
L 3
2 ⋅ 30
The variables in the parenthesis (E,I,L) and (Q,W,L) is telling mathcad that the variables K and R, respectively, will be a function of those variables.
known information
Show me the inverse of the stiffness matrix Not a necessary step, but pretty cool see the matrix version of 1/K Note the arrow --> is the way to initiate a symbolic operation. Here we are asking what is the inverse of K? The arrow comes from the view => toolbars => symbolic pad
K E I( , ,L) 1 −
1 ( E I⋅)
⋅L
− 1 ( 2 E I⋅ ⋅)
⋅L^2
− 1 ( 2 E I⋅ ⋅)
L ⋅^2
1 ( 3 E I⋅ ⋅)
⋅L^3
→
Calculate the displacement vector as K -1^ * R Note that we DO need to keep writing the names of the independent variables next to K, r, and R to tell Mathcad what symbols to look for
r E I( , , L, Q,W) K E I( , ,L) 1 − := ⋅R Q W( , ,L)
Display the resulting displacement vector calculated in terms of W, Q, L, E, I
Note the arrow displays a r E I( , , L, Q,W) symbolic result
1 (E I ⋅)
⋅ (^) L Q 1 30
⋅ (^) WL
⋅ 7 ( 40 E I⋅ ⋅)
L ⋅ 3 − ⋅W
− 1 ( 2 E I ⋅ ⋅)
L ⋅ 2 Q
1 30
⋅W (^) L
⋅ 7 (60 E I ⋅ ⋅)
L ⋅ 4
→
Symbolic Solution
Symbolic Inverse
Symbolic Calculation
We won’t go into the algorithms themselves here. We will just focus on how to use Mathcad to solve the problem.
Use Mathcad help and use the keywords ‘nonlinear equations’ to get some information. Follow the link to the ‘Find’ function in Mathcad. ‘Find’ is the workhorse that gets the solution. All you need to do is give it the correct description of the problem. This includes the equations to solve, any possible constraints to the solutions you are interested in, and a place to start looking for a solution (i.e., initial guess for the solution). Here we will go straight into an example to show how it’s done.
f3 x( ) (^) := 1 x .15 x
6 4 2 0 2 4 6
4
2
0
2
4
6
f1 i( ) f2 i( ) f3 i( )
i
ORIGIN ≡ 1
Using the Find function to solve systems of nonlinear equations This example will solve for the intersecting values of the followin system of 2 equations
x^2 + (y − 2 ) 2 8
x + .15 x ⋅^2 + y 1
Let's first take a look at the solution visually by plotting We will create some functions that allow us to plot the two equations above
f1 x( ) := 8 − x^2 + 2
i :=− 5 , −4.99.. 4 f2 x( )^ :=−^8 −x^2 +^2 f3 x( ) := 1 − x−.15 x ⋅^2 f3( x ) (^) := 1 x .15 x
6 4 2 0 2 4 6
4
2
0
2
4
6
f1 i( ) f2 i( ) f3 i( )
i
We can see that there are two solutions to the two equations above. We'll try to find both solutions by using the 'find' function
Use the help desk with the keyword 'find function'
Step one: start by guessing the solution to the set of two equations we are trying to solve. Let's guess that x=4 and y= -
x :=^4 y :=− 1
Next we create what is called a 'solve block'. This defines the equations to be solved.
Note that we use the 'boolean' tab to get the equal sign, (^) not the keyboard stroke.
Given
x^2 + (y − 2 ) 2 8
x + .15 x ⋅^2 + y 1
Finally, we use the 'Find' function to solve by sending in the two guesses we made above for x and y
Find x y( , )
−0.
=
'Find' starts looking at the initial guess values, and iteratively updates the values of x and y until a pair is found that solves the equations defined in the solve block.
The results give the x and y values corresponding to one of the solutions. find where x=1.278 and y= -0.523 in the graph above 'Find' found this solution because the initial guesses were closer to this solution.
What?
Why?
Find x such that or Find x such that
When?
Example:
Given: , Find x such that y = 0
analytical solution: ==> no need for
Given: , Find x such that y = 0
No idea? Good, a prime candidate for a numerical solution
We will consider several methods, each does the following in some way:
The user will decide what is ‘close enough’ (how big the error can be before we can stop looking)
x
y
x 1 first guess
error (y distance from 0)
b a
search in the range [a,b] for a root
x
y
x 2 next guess
new error (y distance from 0)
b a
Start with an initial range that contains the root, and subdivided it into several smaller sub-ranges.
Look inside each sub-range one by one for the root. When the sub-range containing the root is identi- fied, choose either end of the range as the guess.
Evaluate the error in your guess. If error is too big, subdivide your new range into smaller sub-ranges.
Loop back to step 1) and continue the loop until the error in step 3) is small enough
Take a moment, work out a way to identify the new smaller subrange.
a 1
b 1
a 2
b
start looking in range [a 1 , b 1 ] segment into 4 pieces (we picked 4 out of thin air)
look in each subrange until [a 2 , b2] is found
Now divide [a 2 , b2] into 4 segments and look again
evaluate the error err = minimum ( | f(a 2 ) |, | f(b 2 ) | )
subrange subrange
subrange
subrange
a 2
b a 3
b 3
look in each subrange until [a 3 , b3] is found evaluate the error err = minimum ( | f(a 3 ) |, | f(b 3 ) | )
subrange subrange
subrange
subrange
Now divide [a 3 , b3] into 4 segments and look again ...
Start with an initial range [a, b], and cut the range in half, assume this half point m is the root
Evaluate the error err = | f(m) |.
If error is too big, decide if the root is to the left or right of [m].
Three Bisection iterations
Same as the incremental search:
prod = f(a) * f(m)
if prod < 0, root is to the left
otherwise root is to the right
err > tol - yes?
evaluate the error err = | f(m) |
make new range: root is to left of m ===> a = a, b = m root is to right of m ==> a = m, b = b divide new [a , b] in half to get new m evaluate the error err = | f(m) | (^) ....etc.
a
m1 b
f(m1)
iteration 1
b m
f(m2)
a
iteration 2
a
m3 b
f(m3)
iteration 3
b stays, a moves over from left
error at m1 too big, so guess again
error at m2 too big, so guess again
first guess c - intersection of a line from f(a) to f(b) with x-axis
(from similar triangles)
If error is too big, decide if the root is to the left or right of [c]. for f(a) * f(c) < 0, reassign a new range a = a, b = c for f(a) * f(c) > 0, reassign a new range a = c, b = b
new guess
b
a
f(a)
f(b)
it seems more likely that the root would be closer to a than b, and not in the middle
Given the heights of f(a) vs. f(b)
Let’s use this concept in an algorithm
this is from the definition of slope
xk x
solve for x (^) k+
Let’s continue with a few more iterations
Another example, 2 iterations in one figure
x 1 x first guess
error (y distance from 0)
tangent to f(x 1 ) second guess x 2
f(x 2 )
tangent to f(x 2 )
second guess x (^2)
f(x 2 )
x (^3)
x (^2)
f(x 3 )
x 3
x
x
f(x1)
slope = f’(x1)
x
f(x2)
slope = f’(x2)
x