Using Visual Basic for Equation Solving by Iteration - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

Using Visual Basic for Equation Solving by Iteration

Description:

Make calculations. Call Subroutinename(b1, b2, b3, ..., bn) ... Make calculations based on the arguments passed to subroutine. End Sub. How to Solve by Iteration ... – PowerPoint PPT presentation

Number of Views:206
Avg rating:3.0/5.0
Slides: 10
Provided by: ysu
Category:

less

Transcript and Presenter's Notes

Title: Using Visual Basic for Equation Solving by Iteration


1
Using Visual Basic for Equation Solving by
Iteration
  • Introducing the Subroutine

2
If, Then, Else Statement
If(a lt b) If a is less than b If(a b) If a
equals b If(altgtb) If a is not equal to
b If(altb) If a is less than or equal to
b If(agtb) If a is greater than or equal to
b If(agtb) Then If a is greater than b do
these statements ElseIf (ab) Then If a is
equal to b do these statements Else a is
neither greater do these statements than nor
equal to b End if
3
The Subroutine
Public Function Functionname(arguments) Make
calculations Call Subroutinename(b1, b2, b3, ,
bn) Functionnname some number End
Function Public Sub Subroutinename(a1, a2, a3,
,an) Make calculations based on the arguments
passed to subroutine End Sub
4
How to Solve by Iteration
5
Newton-Raphson Iteration
6
Central Difference Method to Estimate the
Derivative
7
Calculating the Relative Error
8
Continue to iterate until relerror is within some
specified tolerance or until the number of
iterations exceed some predetermined limit.
9
Public tiny Public Function NewtonRaphson(argumen
ts, xguess, tolerance, iter) x xguess tiny
1E-20 For i1 to iter Call func(arguments,x,
fx) Call deriv(arguments, x, dfdx, tiny) xnew
x fx/dfdx relerror abs(xnew - x)/(x
tiny) If(relerror lt tolerance) Then Exit
For Else x xnew Endif Next i NewtonRaphson
xnew End Function Public Sub func(arguments, x,
fx) Insert function here End Sub Public Sub
deriv(arguments, x, dfdx) Call func(arguments,
1.01(x tiny), fhigh) Call func(arguments,
0.99(x tiny), flow) dfdx (fhigh-flow)/(20.01
(x tiny)) End Sub
Write a Comment
User Comments (0)
About PowerShow.com