Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

2 Pages12>
Options
Go to last post Go to first unread
Offline hanskl  
#1 Posted : 02 October 2020 20:20:15(UTC)
hanskl


Rank: Advanced Member

Groups: Registered
Joined: 25/10/2017(UTC)
Posts: 66
Norway

Was thanked: 4 time(s) in 2 post(s)
Hi.

I need help with a iterative calculation. This is my first time trying to build a iterative loop in SMath.

I need to calculate a coefficient that can only be calculated when the difference between X.0 and X.c is below a limit.

I am trying to solve this as a function of r and rho.

Can someone help me get started on how to formulate the iteration?

problem.sm (12kb) downloaded 6 time(s).
problem.PNG

Best regards,
Offline mkraska  
#2 Posted : 02 October 2020 20:47:52(UTC)
mkraska


Rank: Advanced Member

Groups: Registered
Joined: 15/04/2012(UTC)
Posts: 1,625
Germany

Was thanked: 909 time(s) in 571 post(s)
problem_Kr.png
problem_Kr.sm (11kb) downloaded 9 time(s).
Martin Kraska

Pre-configured portable distribution of SMath Studio: https://en.smath.info/wi...th%20with%20Plugins.ashx
thanks 1 user thanked mkraska for this useful post.
on 03/10/2020(UTC)
Offline hanskl  
#3 Posted : 02 October 2020 21:31:50(UTC)
hanskl


Rank: Advanced Member

Groups: Registered
Joined: 25/10/2017(UTC)
Posts: 66
Norway

Was thanked: 4 time(s) in 2 post(s)
Thank you for your suggestion Martin!

I need the output X to be a function of r and rho. Is that possible?

Some random questions...
1. why do you use arctg instead of atan?
2. does the iterative process have to be wrapped into a for loop where you need to give it a range, and ultimately an upper boundry (n.max)?
Offline mkraska  
#4 Posted : 02 October 2020 22:58:52(UTC)
mkraska


Rank: Advanced Member

Groups: Registered
Joined: 15/04/2012(UTC)
Posts: 1,625
Germany

Was thanked: 909 time(s) in 571 post(s)
Originally Posted by: hanskl Go to Quoted Post
Thank you for your suggestion Martin!

I need the output X to be a function of r and rho. Is that possible?

Some random questions...
1. why do you use arctg instead of atan?
2. does the iterative process have to be wrapped into a for loop where you need to give it a range, and ultimately an upper boundry (n.max)?


0. I think you would need to wrap the full procedure into a function of r and rho with X as return value. Alternatively, you might come up with a recursive definition of the procedure.
1. It is just the setting world versus european style for functions. It is the same function, just displayed according to the GUI settings.
2. the for loop just came in handy for generating the indices for storage of iteration history. You could use while 1 as well. I also thought it was a good idea to have an upper limit for the iterations in case the algorithm might diverge.
Martin Kraska

Pre-configured portable distribution of SMath Studio: https://en.smath.info/wi...th%20with%20Plugins.ashx
Offline hanskl  
#5 Posted : 02 October 2020 23:09:57(UTC)
hanskl


Rank: Advanced Member

Groups: Registered
Joined: 25/10/2017(UTC)
Posts: 66
Norway

Was thanked: 4 time(s) in 2 post(s)
Originally Posted by: mkraska Go to Quoted Post
Originally Posted by: hanskl Go to Quoted Post
Thank you for your suggestion Martin!

I need the output X to be a function of r and rho. Is that possible?

Some random questions...
1. why do you use arctg instead of atan?
2. does the iterative process have to be wrapped into a for loop where you need to give it a range, and ultimately an upper boundry (n.max)?


0. I think you would need to wrap the full procedure into a function of r and rho with X as return value. Alternatively, you might come up with a recursive definition of the procedure.
1. It is just the setting world versus european style for functions. It is the same function, just displayed according to the GUI settings.
2. the for loop just came in handy for generating the indices for storage of iteration history. You could use while 1 as well. I also thought it was a good idea to have an upper limit for the iterations in case the algorithm might diverge.


Thanks again for the replies, on a friday night no less. I really appreciate that! Biggrinrinks:

0. Can you explain this in layman terms? Ultimately, I want to graph N.gamma as a function of r and rho, where I have 10 set values of r and 10 corresponding functions plotted with rho along x-axis.
1. OK. I was just curious if they were different functions, like max/Max for example, which I have found can make or break a book.
2. thanks again for the explanation.

