NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

###
There are no special functions in this program. It is a strict linear process. However, we will do a lot of repeated loops. This is our first venture into two dimensional arrays.

Remember to use strings to and "write" what is happening on screen when you test the variables are working correctly.

The first thing you need is the size of the n x n matrix. You will ask the user for 'n' and also set m to 'n'. You need both counters as you will be using nexted for loops (unique counter for each loop)
###

await readnum 'Please enter the size of your n x n matrix', defer n
m = n
###
M = [] is the code for an empty 'list'. That is all an array is. A list of numbers, characters or strings. Create an empty list now. NOTE: computers start counting from ZERO not ONE. If you say your list has 3 elements, that is 0, 1, 2 not 1, 2, 3
###
M = []
###
Ask the user to input the values of the coefficients and the constant for each linear equation in the system.
To do this you need a nested for loop. You are inputing each equation (row), one coefficient/constant (column) as a time. As we are entering the constant now, the column count is 1 more than the row.

###
for row in [0...m]
R = []
#Each row is originally another 'Empty List'
for clmn in [0...n+1]
if clmn < n #entering coefficients
await readnum 'What is the ' + (clmn+1) + ' term of row ' + (row + 1), defer R[clmn]
else #enter the constant
await readnum 'What is the constant of row ' + (row + 1), defer R[clmn]
M[row]=R #sets the 'row' list as the Rth element in M
ct()
#write the original matrix so you can see it.
for row in [0...m]
write M[row]
###
Proceed to write code to emulate The Elementary Row Operations Start by creating the Lower Triangle Zeros. Use a new counter that checks rows and columns. I use j for rows and k for columns
###
for j in [0...n]
clmn = j #reset clmn to start of current row
for row in [0...m]
if row is j
k=j
#first thing, we want to divide by the diagonal element
#to divide out the element and make it 1
div = M[row][row]
else if row > j
k=row-j
#Once the current row as a 1 for the diagonal element
#we need to know that the other lead element is to
#multiply by it
mult = M[row][row-k]
for clmn in [0...n+1]
#now we get to work

if row is j
M[row][clmn]=M[row][clmn]/div
else if row > j
M[row][clmn]=M[row][clmn]-mult*M[row-k][clmn]
write '-----------'
write 'Here is the matrix with the lower triangle zeros.'
for row in [0...m]
write M[row]
i=0
#Upper Triangle Zeros
for k in [n...1] #reset K to start at last clmn
i+=1
for row in [m-1...0] #start at row - 1
if (row-i) >= 0
mult = M[(row-i)][(k-1)]
for clmn in [0...n+1]
M[(row-i)][clmn]=M[(row-i)][clmn]-mult*M[(k-1)][clmn]
write '-----------'
write 'Here is the matrix with the upper triangle zeros.'
for row in [0...m]
write M[row]
S = []
###
rounding used to eliminate rounding
errors caused by division and decimals
###
for row in [0...m]
S[row] = (round((M[row][n])*100))/100
write '-----------'
write 'The solution to your system of equations is:'
write '(' + S + ')'

     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.