Kelvin's Octave Assignment: Difference between revisions

From Class Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
==Solve Linear System of EQ's with Octave==
==Solve Linear System of EQ's with Octave==


This will solve and print solutions for the equations:
x = A\b solves the equation ''A'''''x'''='''b'''


'''<math>1 \times x1+2 \times x2+3 \times x3=1</math>'''
For example, this will solve and print solutions for the equations:


'''<math>4 \times x1+5 \times x2+6 \times x3=2</math>'''
'''<math>1 \times x1+2 \times x2+3 \times x3=55</math>'''


'''<math>7 \times x1+8 \times x2+9 \times x3=3</math>'''
'''<math>4 \times x1+5 \times x2+6 \times x3=20</math>'''
 
'''<math>7 \times x1+8 \times x2+9 \times x3=42</math>'''




Line 15: Line 17:
     4,5,6
     4,5,6
     7,8,9];
     7,8,9];
  b=[1
  b=[55
     2
     20
     3];
     42];
  result = A\b;
  result = A\b;
  x1=result(1)
  x1=result(1)
  x2=result(2)
  x2=result(2)
  x3=result(3)
  x3=result(3)

Latest revision as of 21:45, 3 October 2010

Solve Linear System of EQ's with Octave

x = A\b solves the equation Ax=b

For example, this will solve and print solutions for the equations:

1×x1+2×x2+3×x3=55

4×x1+5×x2+6×x3=20

7×x1+8×x2+9×x3=42


clear all
close all
A=[1,2,3
   4,5,6
   7,8,9];
b=[55
   20
   42];
result = A\b;
x1=result(1)
x2=result(2)
x3=result(3)