Include Hook Sections

Include Hook Sections - Redfine variables with hooks - Messages

#1 Posted: 5/29/2013 2:23:33 PM
sublim21

sublim21

3 likes in 36 posts.

Group: User

Heya,

so here's my suggestion - hooked sections.

The idea is this,

lets say i have a section in a smath sheet

a:=5
b:=10

c:=a+b


what i'd like to do, is insert a 'hook' prior to this section


a:=5
b:=10

c:=a+b



so right now

c=15

what i'd like to do, is be able to call the hook section, with a:=9

hook1(a:9) -> c=19

the reason im suggesting this concept, is that sometimes, i'll write a section
that displays the information very nicely, but then i need to loop over the section with different variables.

This results in messy looking functions and loops, that i feel detract from the readability of the sheet.

By using hooked sections, i can display my methodology nicely, and still loop over the section with different variables.


I hope i've explained the concept well enough.

-Pete
#2 Posted: 5/29/2013 2:41:41 PM
Oscar Campo

Oscar Campo

124 likes in 298 posts.

Group: Moderator

Wrote



a:=5
b:=10
c:=a+b


so right now
c=15

what i'd like to do, is be able to call the hook section, with a:=9

hook1(a:9) -> c=19



In SMath you can define c as a function:

[MATH]a:5[/MATH]

[MATH]b:10[/MATH]

[MATH]c(a;b):a+b[/MATH]

[MATH]c(a;b)=15[/MATH]

[MATH]a:9[/MATH]

[MATH]c(a;b)=19[/MATH]

Regards,

Oscar
#3 Posted: 5/29/2013 3:11:04 PM
Martin Kraska

Martin Kraska

1222 likes in 2150 posts.

Group: Moderator

In fact, you even do not need a function, just symbolic expressions. If you re-define the independent variables, then just display the dependent ones again. There is no need to repeat the definitions, as would be required in most programming languages. In the example you can change the ODE coefficients without having them in the parameter list of D.

The odd thing is that this works only if D is defined with numeric optimization. Then the symbolic dependence is retained. If you use symbolic optimization, then the current (at definition time) values are hardwired and later changes do not have any effect.
lorenz symbolic.PNG
Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
  • New Posts New Posts
  • No New Posts No New Posts