Cheers
Offline Jean Giraud  
#6 Posted : 03 October 2020 01:33:45(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 4,782
Canada

Was thanked: 800 time(s) in 634 post(s)
Originally Posted by: hanskl Go to Quoted Post
I need the output X to be a function of r and rho. Is that possible?

Sorry, don't understand.
If you want to see the evolution of the solution, use a while loop,
SQRT(x) in Samples is a good example.
Visit Golden ratio as well.

problem_Kr Plot What.sm (18kb) downloaded 4 time(s).
Offline hanskl  
#7 Posted : 03 October 2020 01:53:46(UTC)
hanskl


Rank: Advanced Member

Groups: Registered
Joined: 25/10/2017(UTC)
Posts: 66
Norway

Was thanked: 4 time(s) in 2 post(s)
Originally Posted by: Jean Giraud Go to Quoted Post
Originally Posted by: hanskl Go to Quoted Post
I need the output X to be a function of r and rho. Is that possible?

Sorry, don't understand.
If you want to see the evolution of the solution, use a while loop,
SQRT(x) in Samples is a good example.
Visit Golden ratio as well.

problem_Kr Plot What.sm (18kb) downloaded 4 time(s).


Hi Jean,

Thanks for the sample.

I think I got my calculation working now with (a lot) of help from Martin.

I cant plot N.gamma(r, rho) because it obviously takes an enormous amount of computational power.

However, the formulas seem to return the correct value when you compare to the diagrams in this sheet (the benchmark for my calculation).

PS. Is there some way to speed up the calculation of N.gamma? For some values of r and rho it can take Almost a minute to compute.

Cheers

problem_solved.sm (512kb) downloaded 6 time(s).
problem_solved.PNG

Edited by user 03 October 2020 02:36:43(UTC)  | Reason: Not specified

Offline Jean Giraud  
#8 Posted : 03 October 2020 03:02:57(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 4,782
Canada

Was thanked: 800 time(s) in 634 post(s)
Originally Posted by: hanskl Go to Quoted Post
I cant plot N.gamma(r, rho) because it obviously takes an enormous amount of computational power.

Get a quick insight ... that you can mesh finer.

problem_solved More Insight.sm (518kb) downloaded 3 time(s).
Offline mkraska  
#9 Posted : 03 October 2020 10:38:48(UTC)
mkraska


Rank: Advanced Member

Groups: Registered
Joined: 15/04/2012(UTC)
Posts: 1,625
Germany

Was thanked: 909 time(s) in 571 post(s)
Originally Posted by: hanskl Go to Quoted Post

I think I got my calculation working now with (a lot) of help from Martin.

I cant plot N.gamma(r, rho) because it obviously takes an enormous amount of computational power.

However, the formulas seem to return the correct value when you compare to the diagrams in this sheet (the benchmark for my calculation).

PS. Is there some way to speed up the calculation of N.gamma? For some values of r and rho it can take Almost a minute to compute.

Cheers


There is no need to define the quantities as explicit functions if you just want to evaluate an expression. Removing the arguments together with setting the whole algorithm to numeric optimization in the context mnenu made a speedup from 30s to 3s.

problem_solved_Kr.sm (510kb) downloaded 10 time(s).
2020-10-03 09_36_55-SMath Studio - [problem_solved.sm_].png
Martin Kraska

Pre-configured portable distribution of SMath Studio: https://en.smath.info/wi...th%20with%20Plugins.ashx
Offline hanskl  
#10 Posted : 03 October 2020 11:45:45(UTC)
hanskl


Rank: Advanced Member

Groups: Registered
Joined: 25/10/2017(UTC)
Posts: 66
Norway

Was thanked: 4 time(s) in 2 post(s)
Originally Posted by: mkraska Go to Quoted Post
Originally Posted by: hanskl Go to Quoted Post

I think I got my calculation working now with (a lot) of help from Martin.

I cant plot N.gamma(r, rho) because it obviously takes an enormous amount of computational power.

However, the formulas seem to return the correct value when you compare to the diagrams in this sheet (the benchmark for my calculation).

PS. Is there some way to speed up the calculation of N.gamma? For some values of r and rho it can take Almost a minute to compute.

Cheers


