Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The function calculates the value of x (root) in a cubic equation of the form ax^3 + bx^2 + cx + d = 0, where a, b, c, and d are the coefficients specified as input to the function.

The result of the calculation will be the values of x (root) that satisfies the equation.

Example:

Code Block
languagexml
  ...
    <!-- example1 -->
    <P N="x1" V="cubic(5,10,1,3)" />
    <P N="x2" V="cubic(1,3,3,1)" />
    <P N="x3" V="cubic(1,3,3,1)[0]" />
...    
Image Added

The function solves a system of 3 linear equations with 3 unknowns and returns one of the solutions in the x3 parameter. The solution is selected by specifying which root you want to retrieve using square brackets, with the first root being represented by [0], the second by [1], and the third by [2]. The function will return the requested root as the result.

Code Block
languagexml
 ...
     <!-- example2: 24x^3 + 34x^2 -5x -3 = 0 -->
     <O N="C1" T="Group">
        <P N="a1" V="24" />
        <P N="b1" V="34" />
        <P N="c1" V="-5" />
        <P N="d1" V="-3" />
        <P N="root_ex1" V="cubic(a1,b1,c1,d1)" D="Solution for a cubic equation with real roots" />
    </O>
...    
Image Added
Code Block
languagexml
...
    <!-- example3: x^3 - 3x^2 + 7x + 75 = 0 -->
    <O N="C2" T="Group">
        <P N="a2" V="1" />
        <P N="b2" V="-3" />
        <P N="c2" V="7" />
        <P N="d2" V="75" />
        <P N="root_ex2" V="cubic(a2,b2,c2,d2)" D="Solution for a cubic equation with complex roots" />
    </O>
...    

To view this example in the library, see (https://openbrim.org/platform/?application=inc&author=ParamML_Examples_OpenBrIM+Platform&folder=Functions&obj=objidvt2corziomsxfuebw6jg3)