115-09-HW3 - Call GetRange(rng3, "Enter n by 1 output...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
University of California, Davis Department of Applied Science Fall 2009 David M. Rocke Numerical Methods EAD 115 October 14, 2009 Homework Assignment 3 October 21, 2009 1. Do the following problems from the text: 6.3, 6.5, 6.6 on pages 171–172. 2. Do the following problems from the text: 9.8, 9.9 on page 272. 3. Write a program in a language of your choice to implement Naive Gaussian Elimination. Below is the framework for a VBA implementation (available for download on the web site). You may use this, or you may write the equivalent in another language. Option Explicit Sub Gauss() ’ Declarations Dim A() As Variant, b() As Variant, x() As Variant Dim nrows As Integer, ncols As Integer, n As Integer Dim rng1 As Range, rng2 As Range, rng3 As Range Dim i As Integer, j As Integer, k As Integer Dim factor As Double, sum As Double ’ Get input ranges, check for correct shape, and set arrays Call GetRange(rng1, "Enter n by n input range for matrix of coefficients") Call GetRange(rng2, "Enter n by 1 input range for RHS")
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Call GetRange(rng3, "Enter n by 1 output range for solution") ncols = rng1.Columns.Count nrows = rng1.Rows.Count If (nrows <> ncols) Then MsgBox "Matrix not square" Exit Sub End If n = nrows If ((rng2.Rows.Count <> n) Or (rng3.Rows.Count <> n) Or _ (rng2.Columns.Count <> 1) Or (rng3.Columns.Count <> 1)) Then MsgBox "RHS or output range not n by 1" Exit Sub End If A = rng1.Value b = rng2.Value x = b Elimination Back substitution rng3.Value = x End Sub Sub GetRange(rng As Range, msg As String) Dim srng As String srng = InputBox(msg) Set rng = Range(srng) End Sub 4. Use your program to solve the linear system Ax = b , where A = 1 1 / 2 1 / 3 1 / 4 1 / 5 1 / 2 1 / 3 1 / 4 1 / 5 1 / 6 1 / 3 1 / 4 1 / 5 1 / 6 1 / 7 1 / 4 1 / 5 1 / 6 1 / 7 1 / 8 1 / 5 1 / 6 1 / 7 1 / 8 1 / 9 and b = 2-4 3 7-1...
View Full Document

This note was uploaded on 01/20/2011 for the course ENG EAD 115 taught by Professor Rocke during the Spring '10 term at UC Davis.

Page1 / 2

115-09-HW3 - Call GetRange(rng3, "Enter n by 1 output...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online