Local variable problem

Local variable problem - Сообщения

#1 Опубликовано: 01.03.2019 19:30:46
Alvaro Diaz Falconi

Alvaro Diaz Falconi

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

Группа: User

Hi. It's seems to me that here a in the f body isn't local:

Clipboard01.gif

Are the yellow correct?

Best regards.
Alvaro.
1 пользователям понравился этот пост
sergio 02.03.2019 06:35:00
#2 Опубликовано: 01.03.2019 20:44:00
Jean Giraud

Jean Giraud

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

Группа: User

Wrote

Are the yellow correct ?


Yes and NO ... a:=Clear(a)=1 ... =1 is logical Yes
Smath Clear(,) does not evaporate from the kernel like Mathcad 11 equivalent.
It may clear a function, why because if you want to redefine f(a,x):=a*x
it is only necessary to re-assign the RHS.
Past SS 6179 can't tell behaviour .

Clear(a).PNG
#3 Опубликовано: 04.03.2019 11:45:17
Davide Carpi

Davide Carpi

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

Группа: Moderator

Yes it is correct... from the arguments you have x=a, then defining a=3 makes the return value: 3*x=3*(3*a)=3*(3*3)=27

if "a=value" is defined before calling the function the value is passed, hence "x=value" is what is known inside the function; then Clear(a) act to avoid the use of global "value" when you use "a" inside the function.

If "a" is not defined before calling the function, then "x=a" is what is known inside the function and Clear(a) clears nothing (a is not defined -> nothing to clear). This means even that if you add a:5 after a:3, then when x is calculated at the end of the function 5 will be the value used.

Note that Clear() is not always needed. You need it if inside the function you need an unknown named in that way for symbolic calculations or either that name is used to build a local matrix whereas already exists a global matrix.
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
1 пользователям понравился этот пост
sergio 04.03.2019 14:38:00
#4 Опубликовано: 04.03.2019 15:47:10
Jean Giraud

Jean Giraud

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

Группа: User

Not easy to explain more generally, in fact Clear(,) is not needed
as does nothing, i.e: it does not evaporate the demand.
The great advantage of Smath is the fact that results are stored in
vector. When opening a work sheet that takes long time to calculate
results are there for quick copying result. Also useful for versions
not backward compatible as it has stored and saved results that can
re-used as is from copy/paste.
Explain from attached demo:
In the attached, there are 4 examples of fitting data sets.
Observe carefully the lengths of the model vector functions
lengths: 2, 3, 4, 3 ... the 3, 4, 3 are compatible even if
the last 3 is shorter than 4 because 3 already exists and they
don't care length 2
Now, if we disable/delete the first example length [2] thus having
3, 4, 3 we can't recover 3 ,4 ,3 ,2 and there is no way to
recover the fit of model 2
Differently, Mathcad that is a scalar CAS, compared to Smath
a vector CAS ... Mathcad wouldn't care and would solve the
examples lengths 3, 4, 3, 2

GenfitLinfit.sm (64 КиБ) скачан 42 раз(а).
#5 Опубликовано: 04.03.2019 18:23:23
Alvaro Diaz Falconi

Alvaro Diaz Falconi

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

Группа: User

Hi Davide. So, there are not way to declare a variable as local in SMath, and we need to use some decoration for the variables inside the body of a function.

local.sm (3 КиБ) скачан 39 раз(а).
local.gif
Best regards.
Alvaro.
#6 Опубликовано: 04.03.2019 19:44:08
Jean Giraud

Jean Giraud

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

Группа: User

Wrote

So, there are not way to declare a variable as local in SMath



That's right, only function can be declared local.
Range series summation is the most known example.
Jean

#7 Опубликовано: 05.03.2019 00:55:27
Jean Giraud

Jean Giraud

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

Группа: User

Wrote

Range series summation is the most known example.


... like in this document.

Spline De Boor [Colibri].sm (35 КиБ) скачан 53 раз(а).

#8 Опубликовано: 05.03.2019 04:55:42
Davide Carpi

Davide Carpi

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

Группа: Moderator

Wrote

Hi Davide. So, there are not way to declare a variable as local in SMath, and we need to use some decoration for the variables inside the body of a function.



You can use a decoration for local variables to minimize conflicts. However it is actually possible to avoid them completely; the trick to expose a variable from the input to the output is to "create and destroy" the local variables without using the input argument, then once locals are cleared you can use the input.

33.png

or in another way:

16.png
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
4 пользователям понравился этот пост
Alvaro Diaz Falconi 05.03.2019 05:33:00, Martin_B 05.03.2019 07:16:00, frapuano 05.03.2019 14:39:00, sergio 05.03.2019 16:06:00
#9 Опубликовано: 05.03.2019 05:35:55
Alvaro Diaz Falconi

Alvaro Diaz Falconi

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

Группа: User

Hi Davide. Thanks very much for show how to isolate completely a procedure in SMath. Both techniques looks good.
Best regards.
Alvaro.

  • Новые сообщения Новые сообщения
  • Нет новых сообщений Нет новых сообщений