There is no need to define the quantities as explicit functions if you just want to evaluate an expression. Removing the arguments together with setting the whole algorithm to numeric optimization in the context mnenu made a speedup from 30s to 3s.



Can you help me understand understand the difference between having the quantities as explicit functions like I did and your approach, and what will the advantange/disadvantages be for one or the other? I want to try to understand the best way to structure my calculations for the result I want.

BTW, just installed the latest SMath version, what a tremendous speedup that gave on this sheet. My oldere version would go on for minutes without being able to plot N.gamma.

Thanks
Offline mkraska  
#11 Posted : 03 October 2020 18:59:34(UTC)
mkraska


Rank: Advanced Member

Groups: Registered
Joined: 15/04/2012(UTC)
Posts: 1,625
Germany

Was thanked: 909 time(s) in 571 post(s)
Originally Posted by: hanskl Go to Quoted Post

Can you help me understand understand the difference between having the quantities as explicit functions like I did and your approach, and what will the advantange/disadvantages be for one or the other? I want to try to understand the best way to structure my calculations for the result I want.

BTW, just installed the latest SMath version, what a tremendous speedup that gave on this sheet. My oldere version would go on for minutes without being able to plot N.gamma.

Thanks


I am on very thin ice when making statements on that, because it is just based on observations, not on conceptual insight.

If you define functions, these are stored as is and evaluated when the function is called. If define a variable, the expression is simplified using the current context (available definitions of variables) You can see that in the debugger window.
You always see what you store in the dynamic callout when hovering over the definition.

I know that in the end you want a quantity depending on r and rho, thus a function. Yet, inside the algorithm r and rho are fixed and not subject to change for a given call of that algorithm. So it is straightforward to use the global value of these variables throughout the algorithm, specified as arguments when calling the algorithm.

Martin Kraska

Pre-configured portable distribution of SMath Studio: https://en.smath.info/wi...th%20with%20Plugins.ashx
thanks 1 user thanked mkraska for this useful post.
on 04/10/2020(UTC)
Offline Jean Giraud  
#12 Posted : 03 October 2020 20:40:12(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 4,782
Canada

Was thanked: 800 time(s) in 634 post(s)
Originally Posted by: hanskl Go to Quoted Post
My oldere version would go on for minutes without being able to plot N.gamma.

My steam engine laptop SS 6179 runs Martin in 1.8 min.
It runs the solver 168*10= 1680 for all 10 plots
Set j=9 ... constrain gamma 0.9 reluctant
Set the solver in eval(,) mode.
Cheers ... Jean

problem_solved_Kr Sanity.sm (511kb) downloaded 8 time(s).
Offline Jean Giraud  
#13 Posted : 03 October 2020 20:52:49(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 4,782
Canada

Was thanked: 800 time(s) in 634 post(s)
Gamma Plot.PNG
Offline Jean Giraud  
#14 Posted : 03 October 2020 22:34:53(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 4,782
Canada

Was thanked: 800 time(s) in 634 post(s)
N.γ(r,ρ) should plot in ~ 30 s on modern machines.
Saved in my Project file ... any abstract about the project ?

Project Hanski Unknown.sm (514kb) downloaded 10 time(s).
Offline Andrey Ivashov  
#15 Posted : 04 October 2020 00:30:06(UTC)
Andrey Ivashov


Rank: Administration

Groups: Developers, Registered, Knovel Developers, Administrators, Advanced Member
Joined: 11/07/2008(UTC)
Posts: 1,426
Man
Russian Federation

Was thanked: 1681 time(s) in 566 post(s)
Originally Posted by: Jean Giraud Go to Quoted Post
N.γ(r,ρ) should plot in ~ 30 s on modern machines.
Saved in my Project file ... any abstract about the project ?

Project Hanski Unknown.sm (514kb) downloaded 10 time(s).


Calculated in about 5 seconds on the latest stable SMath Studio.

Originally Posted by: Jean Giraud Go to Quoted Post
Originally Posted by: hanskl Go to Quoted Post
My oldere version would go on for minutes without being able to plot N.gamma.

My steam engine laptop SS 6179 runs Martin in 1.8 min.
It runs the solver 168*10= 1680 for all 10 plots
Set j=9 ... constrain gamma 0.9 reluctant
Set the solver in eval(,) mode.
Cheers ... Jean

