Local variable problem

Local variable problem - Poruke

#1 Objavljeno: 1. 3. 2019. 19:30:46
Alvaro

Alvaro

1.139 svidjanja u 1.805 postova.

Grupa: 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 korisnika je svidelo ovu objavu
sergio 2. 3. 2019. 06:35:00
#2 Objavljeno: 1. 3. 2019. 20:44:00
Jean Giraud

Jean Giraud

983 svidjanja u 6.866 postova.

Grupa: 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 Objavljeno: 4. 3. 2019. 11:45:17
Davide Carpi

Davide Carpi

1.444 svidjanja u 2.936 postova.

Grupa: 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 korisnika je svidelo ovu objavu
sergio 4. 3. 2019. 14:38:00
#4 Objavljeno: 4. 3. 2019. 15:47:10
Jean Giraud

Jean Giraud

983 svidjanja u 6.866 postova.

Grupa: 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,37 KiB) preuzeto 1432 put(ova).
#5 Objavljeno: 4. 3. 2019. 18:23:23
Alvaro

Alvaro

1.139 svidjanja u 1.805 postova.

Grupa: 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,88 KiB) preuzeto 1478 put(ova).
local.gif
Best regards.
Alvaro.
#6 Objavljeno: 4. 3. 2019. 19:44:08
Jean Giraud

Jean Giraud

983 svidjanja u 6.866 postova.

Grupa: 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 Objavljeno: 5. 3. 2019. 00:55:27
Jean Giraud

Jean Giraud

983 svidjanja u 6.866 postova.

Grupa: User

Wrote

Range series summation is the most known example.


... like in this document.

Spline De Boor [Colibri].sm (35,35 KiB) preuzeto 1238 put(ova).

#8 Objavljeno: 5. 3. 2019. 04:55:42
Davide Carpi

Davide Carpi

1.444 svidjanja u 2.936 postova.

Grupa: 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 korisnika je svidelo ovu objavu
Alvaro 5. 3. 2019. 05:33:00, Martin_B 5. 3. 2019. 07:16:00, frapuano 5. 3. 2019. 14:39:00, sergio 5. 3. 2019. 16:06:00
#9 Objavljeno: 5. 3. 2019. 05:35:55
Alvaro

Alvaro

1.139 svidjanja u 1.805 postova.

Grupa: User

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

  • Novi postovi
  • Nema novih postova