Guest User

SolvePoly for ordrered roots

a guest
Jun 24th, 2026
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. Function SolvePoly(ParamArray CoeffA() As Variant)
  2.  
  3. Dim i As Long
  4. Dim PArray As Variant
  5. Dim Num_Coeff As Long
  6. Dim Degree As Long
  7. Dim Res As Variant
  8.  
  9. Num_Coeff = UBound(CoeffA) + 1
  10. Degree = Num_Coeff - 1
  11.  
  12. ReDim PArray(1 To Num_Coeff, 1 To 1)
  13.  
  14. For i = 0 To Num_Coeff - 1
  15. If IsNumeric(CoeffA(i)) Then
  16. PArray(i + 1, 1) = CoeffA(i)
  17. Else
  18. PArray(i + 1, 1) = CoeffA(i).Value2
  19. End If
  20. Next i
  21.  
  22. Select Case Num_Coeff
  23. Case Is < 3
  24. Res = "Num_Coeff must be >= 3"
  25.  
  26. Case Is < 4
  27. Res = Quadratic(PArray)
  28.  
  29. Case 4
  30. Res = CubicC(PArray)
  31.  
  32. Case 5
  33. Res = Quartic(PArray)
  34.  
  35. Case Else
  36. Res = RPolyJT(PArray)
  37. End Select
  38.  
  39. If IsArray(Res) Then
  40. Res = SortRootResult(Res, Degree, 0.0000000001)
  41. SolvePoly = WorksheetFunction.Transpose(Res)
  42. Else
  43. SolvePoly = Res
  44. End If
  45.  
  46. End Function
Advertisement
Add Comment
Please, Sign In to add comment