Welcome Guest! To enable all features please Login. New Registrations are disabled.

Notification

Icon
Error

Login


Options
Go to last post Go to first unread
Offline omorr  
#1 Posted : 09 April 2012 00:06:30(UTC)
omorr


Rank: Administration

Groups: Registered, Advanced Member
Joined: 23/06/2009(UTC)
Posts: 1,740
Man
Serbia

Was thanked: 318 time(s) in 268 post(s)
Hello,

Unfortunately, there are still continuing problems with the nonlinear solvers.
Look at this example please Primer65a

It is a problem with moderate complexity. The goal is to solve a nonlinear equation.
Here is a screenshot from the file - v0.93


As it could be seen solve() and roots() gave similar results (T~328) (green and blue colored regions) but look at the function values - quite far from zero(~7*10^5). Something must be wrong with the convergence criteria of these functions, or I made some mistake I could not see.

It was enough here just to make few secant iterations and to get the root (red colored regions) (T~343) with the function value quite closer to zero (~10^-7).

I must admit that it took me quite a lot of time to get this result. Calculations took quite a long time (sometimes more than 20min) - different optimization did not help - until I realized that eval() on the right place will dramatically speed up the calculation (just few seconds).

I really do not know why eval() in that procedure made this calculation much, much faster. It seems that eval() will help in speeding the calculation but I did not realized yet when to use it. It is a bit "trial and error" procedure.

I commented this few times before, and I hope you would not mind if I mention this again.
Efficient nonlinear solvers (and some other numerical methods) are essential and crucial methods for every math software. It is a "must have" feature. Thanking to the Andrey's efforts there are solve() and roots() in SMath. Andrey did his best to make them but, unfortunately, in spite of his efforts it seems they are not god enough. I am not a programmer, have a vague idea how SMath plugins are working, have no idea how Andrey made solve() and roots() - I would not understand it anyway. I just feel (following some other math software) that the only solution is incorporating some established numerical libraries (made in C,C++,C# etc.) into SMath like "black boxes". For instance, I used Fortran and C procedures without knowing how are they working - just read what are the input parameters and what they return as results. I am just hoping that SMath plugin system can provide something like this and someone will do that eventually.

Regards,
Radovan

Edited by user 09 April 2012 00:13:06(UTC)  | Reason: Not specified

When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"

Wanna join the discussion?! Login to your SMath Studio Forum forum account. New Registrations are disabled.

Offline kilele  
#2 Posted : 10 April 2012 21:39:08(UTC)
kilele


Rank: Advanced Member

Groups: Registered
Joined: 30/03/2011(UTC)
Posts: 393

Was thanked: 132 time(s) in 113 post(s)
Radovan, If I might venture an opinion, you seem to be the appropriate person to help Andrey by writing some algorithms in the form of PSEUDOCODE for solving nonlinear systems
Offline omorr  
#3 Posted : 10 April 2012 22:31:27(UTC)
omorr


Rank: Administration

Groups: Registered, Advanced Member
Joined: 23/06/2009(UTC)
Posts: 1,740
Man
Serbia

Was thanked: 318 time(s) in 268 post(s)
Hello,
kilele wrote:
Radovan, If I might venture an opinion, you seem to be the appropriate person to help Andrey by writing some algorithms in the form of PSEUDOCODE for solving nonlinear systems

I hope you would not mind, but I have to disagree. There is already lots of libraries and code for numerical calculation out there and freely available. There are mature, well established, optimized and thoroughly tested numerical procedures made in different programming languages. It would be kind of wasting the time if we do it again, like "inventing a wheel". Of course, we can use that code in its original form but imagine using some well known Fortran or C++ code for, say, solving different kind of nonlinear or differential equations. One of the logical reasons for using those compiled languages is when you need power and speed, when you have huge amount of data, thousands of equations and quite complex problems. For some problems of moderate complexity using Fortran of C++ is hardly justified. You will spend much of your time on programming issues than on your problem solving. Therefore, in those cases we just need some attractive math environment like SMath equipped with lots of numerical procedures (made from the above mentioned libraries via the plugin mechanism). I do not understand how the plugin mechanism is working but looking at the environments which can be used for making them IDEs and programming languages for developing plugins I suppose that the SMath plugins for numerical calculations can be made by using some of those languages and already made numerical libraries in the same languages.

Of course, as I am not an expert in these things I might be totally wrong and this might not go that easy. Some plugin makers can give us more accurate and precise answers on this issue.

Regards,
Radovan

Edited by user 10 April 2012 22:42:45(UTC)  | Reason: Not specified

When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
Offline kilele  
#4 Posted : 11 April 2012 01:47:30(UTC)
kilele


Rank: Advanced Member

Groups: Registered
Joined: 30/03/2011(UTC)
Posts: 393

