Polyroots, arrangement of solutions

Polyroots, arrangement of solutions - Сообщения

#1 Опубликовано: 11.03.2021 20:29:16
hanskl

hanskl

7 сообщений из 158 понравились пользователям.

Группа: User

Hi,

I have come across some problems while using polyroots. I am solving a cubic polynomial and I have a problem where polyroots rearranges the solutions when I make slight adjustments to the input.

How does polyroots arrange the solutions?

Best regards,
#2 Опубликовано: 12.03.2021 05:10:04
hanskl

hanskl

7 сообщений из 158 понравились пользователям.

Группа: User

Sorry, I forgot to upload.

Hope you can make sence of the attached sheet and the "problem" I am faced with.

Best regards,

cubic.sm (77 КиБ) скачан 55 раз(а).
#3 Опубликовано: 12.03.2021 13:03:02
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

Wrote

I have come across some problems while using polyroots. I am solving a cubic polynomial and I have a problem where polyroots rearranges the solutions when I make slight adjustments to the input.
How does polyroots arrange the solutions?


Work in progress ... hope it can be automated, be patient.
Jean

cubic.sm (106 КиБ) скачан 29 раз(а).

#4 Опубликовано: 12.03.2021 13:11:03
Alvaro Diaz Falconi

Alvaro Diaz Falconi

992 сообщений из 1674 понравились пользователям.

Группа: User

Wrote

Sorry, I forgot to upload.

Hope you can make sence of the attached sheet and the "problem" I am faced with.

Best regards,

cubic.sm (77 КиБ) скачан 55 раз(а).



Usually polynomial roots sorting can't be done, just because they are complex numbers in the general case, and you can't define an order relation there. But forcing to get only reals, you can use sort() or reverse(sort()). The same could be done with the solve code at the end of your document.

Clipboard01.jpg

Best regards.
Alvaro.
#5 Опубликовано: 12.03.2021 15:29:52
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

