Function call does not evaluate numerically inside a for() loop

Function call does not evaluate numerically inside a for() loop - Сообщения

#1 Опубликовано: 15.04.2018 03:23:52
Alexander O. Melnik

Alexander O. Melnik

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

Группа: Moderator

Good day SMath community,

I was battling this issue in my worksheet for a better part of the weekend.

I wrote a formula (biaxial bending in a column) to calculate unknown input loads based on known response. A key to practical use of the formula is to solve for unknown response based on known input loads (backwards of what formula does). I attempted to use FindRoot() with no success.

I decided to write a simple "solver" using a for() loop, which i have done many other times before. To my surprise the custom formula does not evaluate correctly inside the for() loop, while evaulating just fine outside it.

This is rather baffling. Please take a look and help - i honestly dont know what to do here - this should be a simple task which proved to be very stubborn.

Many thanks!

Файл не найден.Файл не найден.
#2 Опубликовано: 15.04.2018 06:04:10
Davide Carpi

Davide Carpi

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

Группа: Moderator

Hello Alex,

Wrote

I decided to write a simple "solver" using a for() loop, which i have done many other times before. To my surprise the custom formula does not evaluate correctly inside the for() loop, while evaulating just fine outside it.


The loop fails on i=2, where the neutral axis has a value that doesn't cross the section; looking at biaxial(2) this case is not handled (local variable #chunk not defined -> error on stress block properties calculation -> error in the loop)


Wrote

definition of xii "erased"


This is by design since SMath Studio 0.99.6622

Wrote

Calculation error happened during definition of the variable/function clears previous value of this variable/function if it is available;

If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
1 пользователям понравился этот пост
Alexander O. Melnik 15.04.2018 12:39:00
#3 Опубликовано: 15.04.2018 10:39:33
Jean Giraud

Jean Giraud

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

Группа: User

Wrote

This is rather baffling. Please take a look and help - i honestly dont know what to do here - this should be a simple task which proved to be very stubborn.


Alex, everything is OK and NOT in few points.

I worked a bit on your previous version. Now the last error "_ not defined"
The incompatibility is too deep to be isolated... % appears as a factor is
no problem for FindRoot solver. rotation° is the problem in the solver.
The function is OK in the program data*rot(,), but the solver does not solve
for (°) because the demand is for solving the argument of a function of a function..
This in Mathcad is possible via an iterative Given/Find, not directly possible in Smath.

What you can do and in fact is what you need, create a matrix of solutions from
... biaxial(°,%) ... works fine in the attached 6179

Cheers Alex ... Jean

formula[1].sm (108 КиБ) скачан 49 раз(а).

1 пользователям понравился этот пост
Alexander O. Melnik 15.04.2018 12:39:00
#4 Опубликовано: 15.04.2018 12:38:32
Alexander O. Melnik

Alexander O. Melnik

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

Группа: Moderator

Oh thank you very much Davide and Jean, now i have something to work with :-)

Jean, i entertained initially the idea of creating a matrix of solutions, but what proved to be a challenge is to interpolate the desired one from said matrix (which is a 3D surface)

Davide, so is "variable undefined" a sign that function evaluated to an error?

I managed to get my solution using a for() loop by removing the error you mentioned, but once i encapsulate said for loop in a function call the error is back

formulaR2.sm (99 КиБ) скачан 48 раз(а).
#5 Опубликовано: 15.04.2018 14:19:12
Jean Giraud

Jean Giraud

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

Группа: User

Wrote

Oh thank you very much Davide and Jean, noiw i have something to work with :-)

Jean, i entertained initially the idea of creating a matrix of solutions, but what proved to be a challenge is to interpolate the desire one from said matrix (which is a 3D surface)



Alex,
Your "self entertaining" was correct, but unfortunately up to this point,
you have a system, not a surface. Mathcad would plot nothing either.
Most probably it would generate "a critical error occured".

The last olive can be programmed for convenience.
I love projects that understand nothing but work !
I'm not a bridge maker, just a Process Control old man.

Cheers Alex ... Jean

formula[2].sm (128 КиБ) скачан 47 раз(а).


#6 Опубликовано: 15.04.2018 17:22:42
Jean Giraud

