https://handwiki.org/wiki/index.php?title=DMelt:Math/6_Equations&feed=atom&action=history DMelt:Math/6 Equations - Revision history 2022-09-29T05:04:59Z Revision history for this page on the wiki MediaWiki 1.35.1 https://handwiki.org/wiki/index.php?title=DMelt:Math/6_Equations&diff=170&oldid=prev imported>Jworkorg at 16:11, 14 February 2021 2021-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 &lt;javadoc&gt;jhplot.HLatexEq&lt;/javadoc&gt;. 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 /> &lt;jcode lang=&quot;python&quot;&gt;<br /> from jhplot import *<br /> eq=&quot;\int^{100}_{i=0} F(x) dx&quot; # use LaTeX syntax for this equation<br /> image=&quot;/tmp/equation.png&quot; # 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 &quot;Created :&quot;,image<br /> IView(image) # View the created PNG image <br /> &lt;/jcode&gt;<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 /> &lt;javadoc sc&gt;jhplot/math/Numeric|jhplot.math.Numeric&lt;/javadoc&gt; package. In general, only real solutions are considered.<br /> <br /> &lt;jcode lang=&quot;python&quot;&gt;<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 /> &lt;/jcode&gt;<br /> <br /> = Polynomial solving (symbolic)=<br /> <br /> For solving polynomial equations, one can use the symbolic calculation engine. <br /> <br /> &lt;jcode lang=&quot;python&quot;&gt;<br /> from jhplot.math import *<br /> from jhplot import *<br /> j=Symbolic(&quot;jscl&quot;) # using jscl engine<br /> j.expand(&quot;solve(c+b*x+a*x^2,x)&quot;) # answer: root(c, b, a)<br /> &lt;/jcode&gt;<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 /> &lt;pre&gt;<br /> x^2 + y^2 = 4<br /> x*y = 1<br /> &lt;/pre&gt;<br /> <br /> We use:<br /> <br /> &lt;jcode lang=&quot;python&quot;&gt;<br /> j.expand(&quot;groebner({x^2 + y^2 - 4, x*y - 1}, {x, y})&quot;)<br /> &lt;/jcode&gt;<br /> <br /> The returned output is:<br /> &lt;pre&gt;<br /> {1-4*x^2+x^4, 4*x-x^3-y}<br /> &lt;/pre&gt;<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 &quot;a = 4/5&quot; but &quot;5*a-4&quot; (&quot;= 0&quot; 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 /> &lt;pre&gt;<br /> 2x + 3y - 2z = 1<br /> x + 7y + 6x = -2<br /> 4x - 3y - 5z = 1<br /> &lt;/pre&gt;<br /> <br /> We will solve this using &lt;javadoc sc&gt;org.apache.commons.math3.linear.DecompositionSolver&lt;/javadoc&gt; package:<br /> <br /> &lt;jcode lang=&quot;python&quot;&gt;<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 &quot;Solution: x=&quot;,solution.getEntry(0), &quot;y=&quot;,solution.getEntry(1),&quot;z=&quot;,solution.getEntry(2)<br /> &lt;/jcode&gt;<br /> <br /> The execution of this code prints:<br /> <br /> &lt;pre&gt;<br /> Solution: x= -0.369863013699 y= 0.178082191781 z= -0.602739726027<br /> &lt;/pre&gt;<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 /> &lt;jnote&gt; under construction&lt;/jnote&gt;<br /> <br /> <br /> [[Category:Equations]]<br /> [[Category:Linear system of equations]]</div> imported>Jworkorg