... the project is now automated except as explained in green.
That inconvenience was not solved in Mathcad either.
Up to you to sanity at sol_1, sol_2 if they follow upstream
parameters and so on ... [you are the Expert in what I'm not].
Please, come back for more or better presentation.
Cheers ... Jean

cubic Polyroots Automated.sm (94 КиБ) скачан 44 раз(а).
#6 Опубликовано: 12.03.2021 16:40:59
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

... as long as sol_1 will have missing term 'x',
easy to force Polyroots to complete full automated project.

cubic Polyroots Automated.sm (96 КиБ) скачан 28 раз(а).
#7 Опубликовано: 12.03.2021 17:04:55
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

Wrote

... as long as sol_1 will have missing term 'x',
easy to force Polyroots to complete full automated project.


... slight refresh ... Golden ratio added.

cubic Polyroots Automated.sm (108 КиБ) скачан 34 раз(а).
#8 Опубликовано: 12.03.2021 17:25:50
hanskl

hanskl

7 сообщений из 158 понравились пользователям.

Группа: User

Wrote



Usually polynomial roots sorting can't be done, just because they are complex numbers in the general case, and you can't define an order relation there. But forcing to get only reals, you can use sort() or reverse(sort()). The same could be done with the solve code at the end of your document.

Clipboard01.jpg

Best regards.
Alvaro.



Alvaro,

Thank you. Did not think about sort(), that would do the trick.

Is it possible to extract solution(s) from the vector that satisfies 0≤x≤L?

Best regards,
#9 Опубликовано: 12.03.2021 17:32:15
hanskl

hanskl

7 сообщений из 158 понравились пользователям.

Группа: User

Wrote

... the project is now automated except as explained in green.
That inconvenience was not solved in Mathcad either.
Up to you to sanity at sol_1, sol_2 if they follow upstream
parameters and so on ... [you are the Expert in what I'm not].
Please, come back for more or better presentation.
Cheers ... Jean

cubic Polyroots Automated.sm (94 КиБ) скачан 44 раз(а).



Jean,

Thank you for the input. I dont have the Maple Tools plugin, so I cant see all the results from your sheet.

Alvaro's suggestion to use sort() helps me "hardcode" the desired solution, but I didnt quite understand why polyroots() doesnt sort its solutions. Any insight on that matter?

Best regards
#10 Опубликовано: 12.03.2021 20:45:22
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

Wrote

Thank you for the input. I dont have the Maple Tools plugin, so I cant see all the results from your sheet.

Alvaro's suggestion to use sort() helps me "hardcode" the desired solution, but I didn't quite understand why polyroots() doesn't sort its solutions. Any insight on that matter?


In your project, Polyroots does nothing except allowing export the solutions.
Which solutions [sol_1(x), sol_2(x)] conclude your design inputs.
Smath w/o Maple is not intended Smath.
Some advanced projects resume w/o Maple.
Attached for checking down to Golden ratio.

cubic Polyroots REMOVED.sm (86 КиБ) скачан 33 раз(а).
#11 Опубликовано: 12.03.2021 22:23:02
Alvaro Diaz Falconi

Alvaro Diaz Falconi

992 сообщений из 1674 понравились пользователям.

Группа: User

Wrote


...
Is it possible to extract solution(s) from the vector that satisfies 0≤x≤L?



Hi. Sure. For instance can use a for loop, like in the attached.

Clipboard01.jpg

cubic.sm (82 КиБ) скачан 21 раз(а).

Wrote


...
but I didn't quite understand why polyroots() doesn't sort its solutions. Any insight on that matter?



The problem is that the complexes cannot be ordered, so there is no standard about how to present the results.

However, since the roots of a polynomial are usually calculated as the eigenvalues of the companion matrix, and numerical procedures usually order these eigenvalues according to their magnitude, which is a real number, since it does have applications to keep the large eigenvalues and neglect the small ones, perhaps that is the order in which the roots appear in polyroots (): ordered by their complex magnitude, but I can't be sure, since I don't know the SMath routine for its calculation.

Best regards.
Alvaro.
#12 Опубликовано: 13.03.2021 12:01:12
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

Wrote

I didnt quite understand why polyroots() doesnt sort its solutions. Any insight on that matter?


Polyroots obey the rules from libraries [maybe Smath is NAG ?]
It is incomplete as it can not calculate complex vector.
Visit Samples just posted for your tool box.
I guess Norway not yet green like here !
Take care ... Jean

#13 Опубликовано: 13.03.2021 14:56:41
hanskl

hanskl

7 сообщений из 158 понравились пользователям.

Группа: User

Wrote


Polyroots obey the rules from libraries [maybe Smath is NAG ?]
It is incomplete as it can not calculate complex vector.
Visit Samples just posted for your tool box.
I guess Norway not yet green like here !
Take care ... Jean



Jean,
Sometimes I feel like you are talking over my head and overestimate my level of understanding the maths involved in my (structural engineering) projects. I guess thats partly why I like this forum, no matter what thread I read I feel like there’s new things to learn.

The winter is still going strong over here, at least when you get some distance to the coast and fjords. We had a wonderful day skiing today.

Best regards,
#14 Опубликовано: 13.03.2021 15:13:36
hanskl

hanskl

7 сообщений из 158 понравились пользователям.

Группа: User

Wrote

Wrote

Thank you for the input. I dont have the Maple Tools plugin, so I cant see all the results from your sheet.

Alvaro's suggestion to use sort() helps me "hardcode" the desired solution, but I didn't quite understand why polyroots() doesn't sort its solutions. Any insight on that matter?


In your project, Polyroots does nothing except allowing export the solutions.
Which solutions [sol_1(x), sol_2(x)] conclude your design inputs.
Smath w/o Maple is not intended Smath.
Some advanced projects resume w/o Maple.
Attached for checking down to Golden ratio.

cubic Polyroots REMOVED.sm (86 КиБ) скачан 33 раз(а).



Jean,

Very interesting example searching for max/min.
In my project, I am searcing for max/min of the function w(x), by finding the roots of it's first derivative θ(x).

Best regards,
#15 Опубликовано: 13.03.2021 15:24:41
hanskl

hanskl

7 сообщений из 158 понравились пользователям.

Группа: User

Wrote

The problem is that the complexes cannot be ordered, so there is no standard about how to present the results.

However, since the roots of a polynomial are usually calculated as the eigenvalues of the companion matrix, and numerical procedures usually order these eigenvalues according to their magnitude, which is a real number, since it does have applications to keep the large eigenvalues and neglect the small ones, perhaps that is the order in which the roots appear in polyroots (): ordered by their complex magnitude, but I can't be sure, since I don't know the SMath routine for its calculation.

Best regards.
Alvaro.



Alvaro,

Thank you for the beatiful way of filtering out the relevant roots. I have some questions.
1. Why do you use length(R) rather than rows(R) to determine the upper limit of the range?
2. Is abs(Im(el(R,k)))<10^{-12} the only way of determining if a number is non-complex ie. has no imaginary part (I dont know the correct term for such a number, or is it Reals?)
3. Would you trust polyroots() over someting like the cubic solver in the attached sheet? I want to use code that finds the solutions symbolically rather than numerically.
4. I should probably define a function that finds the roots of a polynomial that are within a range if I want to to this several times within the same sheet?

Best regards,

cubicroots.sm (9 КиБ) скачан 35 раз(а).
cubicroots.PNG
#16 Опубликовано: 13.03.2021 19:41:40
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

Wrote

3. Would you trust polyroots() over something like the cubic solver in the attached sheet? I want to use code that finds the solutions symbolically rather than numerically.
4. I should probably define a function that finds the roots of a polynomial that are within a range if I want to to this several times within the same sheet?


3. Your cubic is incorrect vs the conventional attached and Polyroots.
4. That's another story but can be done from scanning trough the various
vectors you want to explore. Possibly plot/stack all explorations.
More and + interesting ... Jean

cubicroots [sanity check].sm (37 КиБ) скачан 41 раз(а).

#17 Опубликовано: 13.03.2021 20:38:14
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

... here is a brute force plot scanner/explorer
Design the 'a' vectors at will for best expected.
Cheers ... Jean

cubicroots [Brute Force Scanner].sm (21 КиБ) скачан 39 раз(а).
#18 Опубликовано: 13.03.2021 23:26:52
Alvaro Diaz Falconi

Alvaro Diaz Falconi

992 сообщений из 1674 понравились пользователям.

Группа: User

Wrote


1. Why do you use length(R) rather than rows(R) to determine the upper limit of the range?
2. Is abs(Im(el(R,k)))<10^{-12} the only way of determining if a number is non-complex ie. has no imaginary part (I dont know the correct term for such a number, or is it Reals?)
3. Would you trust polyroots() over someting like the cubic solver in the attached sheet? I want to use code that finds the solutions symbolically rather than numerically.
4. I should probably define a function that finds the roots of a polynomial that are within a range if I want to to this several times within the same sheet?



1. True Vectors are column vectors, the expression "row vector" actually means nothing. But ... columns don't look good. Using length() instead rows() I can use row or column vectors in my procedures.

2. No, it isn't. But routines in polyroots() usually introduce some imaginary parts in roots because roundoff errors evaluating the discriminant of the polynomial equation. The question Im(R.k)=0 could look better, but for numerical methods it's impractical.

3. I don't know the internals of SMath polyroots(), but I'm pretty sure that can't handle symbolic values. And I'm pretty sure also that an application in civil engineering with symbolic expressions for cubic polynomials roots requires a very powerful symbolic kernel, and SMath isn't at that stage right now.

4. Sure, first use your cubic, which works well and it's equivalent to polyroots(reverse(stack(a,b,c,d)) and then define another for take only roots in the desired interval. Notice that in my procedure I assign x.4[n:=n+1] to R[k] but it's more correct assign to Re(R[k]).

Best regards.
Alvaro.
#19 Опубликовано: 14.03.2021 11:05:07
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

Wrote


3. Would you trust polyroots() over something like the cubic solver in the attached sheet? I want to use code that finds the solutions symbolically rather than numerically.
4. I should probably define a function that finds the roots of a polynomial that are within a range if I want to to this several times within the same sheet?


........................
2. The cubic module as constructed is same as polyroots with the nuance.
cubic takes the vector [3] ... polyroots takes [4]
The nuance is that if the last v[4 is not '1' then the plot is scaled
to that factor... otherwise: if v[4 is 1 same roots.
3. At this point of your project, you have reduced the long arguments
by sol_1(x), sol_2(x). At this next point, if you want either/both functions
to pass a cubic polynomial through, you define a set of 4 points that
make sense wrt the nature of your expectation, then solve for the coefficients of the cubic polynomial.
Doing so, no needs for cubic, neither polyroots
neither for symbolic of any kind, neither partial fraction expansion.
................
The attached linfit module does all that, no sweat/quick,
infinitely re-usable for each set of new experimental XY
What it returns is simply your 4 set of the resulting design values
that produce your experimental demand
BTW, linfit is unlimited in the order of polynomial fit.
Cheers ... Jean.

Cubic solver QUICK Explorer.sm (49 КиБ) скачан 41 раз(а).
#20 Опубликовано: 14.03.2021 18:31:03
hanskl

hanskl

7 сообщений из 158 понравились пользователям.

Группа: User

Wrote


1. True Vectors are column vectors, the expression "row vector" actually means nothing. But ... columns don't look good. Using length() instead rows() I can use row or column vectors in my procedures.

2. No, it isn't. But routines in polyroots() usually introduce some imaginary parts in roots because roundoff errors evaluating the discriminant of the polynomial equation. The question Im(R.k)=0 could look better, but for numerical methods it's impractical.

3. I don't know the internals of SMath polyroots(), but I'm pretty sure that can't handle symbolic values. And I'm pretty sure also that an application in civil engineering with symbolic expressions for cubic polynomials roots requires a very powerful symbolic kernel, and SMath isn't at that stage right now.

4. Sure, first use your cubic, which works well and it's equivalent to polyroots(reverse(stack(a,b,c,d)) and then define another for take only roots in the desired interval. Notice that in my procedure I assign x.4[n:=n+1] to R[k] but it's more correct assign to Re(R[k]).

Best regards.
Alvaro.




Thanks for the explanations.

Re 3, I think I worded myself poorly. Numeric evaluation of algebraic equations are fine by me, I just didnt want to code with a numeric tool like solve () that just checks all the values wihtin it's range to find the roots.

I guess there is no reason to use my own code to solve polynomials when SMath has polyroots. The cubic solver from my last post was something I made before I discovered polyroots.

Re 4, does this look like what you would have made to serve this purpose?

polyroots.PNG

Best regards,
  • Новые сообщения Новые сообщения
  • Нет новых сообщений Нет новых сообщений