https://handwiki.org/wiki/index.php?title=DMelt:Math/6_Equations&feed=atom&action=historyDMelt:Math/6 Equations - Revision history2024-03-28T20:57:29ZRevision history for this page on the wikiMediaWiki 1.38.4https://handwiki.org/wiki/index.php?title=DMelt:Math/6_Equations&diff=172&oldid=previmported>Jworkorg at 16:11, 14 February 20212021-02-14T16:11:45Z<p></p>
<p><b>New page</b></p><div><br />
<br />
{{sidebar box|[[DMelt:Start|Table of contents]]}}<br />
<br />
= Latex equations=<br />
[[Equation]] is a statement of an equality containing one or more variables.<br />
You can create PNG images with equations using the [[Software:LaTeX]] syntax using the class <javadoc>jhplot.HLatexEq</javadoc>. These images can be included on the web page or presentations.<br />
Here is a small code that shows how to make a PNG image <br />
<br />
<jcode lang="python"><br />
from jhplot import *<br />
eq="\int^{100}_{i=0} F(x) dx" # use LaTeX syntax for this equation<br />
image="/tmp/equation.png" # output file with PNG image of this equation<br />
q1=HLatexEq(eq, 32) # create PNG image from LaTeX using the font size 32 <br />
q1.export(image) # making the image<br />
print "Created :",image<br />
IView(image) # View the created PNG image <br />
</jcode><br />
<br />
= Solving equations=<br />
<br />
Numerous Java packages can be used to solve linear, non-linear and differential equations.<br />
<br />
= Solving linear, quadratic and cubic equations =<br />
To solve linear, quadratic and cubic equations, use the <br />
<javadoc sc>jhplot/math/Numeric|jhplot.math.Numeric</javadoc> package. In general, only real solutions are considered.<br />
<br />
<jcode lang="python"><br />
from jhplot.math.Numeric import *<br />
a=solveLinear(1,2) # solves ax+b=0. a=1, b=2<br />
print a<br />
b= solveQuadratic(1, 2, -1) # roots of the quadratic equation<br />
print b<br />
b= solveCubic(1, 2, 4,2)<br />
print b<br />
c=solveQuartic(1,-2, 3, 4, -2)<br />
print b<br />
</jcode><br />
<br />
= Polynomial solving (symbolic)=<br />
<br />
For solving polynomial equations, one can use the symbolic calculation engine. <br />
<br />
<jcode lang="python"><br />
from jhplot.math import *<br />
from jhplot import *<br />
j=Symbolic("jscl") # using jscl engine<br />
j.expand("solve(c+b*x+a*x^2,x)") # answer: root[0](c, b, a)<br />
</jcode><br />
<br />
<br />
= Algebraic equation systems =<br />
One solve algebraic equation systems of any degree, with several indeterminates, by computing the Groebner bases of polynomial ideals. For example, let this system for the indeterminates x, y:<br />
<br />
<pre><br />
x^2 + y^2 = 4<br />
x*y = 1<br />
</pre><br />
<br />
We use:<br />
<br />
<jcode lang="python"><br />
j.expand("groebner({x^2 + y^2 - 4, x*y - 1}, {x, y})")<br />
</jcode><br />
<br />
The returned output is:<br />
<pre><br />
{1-4*x^2+x^4, 4*x-x^3-y}<br />
</pre><br />
which allows to find x, then y from x. This operation doesn't calculate the roots, it just writes the equation. For example, it wouldn't give "a = 4/5" but "5*a-4" ("= 0" implied). Groebner basis computation is explained in more details below:<br />
<br />
= Solving linear systems =<br />
<br />
Consider a linear systems of equations of the form AX=B. For example, consider <br />
<pre><br />
2x + 3y - 2z = 1<br />
x + 7y + 6x = -2<br />
4x - 3y - 5z = 1<br />
</pre><br />
<br />
We will solve this using <javadoc sc>org.apache.commons.math3.linear.DecompositionSolver</javadoc> package:<br />
<br />
<jcode lang="python"><br />
from org.apache.commons.math3.linear import *<br />
<br />
# get the coefficient matrix A using LU decomposition<br />
coeff= Array2DRowRealMatrix([[2,3,-2],[-1,7,6],[4,-3,-5]])<br />
solver =LUDecompositionImpl(coeff).getSolver()<br />
# use solve(RealVector) to solve the system <br />
constants = ArrayRealVector([1, -2, 1 ])<br />
solution = solver.solve(constants);<br />
print "Solution: x=",solution.getEntry(0), "y=",solution.getEntry(1),"z=",solution.getEntry(2)<br />
</jcode><br />
<br />
The execution of this code prints:<br />
<br />
<pre><br />
Solution: x= -0.369863013699 y= 0.178082191781 z= -0.602739726027<br />
</pre><br />
<br />
Read more for different types of decomposition [http://commons.apache.org/math/userguide/linear.html here].<br />
Please read more in the [[DMelt:Numeric/1_Linear_Algebra|Linear Algebra]] section.<br />
<br />
= Solving non-linear systems =<br />
<br />
You can solve non-linear equations using the jMathLab symbolic kernel as explained in <br />
Section [[DMelt:JMathlab/Equations|JMathLab Equations]].<br />
<br />
= Solving differential equations =<br />
<jnote> under construction</jnote><br />
<br />
<br />
[[Category:Equations]]<br />
[[Category:Linear system of equations]]</div>imported>Jworkorg