Main

The [[https://apmonitor.com|APMonitor Modeling Language]] is optimization software for mixed-integer and differential algebraic equations. It is coupled with large-scale solvers for linear, quadratic, nonlinear, and mixed integer programming (LP, QP, NLP, MILP, MINLP). Modes of operation include data reconciliation, real-time optimization, dynamic simulation, and nonlinear predictive control. It is freely available through MATLAB, Python, Julia, or from a [[http://apmonitor.com/online/view_pass.php|web browser interface]].
~~ ~~F = empty((3))

~~ ~~F[0] = pow(x,2)+pow(y,2)-20

~~ ~~F[1] = y - pow(x,2)

~~ ~~F[2] = w + 5 - x*y

~~ ~~return F

~~ ~~zGuess = array([1,1,1])

~~ ~~z = fsolve(myFunction,zGuess)

~~ ~~print(z)

## Solve Equations in Python

## Main.PythonSolveEquations History

Hide minor edits - Show changes to output

Changed line 61 from:

The [[https://apmonitor.com|APMonitor Modeling Language]] is optimization software for mixed-integer and differential algebraic equations. It is coupled with large-scale solvers for linear, quadratic, nonlinear, and mixed integer programming (LP, QP, NLP, MILP, MINLP). Modes of operation include data reconciliation, real-time optimization, dynamic simulation, and nonlinear predictive control. It is freely available through MATLAB, Python, Julia, or from a [[http://apmonitor.com/online/view_pass.php|web browser interface]].

to:

The [[https://apmonitor.com|APMonitor Modeling Language]] with a Python interface is optimization software for mixed-integer and differential algebraic equations. It is coupled with large-scale solvers for linear, quadratic, nonlinear, and mixed integer programming (LP, QP, NLP, MILP, MINLP). Modes of operation include data reconciliation, real-time optimization, dynamic simulation, and nonlinear predictive control. It is freely available through MATLAB, Python, Julia, or from a [[http://apmonitor.com/online/view_pass.php|web browser interface]].

Added lines 60-61:

The [[https://apmonitor.com|APMonitor Modeling Language]] is optimization software for mixed-integer and differential algebraic equations. It is coupled with large-scale solvers for linear, quadratic, nonlinear, and mixed integer programming (LP, QP, NLP, MILP, MINLP). Modes of operation include data reconciliation, real-time optimization, dynamic simulation, and nonlinear predictive control. It is freely available through MATLAB, Python, Julia, or from a [[http://apmonitor.com/online/view_pass.php|web browser interface]].

Changed lines 15-26 from:

import numpy as np

~~ ~~A = np.array([ [3,-9], [2,4] ])

~~ ~~b = np.array([-42,2])

~~ ~~z = np.linalg.solve(A,b)

~~ ~~print(z)

~~ ~~M = np.array([ [1,-2,-1], [2,2,-1], [-1,-1,2] ])

~~ ~~c = np.array([6,1,1])

~~ ~~y = np.linalg.solve(M,c)

~~ ~~print(y)

to:

(:source lang=python:)

import numpy as np

A = np.array([ [3,-9], [2,4] ])

b = np.array([-42,2])

z = np.linalg.solve(A,b)

print(z)

M = np.array([ [1,-2,-1], [2,2,-1], [-1,-1,2] ])

c = np.array([6,1,1])

y = np.linalg.solve(M,c)

print(y)

(:sourceend:)

import numpy as np

A = np.array([ [3,-9], [2,4] ])

b = np.array([-42,2])

z = np.linalg.solve(A,b)

print(z)

M = np.array([ [1,-2,-1], [2,2,-1], [-1,-1,2] ])

c = np.array([6,1,1])

y = np.linalg.solve(M,c)

print(y)

(:sourceend:)

Changed lines 37-43 from:

from numpy import *

~~ ~~from scipy.optimize import *

~~ ~~def myFunction(z):

~~ ~~x = z[0]

~~ ~~y = z[1]

~~ ~~ w = z[2]

to:

(:source lang=python:)

from numpy import *

from scipy.optimize import *

def myFunction(z):

x = z[0]

y = z[1]

w = z[2]

from numpy import *

from scipy.optimize import *

def myFunction(z):

x = z[0]

y = z[1]

w = z[2]

Changed lines 46-54 from:

to:

F = empty((3))

F[0] = pow(x,2)+pow(y,2)-20

F[1] = y - pow(x,2)

F[2] = w + 5 - x*y

return F

zGuess = array([1,1,1])

z = fsolve(myFunction,zGuess)

print(z)

(:sourceend:)

F[0] = pow(x,2)+pow(y,2)-20

F[1] = y - pow(x,2)

F[2] = w + 5 - x*y

return F

zGuess = array([1,1,1])

z = fsolve(myFunction,zGuess)

print(z)

(:sourceend:)

Changed line 55 from:

Linear and nonlinear equations can also be solved with [[Main/ExcelSolveEquations|Excel]] and [[Main/~~PythonSolveEquations~~|~~Python~~]]. Click on the appropriate link for additional information and source code.

to:

Linear and nonlinear equations can also be solved with [[Main/ExcelSolveEquations|Excel]] and [[Main/MatlabSolveEquations|MATLAB]]. Click on the appropriate link for additional information and source code.

Changed line 17 from:

A = np.array([[3,-9],[2,4]])

to:

A = np.array([ [3,-9], [2,4] ])

Changed line 22 from:

M = np.array([[1,-2,-1],[2,2,-1],[-1,-1,2]])

to:

M = np.array([ [1,-2,-1], [2,2,-1], [-1,-1,2] ])

Added lines 13-26:

!!!!Source Code for Linear Solutions

import numpy as np

A = np.array([[3,-9],[2,4]])

b = np.array([-42,2])

z = np.linalg.solve(A,b)

print(z)

M = np.array([[1,-2,-1],[2,2,-1],[-1,-1,2]])

c = np.array([6,1,1])

y = np.linalg.solve(M,c)

print(y)

import numpy as np

A = np.array([[3,-9],[2,4]])

b = np.array([-42,2])

z = np.linalg.solve(A,b)

print(z)

M = np.array([[1,-2,-1],[2,2,-1],[-1,-1,2]])

c = np.array([6,1,1])

y = np.linalg.solve(M,c)

print(y)

Changed line 33 from:

!!!!Source ~~Code~~

to:

!!!!Source Code for Nonlinear Solution

Added lines 1-60:

(:title Solve Equations in Python:)

(:keywords Python, solve equations, linear, nonlinear:)

(:description Python tutorial on solving linear and nonlinear equations with matrix operations (linear) or fsolve NumPy(nonlinear):)

The following tutorials are an introduction to solving linear and nonlinear equations with Python. The solution to linear equations is through matrix operations while sets of nonlinear equations require a solver to numerically find a solution.

!!!!Solve Linear Equations with Python

(:html:)

<iframe width="560" height="315" src="https://www.youtube.com/embed/44pAWI7v5Zk" frameborder="0" allowfullscreen></iframe>

(:htmlend:)

!!!!Solve Nonlinear Equations with Python

(:html:)

<iframe width="560" height="315" src="https://www.youtube.com/embed/S4Qg2CsiIj8" frameborder="0" allowfullscreen></iframe>

(:htmlend:)

!!!!Source Code

from numpy import *

from scipy.optimize import *

def myFunction(z):

x = z[0]

y = z[1]

w = z[2]

F = empty((3))

F[0] = pow(x,2)+pow(y,2)-20

F[1] = y - pow(x,2)

F[2] = w + 5 - x*y

return F

zGuess = array([1,1,1])

z = fsolve(myFunction,zGuess)

print(z)

!!!!Additional Tutorials

Linear and nonlinear equations can also be solved with [[Main/ExcelSolveEquations|Excel]] and [[Main/PythonSolveEquations|Python]]. Click on the appropriate link for additional information and source code.

----

(:html:)

<div id="disqus_thread"></div>

<script type="text/javascript">

/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */

var disqus_shortname = 'apmonitor'; // required: replace example with your forum shortname

/* * * DON'T EDIT BELOW THIS LINE * * */

(function() {

var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;

dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';

(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);

})();

</script>

<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>

<a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>

(:htmlend:)

(:keywords Python, solve equations, linear, nonlinear:)

(:description Python tutorial on solving linear and nonlinear equations with matrix operations (linear) or fsolve NumPy(nonlinear):)

The following tutorials are an introduction to solving linear and nonlinear equations with Python. The solution to linear equations is through matrix operations while sets of nonlinear equations require a solver to numerically find a solution.

!!!!Solve Linear Equations with Python

(:html:)

<iframe width="560" height="315" src="https://www.youtube.com/embed/44pAWI7v5Zk" frameborder="0" allowfullscreen></iframe>

(:htmlend:)

!!!!Solve Nonlinear Equations with Python

(:html:)

<iframe width="560" height="315" src="https://www.youtube.com/embed/S4Qg2CsiIj8" frameborder="0" allowfullscreen></iframe>

(:htmlend:)

!!!!Source Code

from numpy import *

from scipy.optimize import *

def myFunction(z):

x = z[0]

y = z[1]

w = z[2]

F = empty((3))

F[0] = pow(x,2)+pow(y,2)-20

F[1] = y - pow(x,2)

F[2] = w + 5 - x*y

return F

zGuess = array([1,1,1])

z = fsolve(myFunction,zGuess)

print(z)

!!!!Additional Tutorials

Linear and nonlinear equations can also be solved with [[Main/ExcelSolveEquations|Excel]] and [[Main/PythonSolveEquations|Python]]. Click on the appropriate link for additional information and source code.

----

(:html:)

<div id="disqus_thread"></div>

<script type="text/javascript">

/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */

var disqus_shortname = 'apmonitor'; // required: replace example with your forum shortname

/* * * DON'T EDIT BELOW THIS LINE * * */

(function() {

var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;

dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';

(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);

})();

</script>

<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>

<a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>

(:htmlend:)