Jean Giraud

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

Группа: User

... Alex,

From this completed demo, you can:
interpolate [cinterp from sanity plots]
I tried some surface interpolation,
too small data set [4 x 3].

Jean

formula[3].sm (123 КиБ) скачан 52 раз(а).
1 пользователям понравился этот пост
Alexander O. Melnik 15.04.2018 18:33:00
#7 Опубликовано: 15.04.2018 18:36:16
Alexander O. Melnik

Alexander O. Melnik

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

Группа: Moderator

Wrote

... Alex,

From this completed demo, you can:
interpolate [cinterp from sanity plots]
I tried some surface interpolation,
too small data set [4 x 3].

Jean

formula[3].sm (123 КиБ) скачан 52 раз(а).




Hi Jean, greatly appreciate your help. In the example you developed, can you interpolate unknown values of "°" & "%" based on given values of P.z and ratio Mx/My? or find all possible values Mx and My for a known value of Pz This is what i am after. Surface defined by dots in coordinate system (PzMxMy) is an interaction diagram of column failure
#8 Опубликовано: 15.04.2018 20:26:07
Alexander O. Melnik

Alexander O. Melnik

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

Группа: Moderator

I have attempted to approach the task from a different angle - parametrically define Pz(a#,na#) Mx(a#,na#) My(a#,na#)

and solve for a# and na# by evaluating Pz, Mx, My using function at().

Function at() does not work with my definition.

Davide, why am i hitting a brick wall here?

ThanksBiaxialColumnCheck.sm (556 КиБ) скачан 56 раз(а).
#9 Опубликовано: 15.04.2018 20:57:25
Jean Giraud

Jean Giraud

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

Группа: User

Hi Jean,
1. In the example you developed, can you interpolate
unknown values of "°" & "%" based on given values of Pz and ratio Mx/My?
2. or find all possible values Mx and My for a known value of Pz.
This is what I am after.
3. Surface defined by dots in coordinate system (PzMxMy)
is an interaction diagram of column failure
================================================

1. done, perfect
2. Don't understand completely
3. up until now, does not work well [NFG !]
#10 Опубликовано: 15.04.2018 22:25:17
Jean Giraud

Jean Giraud

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

Группа: User

Wrote


1. done, perfect
2. Don't understand completely
3. up until now, does not work well [NFG !]


================================
1 & 3 done

Can you re-explain your # 2

Alex3D.sm (36 КиБ) скачан 56 раз(а).
formula[3] Copy.sm (154 КиБ) скачан 54 раз(а).

The 3D crashes the main sheet
#11 Опубликовано: 15.04.2018 22:33:19
Jean Giraud

Jean Giraud

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

Группа: User

2. or find all possible values Mx and My for a known value of Pz.
This is what I am after.
=====================================

I think it's possible
#12 Опубликовано: 15.04.2018 22:40:35
Alexander O. Melnik

Alexander O. Melnik

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

Группа: Moderator

Wrote

Wrote


1. done, perfect
2. Don't understand completely
3. up until now, does not work well [NFG !]


================================
1 & 3 done

Can you re-explain your # 2

Alex3D.sm (36 КиБ) скачан 56 раз(а).
formula[3] Copy.sm (154 КиБ) скачан 54 раз(а).

The 3D crashes the main sheet



Hi Jean, huge effort here from you - BIG thanks. Will take some time for me to digest. To make it a little easier for me can you point out where i can "interpolate unknown values of "°" & "%" based on given values of Pz and ratio Mx/My?". I know Pz, ratio of Mx/Mz and need to find "°" & "%" that correspond to it (all data is spit out by biaxial() formula).

Many Thanks!
#13 Опубликовано: 15.04.2018 23:29:52
Jean Giraud

Jean Giraud

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

Группа: User

Wrote

Hi Jean, huge effort here from you - BIG thanks. Will take some time for me to digest. To make it a little easier for me can you point out where i can "interpolate unknown values of "°"


====== will be back on that tomorrow ======

Here is the lookup wrt PzMxMy, alternately search from either col.

formula[3] Copy.sm (168 КиБ) скачан 41 раз(а).
#14 Опубликовано: 16.04.2018 01:01:37
Jean Giraud

Jean Giraud

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

Группа: User

Wrote

To make it a little easier for me can you point out where
I can "interpolate unknown values of "°"


Maybe, I didn't completely understood ?
Here is the refreshed version.

formula[3] Copy.sm (162 КиБ) скачан 44 раз(а).

#15 Опубликовано: 16.04.2018 04:32:52
Davide Carpi

Davide Carpi

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

Группа: Moderator

Wrote

I managed to get my solution using a for() loop by removing the error you mentioned, but once i encapsulate said for loop in a function call the error is back



The problem here is that when you pass to a function an argument that requires numerical evalution and the evaluation is not possible because undefined variables, the preprocessing fails (at smath level)

the workaround is to create a function that internally defines the leftside as the function that cannot be passed in argument and call your solver internally

notice eval@ inside the solver, this makes possible to use solveNR both directly (with at()) both within the wrapper function solvePcr (not sure now why at() doesn't work in both the cases, have to investigate when it will be possible)


formulaR2_rev2.sm (105 КиБ) скачан 62 раз(а).
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
1 пользователям понравился этот пост
frapuano 16.04.2018 07:52:00
#16 Опубликовано: 16.04.2018 10:57:04
Jean Giraud

Jean Giraud

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

Группа: User

Davide, Alex ... thanks for the distiller-solution.

Two points about your Newton-Raphson example:

1. Will it work for this application in traditional code ?
2. Two [2] pitfalls:
2\a. about your cubic, it is ill-posed. In maths, it is paramount
polynomials are expressed in Lagrange canonical format.
For quick getting the polyroots and set the cubic solver.
In fact, cubic may have complex roots [your example is cubic complex].
Complex solutions are essentials in modeling/solving Control Systems.

2\b. The Smath native "roots" solves directly your example.

Rev(2) most appreciated for eventual hard solving future.

rootsAccurate.PNG
Newton-Raphson.PNG

Solve roots Newton-Raphson.sm (51 КиБ) скачан 54 раз(а).
1 пользователям понравился этот пост
Alexander O. Melnik 17.04.2018 01:05:00
#17 Опубликовано: 17.04.2018 13:21:34
Alexander O. Melnik

Alexander O. Melnik

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

Группа: Moderator

investigated a few options:

1. point interpolation on a surface is tough to implement (for me)
2. Solving for na# works well (Davide's last post)
3. Solving for rotation does not work well (relationship is far from linear, solver chokes up too often - see example formulaR4.sm (220 КиБ) скачан 43 раз(а). )

My current solution is solve for na# (Davide's last post) by bracketing the rotation till desired Mx/My is achieved (not shown here)
#18 Опубликовано: 17.04.2018 14:40:12
Jean Giraud

Jean Giraud

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

Группа: User

Wrote

investigated a few options:

1. point interpolation on a surface is tough to implement (for me)
2. Solving for na# works well (Davide's last post)
3. Solving for rotation does not work well (relationship is far from linear, solver chokes up too often - see example Project_0 Biaxial SolveRotdeg.sm (105 КиБ) скачан 38 раз(а).

#19 Опубликовано: 17.04.2018 18:34:16
Jean Giraud

Jean Giraud

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

Группа: User

... suite,

by solving, simultaneously [rot°, _%], if biaxial would be an analytical f(x,y)
you can solve x<=y or vice versa y<=x. Up until now, found only one that Smath/Maple
does not solve. On the other hand, biaxial(rot°, _%) generates 3 sets of results.
The CreateMesh [not the Smath CreateMesh] can alternately scan/evaluate and tabulate
results for further use ... I'm working on that, in the mean time, if you have a good
range of each [rot°, _%] that would be nice, though easy to modify.
#20 Опубликовано: 18.04.2018 00:31:56
Jean Giraud

Jean Giraud

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

Группа: User

... suite as far as manageable.
I got lost in your last attempt !
Cheers Alex

Project_0 Biaxial SolveRotdeg.sm (140 КиБ) скачан 66 раз(а).
  • Новые сообщения Новые сообщения
  • Нет новых сообщений Нет новых сообщений