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

Notification

Icon
Error

Login


14 Pages«<89101112>»
Options
Go to last post Go to first unread
Offline Davide Carpi  
#181 Posted : 10 September 2016 03:50:52(UTC)
Davide Carpi


Rank: Advanced Member

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

Was thanked: 1323 time(s) in 873 post(s)
Thank you, I have a refactored version running on my system where the el(#) issue doesn't happens, thus I haven't noticed it. I'll look in these days if I can fix it even in the current code. I'll add Taylor(4) in the refactored plugin (and I'll see if I can improve or I have to remove Taylor(3), that wasn't designed for multi-variables functions).

Edited by user 10 September 2016 04:27:17(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 Alex M.  
#182 Posted : 20 October 2016 19:01:44(UTC)
Alex M.


Rank: Advanced Member

Groups: Registered
Joined: 03/03/2014(UTC)
Posts: 418
Canada

Was thanked: 125 time(s) in 96 post(s)
Hello Davide,

I am attempting to use FindRoot() function for a rather unorthodox purpose: to arrive to an iterative solution of an excel spreadsheet (if you think this is nuts you can stop reading right here).

Idea is:
1. substitute value in excel
2. get value from excel
3. if value obtained is not zero go back to "1"

I wrote a simple Newton-Raphson for() loop that works, however I am puzzled why FindRoot() or NewtonRaphson() cannot achieve similar purpose.

See PDF attached.

BMCR.sm (14kb) downloaded 65 time(s). BMCR.xlsx (26kb) downloaded 47 time(s). BMCR.pdf (126kb) downloaded 79 time(s).

P.S.: after two minutes of "pause&think" I have realized that there is a good chance that FindRoot(), when iterating, cannot execute a call to another plugin's function, is this correct?

P.P.S.: I found the reason - it is likely the excel_IO function itself. More weekend work for me to do.

Edited by user 20 October 2016 22:13:17(UTC)  | Reason: Not specified

Offline Davide Carpi  
#183 Posted : 21 October 2016 00:21:05(UTC)
Davide Carpi


Rank: Advanced Member

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

Was thanked: 1323 time(s) in 873 post(s)
Hello Alex,

Originally Posted by: Alex M. Go to Quoted Post
P.P.S.: I found the reason - it is likely the excel_IO function itself. More weekend work for me to do.


Yes, at first glance I think the issues is that EXCEL_IO returns a value even you you feed it with an unknown, hence while FindRoot() preprocess the function gets a result -> no unknowns; since now NS' nightly is better structured I think in future I might provide some workaround even for these cases.

If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects
thanks 1 user thanked Davide Carpi for this useful post.
on 21/10/2016(UTC)
Offline Alex M.  
#184 Posted : 21 October 2016 00:45:50(UTC)
Alex M.


Rank: Advanced Member

Groups: Registered
Joined: 03/03/2014(UTC)
Posts: 418
Canada

Was thanked: 125 time(s) in 96 post(s)
Originally Posted by: Davide Carpi Go to Quoted Post
Hello Alex,

Originally Posted by: Alex M. Go to Quoted Post
P.P.S.: I found the reason - it is likely the excel_IO function itself. More weekend work for me to do.


Yes, at first glance I think the issues is that EXCEL_IO returns a value even you you feed it with an unknown, hence while FindRoot() preprocess the function gets a result -> no unknowns; since now NS' nightly is better structured I think in future I might provide some workaround even for these cases.



Thank you Davide,

I do have to fix excel plugin no matter what though. Right now it converts any variables passed to it to string (string of a variable name if undefined) and than to number - this is likely a part of the problem.

Edited by user 21 October 2016 00:53:56(UTC)  | Reason: Not specified

thanks 1 user thanked Alex M. for this useful post.
on 21/10/2016(UTC)
Offline Jean Giraud  
#185 Posted : 21 October 2016 04:25:04(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,868
Canada

Was thanked: 980 time(s) in 808 post(s)
P.S.: after two minutes of "pause&think" I have realized that there is a good chance that FindRoot(), when iterating, cannot execute a call to another plugin's function, is this correct?

That makes sense. You may have to pull-out the data from XLS,
reconstruct in Smath and spool back in XLS. Can't you do
directly in XLS via "Target value". They claimed the special
"Target solver" could solve 400 variables

Forum Given_Find.gif
Offline omorr  
#186 Posted : 21 October 2016 11:39:24(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)
As anyone could see, there were lots of posts here for this plugin.

After so many years struggling with SMath and nonlinear problems (system of nonlinear algebraic equations, nonlinear optimization) I have to admit that whenever I want to do that in SMath (more than two, three variables), I get few gray hairs Wallbash . See for example this one (doomed for me...). At the moment, I just do not know how to solve this Grabli

SMath Studio-Primer38-doomed.sm.jpg

SMath file - Be my guest if you want to solve it Good

Primer38-doomed.sm (28kb) downloaded 72 time(s).

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 21/10/2016(UTC)
Offline Jean Giraud  
#187 Posted : 21 October 2016 18:38:15(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,868
Canada

Was thanked: 980 time(s) in 808 post(s)
Originally Posted by: omorr Go to Quoted Post
I just do not know how to solve this


f(,x,y) does not generate a function, just a vector.
So, there is nothing to solve directly. If that vector is
a vector of initial guesses, you must have 11 relationships
wrt each of the 3 parameters. From there, the recursive
"Divide and Conquer" algorithm sould solve. This is the Mathcad
"Given/Find", has been working for up to 22 equalities,
not too easy to initialise.. The near 0 all 11 elements look
pure coincidence. I guess I'm missing something.
In the "Solve Inverse Recursive" just plug your new 'k'
from your work sheet.

Can't help much !!!

Smath "FindRoots" is a "Divide and Conquer" solver.
Offline omorr  
#188 Posted : 21 October 2016 20:25:32(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 Jean for the reply,

The problem is of 11 equations-relationships with 11 unknowns. The function f() has three arguments (phi - single value, x,y - vectors with five elements each) returning 11 element vector.

We have to find phi,x,y where all the elements of f() will be close to zero. Moreover, if we talk about the acceptable range of phi,x,y - phi is in the range [0,1], x,y are positive values with the conditions sum(x)=1, sum(y)=1. Anyway, this is a quite standard calculation in chemical thermodynamics - vapor, liquid equilibrium.

From my experience, I just wanted to note (once more) that solving similar problems - like this one - might be quite a frustrating thing in SMath.

Here is the same problem solved in Mathcad

Mathcad - [Primer 3.8].png

Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
Offline Jean Giraud  
#189 Posted : 22 October 2016 03:52:25(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,868
Canada

Was thanked: 980 time(s) in 808 post(s)
Oh ! YES : liquid/vapor equilibrium.

The Mathcad Given/Find code is much different and much more convivial
than Smath 'FindRoot'. The 5 examples output same results with a bit
of attention wrt the vector 'initial': FindRoot' much less robust.
The Mathcad Given/Find solves first [internally] symbolic, which
FindRoot does not.

I didn't completely understand your vector construction.

The final solution of the Frobenius DE variable coefficients
goes via Given/Find. I will work that long monkey business example,
hoping Smath doing it.

Jean

Solve Given_Find [UN Cylinder].sm (63kb) downloaded 63 time(s).
Offline Jean Giraud  
#190 Posted : 22 October 2016 07:07:36(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,868
Canada

Was thanked: 980 time(s) in 808 post(s)
Frobenius => no sweat !

Jean

Solve Given_Find [UN Frobenius].sm (38kb) downloaded 88 time(s).
Offline Jean Giraud  
#191 Posted : 22 October 2016 07:35:29(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,868
Canada

Was thanked: 980 time(s) in 808 post(s)
... (suite)
In the above Frobenius, in the F vector,
it only necessary to equate C1=1
the remaining elements need not be equated to 0
Offline omorr  
#192 Posted : 22 October 2016 10:16: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)
Originally Posted by: Jean Giraud Go to Quoted Post

I didn't completely understand your vector construction.

That's one of my main points I mentioned many times. Actually, one do not have to understand the vector construction of the equations. It is important that the function returns the numerical vector of the same length as the length of the variable numbers. Solvers which uses Jacobin analytically are sometimes totally useless. Only the methods which are gradient free (or numerical Jacobian) might help here. Davide included in FindRoot() many algorithms for nonlinear solvers (working in background).

Originally Posted by: Jean Giraud Go to Quoted Post

The final solution of the Frobenius DE variable coefficients
goes via Given/Find. I will work that long monkey business example,
hoping Smath doing it.

Nice, FindRoot() will do the job here for the Quternion system if the init vector elements *p,q,r* have different initial values (not zero values i.e.)

Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
Offline omorr  
#193 Posted : 22 October 2016 10:55: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)
Originally Posted by: Jean Giraud Go to Quoted Post
Frobenius => no sweat !

Jean

Solve Given_Find [UN Frobenius].sm (38kb) downloaded 88 time(s).

Thank you for this example,

FindRoot() goes with it well. You have nine clear defined expressions (F vector) with nine unknowns (V vector), and FindRoot() will do the job

By the way, if all the initial values are the same we can use the standard trick : V[9:=0 , V:=V+1 : and all nine vector elements will have unity values. This is all right, I think, because this will give: Unknowns(F)=[C] which means the unknowns is C - it happened to be a vector. But, your construction is more understandable, I think.

Moreover, this way will also work

SMath Studio - [SolveGiven_Find[UNFrobenius].sm_].png

Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
Offline Jean Giraud  
#194 Posted : 22 October 2016 19:56:21(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,868
Canada

Was thanked: 980 time(s) in 808 post(s)
Thanks Radovan,

Your collaboration is most appreciated. I agree with you:
"solving" in generally a painful task, more painful in Smath
than in Mathcad. The set of Frobenius coefficients C1 works well.
The set C2 does not solve ... the same pattern as C1.
FindRoot => not robust for Frobenius C2
I can't see any possible repair /

Jean

Solve Given_Find [UN Frobenius C2].sm (24kb) downloaded 52 time(s).
Offline omorr  
#195 Posted : 22 October 2016 21:00:55(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)
You are welcome Jean,

Your last two examples, basically, represented system of linear equations, and FindRoot() should not have to much problems in solving them.

In this example, you missed one equation: C[3:=1 (there were 8) and there were 9 variables. Mathcad could cope with this.

Here is the corrected version.

SolveGiven_Find[UNFrobeniusC2]_corr.sm (22kb) downloaded 61 time(s).

Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
Offline Jean Giraud  
#196 Posted : 22 October 2016 23:35:34(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,868
Canada

Was thanked: 980 time(s) in 808 post(s)
Thanks Radovan,

I tried the 9 components 'F' before posting. The error was not there.
The bug was that once the solve had failed, it wouldn't rescue itself.
The trick was to delete the red "FindRoot" and recall from the menu.
This bug is one of those "Shadow in the context".

Cheers, Jean
Offline omorr  
#197 Posted : 24 October 2016 15:30:22(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 the test example which is intended to point out that SMath should be capable of solving this (two nonlinear equations with two unknowns), by using the functions from this plugin.

Mathcad_nls.jpg

I failed by everything I try.

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 24/10/2016(UTC)
Offline Jean Giraud  
#198 Posted : 24 October 2016 18:30:20(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,868
Canada

Was thanked: 980 time(s) in 808 post(s)
Here is another "cup of tea" to help you grow white hairs.

Thanks for your attached challenge.
Andrey, Martin, Davide ...: where are you in there ?

Cheers Radovan, Jean

ODE Rkadapt Minerr.sm (49kb) downloaded 53 time(s).



thanks 1 user thanked Jean Giraud for this useful post.
on 24/10/2016(UTC)
Offline omorr  
#199 Posted : 24 October 2016 19:24:00(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 Jean,

I tried to solve those optimization problems few years ago (see this for example) by myself and with the help of Davide's NonlinearSolvers plugin (dozen of functions are there). You can find many examples during the plugin functions testing. Unfortunately, many of these files on this thread do not work anymore due to the time gap, lack of enough users for testing, my own ability shortcomings for testing them, and changes in SMath itself. Some of them might work with slight changes (only part of them though). On the other hand, some examples were terribly slow.

Your example (uncompleted - missing the optimization of initial conditions) might get solved completely in SMath but we need the Davide to check the plugins function and let us know how to use them. Therefore, we have to be patient a bit.

Best Regards,
Radovan

Edited by user 24 October 2016 19:31:46(UTC)  | Reason: Not specified

When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
Offline Davide Carpi  
#200 Posted : 24 October 2016 19:31:23(UTC)
Davide Carpi


Rank: Advanced Member

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

Was thanked: 1323 time(s) in 873 post(s)
Thank you guys, these examples are very useful to fix the bugs in this plugin Good

I'm working to a new version of the code, almost totally refactored.
Looking at your examples seems there are several things to fix in my preprocessor; with some tweak, it is able to solve it.

2016-10-24 18_27_07-SMath Studio - [FindRoot.sm_].png

now I just have to find some consistant way to make it working always Crazy
If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects
thanks 2 users thanked Davide Carpi for this useful post.
on 24/10/2016(UTC),  on 18/03/2018(UTC)
Users browsing this topic
14 Pages«<89101112>»
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.