Biography
Research
Coverage
Reading Group
Publications
Projects
Events
SECON 2006
Links
Course Work
Personal
Octave
|
 |
 |
|
Jake Adriaens

Solving linear symbolic equations in Octave
The documentation for symlsolve() in the Octave-Forge symbols package wasn't great, so I had to figure this out by trial and error. I've documented an example here so others don't have to go through the same trouble. The example is taken from the GiNaC lsolve() documentation.
Suppose we want to solve the following set of equations:
ax+by=3
x-y=b
The following octave code should do the trick:
symbols %initialize the symbols package
a=sym("a"); %declare our symbols
b=sym("b");
x=sym("x");
y=sym("y");
eqns = {a*x+b*y==3, x-y==b}; %set the equations
vars = {x, y}; %set the variables we want to solve for
solution = symlsolve(eqns, vars); %solve the equations
x = solution{1} %print the results
y = solution{2}
This yields the result:
x =
a^(-1)*(a+b)^(-1)*((3.0)*a+a*b^2)
y =
-(-3.0+a*b)*(a+b)^(-1)
|
|
 |