NonlinearSolvers plugin

NonlinearSolvers plugin - BDQRF, Bisection, Brent's, Broyden's, Newton-Raphson, Ridder's, Secant, Homotopy - Poruke

#261 Objavljeno: 15. 8. 2023. 14:11:34
Martin Kraska

Martin Kraska

1.369 svidjanja u 2.283 postova.

Grupa: Moderator

Davide, would it be possible to enable the use of custom units as variable names to solve for in FindRoot()?

The application case is statics of rigid bodies.

The vector sum of all forces is zero and the sum of moments about some reference point is zero. This is then solved for the support reactions.

This usually involves cross products. One of the vectors is typically a vector normalized by it's length and multiplied by an unknown scalar quantity (for which we later want to solve).

I've made quite some experiments on how to get the expressions right. These options seem to work:

- Mark the unknowns including any given quantities as units. This seems to flag them as scalars for SMath simplification.
- Use a custom cross product and Maxima. Then no custom units are required. This is actually a request for a better cross product in SMath.
- Mark the unknowns and any given quantities as units and use Maxima for simplification. This is actually used in 1-2.sm

Only the first version works without Maxima.
So if FindRoot() would accept unit names for unknowns then users could solve such problems without Maxima.

1-2.sm (125,67 KiB) preuzeto 1967 put(ova).
2023-08-15 18_27_47-SMath Solver - [Vektorprodukt.sm_].png
Vektorprodukt.sm (193,46 KiB) preuzeto 1923 put(ova).
Technische Mechanik mit SMath Studio: https://link.springer.com/book/10.1007/978-3-658-50592-9
#262 Objavljeno: 16. 8. 2023. 02:44:29
Alvaro

Alvaro

1.139 svidjanja u 1.805 postova.

Grupa: User

Wrote

... The application case is statics of rigid bodies. ...



Hope that the attached helps. FindRoots (and roots) without maxima.

1-2.pdf (581,49 KiB) preuzeto 1387 put(ova).
1-2.sm (138,19 KiB) preuzeto 1881 put(ova).

Best regards.
Alvaro.

3 korisnika je svidelo ovu objavu
Mark R Harris 18. 8. 2023. 00:07:00, Martin Kraska 16. 8. 2023. 08:19:00, Davide Carpi 16. 8. 2023. 14:59:00
#263 Objavljeno: 27. 8. 2023. 12:44:14
Martin Kraska

Martin Kraska

1.369 svidjanja u 2.283 postova.

Grupa: Moderator

Hi Alvaro your proposal to use vectorize() for products of undefined variables with vectors is recomended by Andrey as well. But here is a simplified example of what can happen using this approach:

Unit vector.png
Unit vector.sm (8,2 KiB) preuzeto 1893 put(ova).

In both cases, vectorization is dangerous as it doesn't fail in an obvious way but rather silently produces wrong results.

Martin
Technische Mechanik mit SMath Studio: https://link.springer.com/book/10.1007/978-3-658-50592-9
1 korisnika je svidelo ovu objavu
Alvaro 28. 8. 2023. 02:13:00
#264 Objavljeno: 28. 8. 2023. 02:28:46
Alvaro

Alvaro

1.139 svidjanja u 1.805 postova.

Grupa: User

Hi Martin. You're right, vectorization in SMath, just like it did in mathcad, can easily produce results that aren't what one would expect, not to mention the one you mentioned earlier that varied depending on whether it was assigned to a variable or not. And as you very well say, it is not a recommended practice to try to explain the erratic behavior of a software in class, even more so if there is really no way to deduce what is due to it. And although perhaps an explanation could be found for that unit vector version, for the other one I don't really find sense. So I think it's a good idea that you could work with units to imply scalars. It would be necessary to add that the sum of these 'units' does not report an error so that its application is broader.

BTW, a workaround, but although I understand (I guess) why your example gives a "wrong" result, I'm not quite sure why this version gives a "correct" one. Maybe it's because the vector is already "spent" on the addition, but the rules are not clear as to why the addition "arrives" before the vectorization. That is to say, if I were to present this in class, assuming it was ethical for me to try to explain it, I would probably be in troubles if someone asked the slightest detail why that result is obtained.

Clipboard01.png

Best regards.
Alvaro.
2 korisnika je svidelo ovu objavu
Martin Kraska 28. 8. 2023. 03:36:00, sergio 28. 8. 2023. 06:00:00
#265 Objavljeno: 28. 8. 2023. 04:14:00
Martin Kraska

Martin Kraska

1.369 svidjanja u 2.283 postova.

Grupa: Moderator

Hi Alvaro,

Your post supports my belief that there is no safe alternative to the scalarity assumption for undefined variables. Fortunately, units are assumed to be scalars and we can demonstrate how nice and smooth things work with this assumption.

Unfortunately, precious features like FindRoot() currently won't work with this. So I thought it was worth a bit of discussion to find out if there is really no safe alternative.

Perhaps Davide can enable handling of unit-like unknowns.

Yet there are disadvantages of the units approach
- you might run into "units don't match" (so far this was no problem in my applications)
- you have to avoid pre-defined names, ending up with text indices everywhere
- the borderline between where it is essential and where normal variables would do is uncertain

So for now I'd state these textbook rules for symbolic vector operations:
- Do not use vectorize.
- If an expected simplification fails, mark scalar variables as units.

It would probably be overkill to generally forbid ordinary non-unit variables.

Martin
Technische Mechanik mit SMath Studio: https://link.springer.com/book/10.1007/978-3-658-50592-9
1 korisnika je svidelo ovu objavu
sergio 28. 8. 2023. 06:00:00
#266 Objavljeno: 16. 8. 2024. 05:00:13
Martin Kraska

Martin Kraska

1.369 svidjanja u 2.283 postova.

Grupa: Moderator

It seems that there is a bug in Jacobian() from Nonlinear Solvers.

The application is to convert a system of equations to matrix form.

The built-in Jacob() function and Maxima's jacobian() work as expected, once you provide the correct type of arguments.

Jacobian() seems to not obey the order of entries in the variables vector (using the ordering returned by Unknowns() ).

Worksheet18.png
Worksheet18.sm (20,67 KiB) preuzeto 1988 put(ova).
Technische Mechanik mit SMath Studio: https://link.springer.com/book/10.1007/978-3-658-50592-9
1 korisnika je svidelo ovu objavu
Davide Carpi 18. 8. 2024. 01:32:00
#267 Objavljeno: 18. 8. 2024. 01:33:06
Davide Carpi

Davide Carpi

1.444 svidjanja u 2.936 postova.

Grupa: Moderator

Wrote

It seems that there is a bug in Jacobian() from Nonlinear Solvers.

The application is to convert a system of equations to matrix form.

The built-in Jacob() function and Maxima's jacobian() work as expected, once you provide the correct type of arguments.

Jacobian() seems to not obey the order of entries in the variables vector (using the ordering returned by Unknowns() ).



Odd, I'll check it, thank you Martin.
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
#268 Objavljeno: 29. 9. 2026. 17:21:44
usamakhan

usamakhan

7 svidjanja u 98 postova.

Grupa: User

I am having this weird error. I am on KUbuntu

2026-09-29-20-19-08.mp4 (3,61 MiB) preuzeto 128 put(ova).
lm.sm (5,78 KiB) preuzeto 303 put(ova).
Izmenjeno 29. 9. 2026. 17:22:21
  • Novi postovi
  • Nema novih postova