Was thanked: 132 time(s) in 113 post(s)
well it's just a matter of time that the DEV, with Radovan and others invaluable support and clever betatesting, gets to include great features like nonlinear solvers, symbolic calculations of every kind, new ways of documenting your results and powerful graphing capabilities.
Maybe it would help if someone could elaborate a step by step tutorial on how to create a SMath plugin taking any of the math libraries available on the net
Offline Davide Carpi  
#5 Posted : 24 May 2012 14:53:21(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,647
Man
Italy
Location: Italy

Was thanked: 1329 time(s) in 875 post(s)
Hi,

i've an issue with solve() and functions...

This is a part of a script to calculate properties for generic polygons (PolyProperties_DEBUG.zip

Looking for the axes that split in two chunks with equal area the polygon, instead of an iterative procedure i've thought to use solve(), but doesn't work Sad



anyone have an idea to fix it?


regards,

w3b5urf3r

Edited by user 24 May 2012 15:29:03(UTC)  | Reason: Not specified

If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects
Offline omorr  
#6 Posted : 24 May 2012 22:27:07(UTC)
omorr


Rank: Administration

Groups: Registered, Advanced Member
Joined: 23/06/2009(UTC)
Posts: 1,740
Man
Serbia

Was thanked: 318 time(s) in 268 post(s)
Hello w3b5urf3r,

It seems that solve() and roots() will not work with eval() sometimes. Here is a simple example:
solve(), roots(), eval()
You used eval() in two of your functions in the same way like f(x):=eval(...). I tried to remove eval() from both of them but even then solve() did not work. Although you can get single values by calculating root function, there can not be made a plot of the functions you are searching roots from - with or without eval. I do not know why. Any explanation that comes to my mind is that there may be some internal problem of the solve() function in your example. Maybe some kind of bug - not sure about it.

I've noticed another problem in resolving this. As we can calculate values from the root function, I get few values and made independent and dependent vectors. After that, I used interpolation and this way solve() will work. The strange thing is that there are quite different results with and without eval() used. Here is the part of your corrected file - using eval:
witheval
PolyProperties_DEBUG-witheval.sm

And without eval()
withouteval
PolyProperties_DEBUG-withouteval.sm

As you can see, there is quite a difference. The only difference between these two files is in using eval(). This might be a bug I have no idea where it comes from. I suppose that the version with eval() is the correct one.

As a final solution to your problem, if these functions are linear then you do not need solve(). Just calculate the intersection with x axis from a straight line (two points would be enough for that).

Regards,
Radovan

Edited by user 25 May 2012 09:42:02(UTC)  | Reason: Not specified

When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
Offline Davide Carpi  
#7 Posted : 28 May 2012 14:00:45(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,647
Man
Italy
Location: Italy

Was thanked: 1329 time(s) in 875 post(s)
Hi omorr Good

Yes I agree with you, there's something strange...

the second solution is the correct one; unfortunately for my purposes the functions are not linear, so I've built a dedicated script (I've tried with the secant method but sometimes diverges)

I'll publish the entire script just finished debugging Good


regards,

w3b5urf3r
If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects
Offline TheWizEd  
#8 Posted : 28 May 2012 17:32:59(UTC)
TheWizEd


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2010(UTC)
Posts: 178
Man
United States

Was thanked: 19 time(s) in 13 post(s)
Radovan,

On your original topic of algorithms for SMath, its not as easy as plugging in a module from another author. SMath does not store numbers as floating point but a series of Terms. For example 2/3 is not stored as 0.6666...7 but 2 and 3 and /. I believe Andrey did it this way for Optimization and it turns out worked well for storing units. To really take advantage of the SMath engine an algorithm would have to be reprogrammed to use the SMath object library.

If I had more time and was a better programmer I'd try to take on some of these. But alas I'm a trial and error programmer. Lots of errors but eventually get it right. Maybe a suggestion for an easy one and I'll try.
Ed
thanks 1 user thanked TheWizEd for this useful post.
on 28/05/2012(UTC)
Offline omorr  
#9 Posted : 28 May 2012 18:23:16(UTC)
omorr


Rank: Administration

Groups: Registered, Advanced Member
Joined: 23/06/2009(UTC)
Posts: 1,740
Man
Serbia

Was thanked: 318 time(s) in 268 post(s)
Thank you Ed for your reply and your good will Good

Regarding your answer I am a bit, let me say, discouraged. I just thought (maybe naively) that some numerical library could be incorporated into SMath (with more or less programming effort) and that someone will find the time and make that sooner or later. If I understood you well, that would not be an easy task - maybe impossible. Never mind, I just hope that some kind of quite powerful nonlinear equation solvers will be available for SMath sooner or later, among other numerical stuff. At the moment solve() and roots() will do, but unfortunately they are not good enough.

Regards,
Radovan

Edited by user 08 September 2012 16:45:33(UTC)  | Reason: Not specified

When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
Offline omorr  
#10 Posted : 03 June 2012 21:19:42(UTC)
omorr


