Question: Use the following Visual Basic .NET code to generate the Excel spreadsheet for Part E of Problem Solving Exercise # 3. It is currently set
Use the following Visual Basic .NET code to generate the Excel spreadsheet for Part E of Problem Solving Exercise # 3. It is currently set up to generate the Excel 2016 spreadsheet for the Linear (1st order) fit. You will need to modify the code to generate the Excel 2016 spreadsheet for the 2nd order equation. NOTE: Before running the program, you must add a reference to the Microsoft Excel 16.0 Object Library. To do this, follow the menu sequence: Project | Add Reference | COM | Microsoft Excel 16.0 Object Library.
Imports Excel = Microsoft.Office.Interop.Excel
Public Class Form1
Private Sub btnExcel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExcel.Click
'------------------------------------------------------
'The Setup - always the same
Dim oXL As Excel.Application
Dim oWB As Excel.Workbook
Dim oSheet As Excel.Worksheet
oXL = New Excel.Application
oXL.Visible = True 'this makes it so they can see what's happening
oWB = oXL.Workbooks.Add
oSheet = oWB.ActiveSheet
'--------------------------------------------
'SOLVING MX = N
'now you have a sheet open
'ENTER MATRIX M
oSheet.Cells(2, "A") = "=8" 'row, column -- refers to cell A2
oSheet.Cells(3, "A") = "=255" 'row, column -- refers to cell A3
oSheet.Cells(2, "B") = "=255" 'row, column -- refers to cell B2
oSheet.Cells(3, "B") = "=9975" 'row, column -- refers to cell B3
'matrix has been entered in A2..B3
'ENTER MATRIX N
oSheet.Cells(2, "E") = "=317" 'row, column -- refers to cell E2
oSheet.Cells(3, "E") = "=11165" 'row, column -- refers to cell E3
'matrix has been entered in E2..E3
'now put the in the inverse command in a cell
'Since this has to be entered as an array formula
'follow the directions in MS Excel and use FormulaArray
oSheet.Range("A6", "B7").FormulaArray = "=MINVERSE(A2:B3)"
'the inverse for matrix M is there in A6:B7
'To solve MX = N, take X = (Minverse)N
'So Matrix is A6:B7 times E2:E3 and put answer in A10:A11
'This is also an array formula operation just like above
oSheet.Range("A10", "A11").FormulaArray = "=MMULT(A6:B7, E2:E3)"
'the solution matrix X is now in A10:A11
oWB.SaveAs("H:\EGR1400PS3E.xlsx")
oXL.Quit()
End Sub
End Class
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
