Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X
I was a bit surprised to see that root would even return non-real results with real guesses.
Here are my 2 Cents, using random non-real guesses.
y runs from -50. Indices have to start from ORIGIN.
Stuart
Ok, but still one solution is missing:
The second imaginary solution:
I don't know why this solution it is not catched/found it...
Try polyroots. root's algorithm (without a search range) doesn't cover all complex results).
Stuart
I understand. Also, I can use solve command and received all 3 solutions.
But I want to understand why in the way as I shown above (with x as a range, and with root function), this way does not find the second imaginary solution as I should be the case.
I enjoy conversations where messages cross each other—so much more fun than a strictly linear thread. 😊
You'd have to dig into the code to understand why Ridder's (or Brent's) algorithm returns one complex root and not the other. It would help if one could specify a complex range. Perhaps somebody could write a wrapper function around f(x) that allows root to stray further into the complex plane. Alternatively, somebody could write a new root function. I've got vague memories of rolling my own Levenberg–Marquardt solver to better understand what it did.
Stuart
I found a way:
But thanks for this hint. In this way we can use Unique function also when range variable is negative.
Yes, Mathcad doesn't care what the minimum value of the range variable you used was, as long as you ensure that all indices are equal to or greater than (current) ORIGIN.
Stuart
I like it. If it doesn't work first time, hit it with a bigger hammer! 🙂
However, when I changed x to match your new values in my download of your worksheet, Unique gave a different result.
I used one of my versions of the function set (which does the same sort of thing as Unique). That gave a better result ... stepping x by 10 gives a lot of (default) zeros. I wrote out UniqueP from Tetsuro's original post, which gave the same result as yours. I wonder what's going on?
Stuart
Be aware that in the first post when I uploaded my mathcad prime sheet I had 0 for the second element. I changed to 1, to skip the first 0. Only that I modified (0 -> 1) from the uploaded file.
OK.
The mystery is solved. The -1s in Unique's result aren't all -1s. Showing a few more decimal places shows that beating root into submission with a heavy integer hammer gives more than just the three expected roots.
So Unique and my set0 are looking for strict numerical equality, whereas my set2 only looks for approximate equality as determined by the system variable TOL.
Stuart
Just some random thoughts, particularly concerning the skipped elements in A that are set to 0 by default.
There are other methods of dealing with this issue, but I like to use functions to convert between data types, so ...
Stuart
Mathcad Prime 10 file attached.
As to why, ...
Mathcad Help:
I was a bit surprised to see that root would even return non-real results with real guesses.
Here are my 2 Cents, using random non-real guesses.
Now that's interesting. When I tried that, Mathcad squawked like a parrot on a sugar high. "No, take that nasty complexity out right now! Honestly, some people. Pieces of Eight. Who's a pretty CAS. The horror, The horror ...".
The local definition I used above arose from such an attempt. However, with freshly typed expressions this time, the parrot was rather quiet.
Reducing the range over which root searched gave better (for values of "better") results.
I blame any typos, logical errors and programming mistakes on it being Oh Dark O'Clock and sleep deprivation taking its toll.
Stuart
@Cornel wrote:
Some button jabbing sessions weren't converging at all with small nz. At first, I thought I broken something because I wasn't seeing any results or was only getting one result. So, I modified my smart monkey program to trap convergence errors and increased nz.
Stuart
I felt deeply unsatisfied looking at that image and realized it needed a good sorting. Unfortunately, Mathcad's standard sort algorithm doesn't sort complex numbers in a satisfactory order - it sorts on the Re element only; the Im order is somewhat arbitrary.
So, I dug up one of my old Mathcad 15 mergesort worksheets and reworked it to sort on Re then Im. Csort(A,clist) sorts array A using the column order specified in clist. zsort(A) sorts the elements of array A in ascending order, retaining A's shape.
Sorting the symbolic solver's roots and the numerical solver's roots allows for an easier comparison of the different sets of solutions.
Stuart
zmrunif = z m r unif = complex matrix random uniform
zmrunif(m,n,a,b) : return matrix of size m rows by n columns with random numbers spanning the range a to b, where a and b are possibly complex.