Rank: Administration

Groups: Registered, Advanced Member
Joined: 23/06/2009(UTC)
Posts: 1,740
Man
Serbia

Was thanked: 318 time(s) in 268 post(s)
Hello,

Here is a simple realization of Broydes's method (Quasi-Newton) for solving the system of nonlinear equations.

Broydens' method

Broyden-method-2.sm

Try it when rots() fail. Moreover, there will be no complain if the functions were defined with eval().

Regards,
Radovan

When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
thanks 1 user thanked omorr for this useful post.
on 03/06/2012(UTC)
Offline kilele  
#11 Posted : 04 June 2012 22:17:41(UTC)
kilele


Rank: Advanced Member

Groups: Registered
Joined: 30/03/2011(UTC)
Posts: 393

Was thanked: 132 time(s) in 113 post(s)
Is this infallible? Good
I suppose that SMath's solve() investigates the particular function entered by the user and try different strategies/algorithms/intervals.
If I remember, the Bisection method always converge thanks to Bolzano theorem, i.e provided that the function is continuous and there's a change of sign between the two points. Bisection is slow but who cares (Soyuz spacecrafts are ugly but also reliable) if it manages to find a bunch of roots combined with other algorithms and strategies to seek roots within certain intervals based on the kind of function.
Offline omorr  
#12 Posted : 05 June 2012 00:26:46(UTC)
omorr


Rank: Administration

Groups: Registered, Advanced Member
Joined: 23/06/2009(UTC)
Posts: 1,740
Man
Serbia

Was thanked: 318 time(s) in 268 post(s)
Hello,
Originally Posted by: kilele Go to Quoted Post
Is this infallible? Good
No, it is not of course. It is just an alternative to roots(). It worked for me for some problems when roots() failed

Originally Posted by: kilele Go to Quoted Post
If I remember, the Bisection method always converge ...
You are right. I do not know how solve() works. But Bisection method for n-dimensional problem in SMath? Hmm...I am not so sure about that.

Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
Offline kilele  
#13 Posted : 05 June 2012 03:54:29(UTC)
kilele


Rank: Advanced Member

Groups: Registered
Joined: 30/03/2011(UTC)
Posts: 393

Was thanked: 132 time(s) in 113 post(s)
Originally Posted by: omorr Go to Quoted Post
But Bisection method for n-dimensional problem in SMath? Hmm...I am not so sure about that.


There seems to be bibliography about generalized bisection, of course this is advanced maths far beyond my grasp Biggrin
I might be able to access some of these articles, tell me by pm if someone is interested.

http://www.ddm.org/DD07/Mejzlik.pdf
http://www.springerlink....ontent/w72615872r512112/
http://dl.acm.org/citation.cfm?id=2705
http://dl.acm.org/citation.cfm?id=11151
http://goo.gl/3uKT4
http://goo.gl/qzPPB
http://goo.gl/2D4E2

Edited by user 05 June 2012 15:33:46(UTC)  | Reason: Not specified

thanks 1 user thanked kilele for this useful post.
on 05/06/2012(UTC)
Offline omorr  
#14 Posted : 05 June 2012 11:12:40(UTC)
omorr


Rank: Administration

Groups: Registered, Advanced Member
Joined: 23/06/2009(UTC)
Posts: 1,740
Man
Serbia

Was thanked: 318 time(s) in 268 post(s)
Thanks kilele for the reply,

Actually, we could try to make all those functions in SMath, but I think there is no point to make them ourselves (except for our personal use), like this one:

bisect
bisect.sm

By the way, this will not work if we use eval(), as well.

eval()

Do not know why is this not working Sad

We could also try to make an n-dimensional bisect as well like an SMath function (with some more effort). But this is not the point. I think SMath should have those functions already incorporated, IMHO. The problem is how to make them. I thought the more practical way is to use some already available code and make some plugins from them - but it seems I was wrong.

Regards,
Radovan

Edited by user 05 June 2012 11:30:10(UTC)  | Reason: Not specified

When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
Offline kilele  
#15 Posted : 05 June 2012 12:54:15(UTC)
kilele


Rank: Advanced Member

Groups: Registered
Joined: 30/03/2011(UTC)
Posts: 393

Was thanked: 132 time(s) in 113 post(s)
Thanks again for your valuable contributions..

I've found an article at
http://numericalmethods.eng.usf.edu
explaining the bisection method and its advantages/drawbacks with examples:
http://numericalmethods....en_nle_txt_bisection.doc
Offline kilele  
#16 Posted : 05 September 2012 14:46:25(UTC)
kilele


Rank: Advanced Member

Groups: Registered
Joined: 30/03/2011(UTC)
Posts: 393

Was thanked: 132 time(s) in 113 post(s)
a question for the experts? what is "homotopy method" ?
It seems to be a very successful method in solving the roots for polynomial systems. Look at the end of this document
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.