Juggler_IN
Active Member
- Joined
- Nov 19, 2014
- Messages
- 349
- Office Version
- 2003 or older
- Platform
- Windows
I want a function to accept a polynomial string and return either an ascending or descending order sort of the polynomial terms.
For example, if the input is 87x^1+7x^5-55x^3+22x^4-94x^2-56 the expected output in descending order of the terms is 7x^5+22x^4-55x^3-94x^2+87x^1-56.
How do I sort the terms array basis the exponents of the terms?
For example, if the input is 87x^1+7x^5-55x^3+22x^4-94x^2-56 the expected output in descending order of the terms is 7x^5+22x^4-55x^3-94x^2+87x^1-56.
How do I sort the terms array basis the exponents of the terms?
VBA Code:
Public Function StdPoly( _
p As String) As String
Dim q() As String, i As Integer
While InStr(p, " ") > 0&
p = Replace(p, " ", "")
Wend
p = Replace(p, "+", " +")
p = Replace(p, "-", " -")
Debug.Print p
q = Split(p, " ")
For i = LBound(q) To UBound(q)
Debug.Print i, q(i)
Next i
StdPoly = q(0)
End Function