problem_solved_Kr Sanity.sm (511kb) downloaded 8 time(s).


Calculated in about 2 seconds on the latest stable SMath Studio.

Edited by user 04 October 2020 00:35:02(UTC)  | Reason: Not specified

Offline Jean Giraud  
#16 Posted : 04 October 2020 01:57:01(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 4,782
Canada

Was thanked: 800 time(s) in 634 post(s)
Originally Posted by: Andrey Ivashov Go to Quoted Post
Calculated in about 2 seconds on the latest stable SMath Studio.

Thanks Andrey ... very impressive !
What about Julia set ? Cheers ... Jean.

Pattern Julia Set [PUBLISH].sm (173kb) downloaded 12 time(s).
Offline hanskl  
#17 Posted : 04 October 2020 02:10:04(UTC)
hanskl


Rank: Advanced Member

Groups: Registered
Joined: 25/10/2017(UTC)
Posts: 66
Norway

Was thanked: 4 time(s) in 2 post(s)
Originally Posted by: mkraska Go to Quoted Post
Originally Posted by: hanskl Go to Quoted Post

Can you help me understand understand the difference between having the quantities as explicit functions like I did and your approach, and what will the advantange/disadvantages be for one or the other? I want to try to understand the best way to structure my calculations for the result I want.

BTW, just installed the latest SMath version, what a tremendous speedup that gave on this sheet. My oldere version would go on for minutes without being able to plot N.gamma.

Thanks


I am on very thin ice when making statements on that, because it is just based on observations, not on conceptual insight.

If you define functions, these are stored as is and evaluated when the function is called. If define a variable, the expression is simplified using the current context (available definitions of variables) You can see that in the debugger window.
You always see what you store in the dynamic callout when hovering over the definition.

I know that in the end you want a quantity depending on r and rho, thus a function. Yet, inside the algorithm r and rho are fixed and not subject to change for a given call of that algorithm. So it is straightforward to use the global value of these variables throughout the algorithm, specified as arguments when calling the algorithm.



Thanks, that actually made a lot of sense! Will apply that to other sheets i have that struggle with Slow computation.

Cheers!
Offline hanskl  
#18 Posted : 04 October 2020 02:14:36(UTC)
hanskl


Rank: Advanced Member

Groups: Registered
Joined: 25/10/2017(UTC)
Posts: 66
Norway

Was thanked: 4 time(s) in 2 post(s)
Originally Posted by: Jean Giraud Go to Quoted Post
N.γ(r,ρ) should plot in ~ 30 s on modern machines.
Saved in my Project file ... any abstract about the project ?

Project Hanski Unknown.sm (514kb) downloaded 10 time(s).


The functions calculate soil bearing capacity factors for drained conditions. N.q is used internationally, but N.gamma is according to Norwegian recommendations.

Cheers.
Offline Andrey Ivashov  
#19 Posted : 04 October 2020 02:30:25(UTC)
Andrey Ivashov


Rank: Administration

Groups: Developers, Registered, Knovel Developers, Administrators, Advanced Member
Joined: 11/07/2008(UTC)
Posts: 1,426
Man
Russian Federation

Was thanked: 1681 time(s) in 566 post(s)
Originally Posted by: Jean Giraud Go to Quoted Post
Originally Posted by: Andrey Ivashov Go to Quoted Post
Calculated in about 2 seconds on the latest stable SMath Studio.

Thanks Andrey ... very impressive !
What about Julia set ? Cheers ... Jean.

Pattern Julia Set [PUBLISH].sm (173kb) downloaded 12 time(s).


55 seconds. As I see it was about 14 minutes before...
Offline hanskl  
#20 Posted : 04 October 2020 19:51:31(UTC)
hanskl


Rank: Advanced Member

Groups: Registered
Joined: 25/10/2017(UTC)
Posts: 66
Norway

Was thanked: 4 time(s) in 2 post(s)
I have tinkered a bit because there seems to be a mismatch between my graph and the diagram for some values of r and rho.

The plots of N.γ(0.9,atan(x)) and N.γ(0.95,atan(x)) has an odd shape when they approach x=1. It turns out there are some complex solutions in this area.

Is there anything to be done about this, to make the graph closer resemble the diagram?

Cheers


problem_complex.sm (261kb) downloaded 7 time(s).
Users browsing this topic
2 Pages12>
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.