Include Hook Sections

Include Hook Sections - Redfine variables with hooks - 消息

#1 已发布: 2013/5/29 14:23:33
sublim21

sublim21

3个赞,共36个帖子。

组: 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 已发布: 2013/5/29 14:41:41
Oscar Campo

Oscar Campo

135个赞,共309个帖子。

组: 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 已发布: 2013/5/29 15:11:04
Martin Kraska

Martin Kraska

1,362个赞,共2,276个帖子。

组: 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
Technische Mechanik mit SMath Studio: https://link.springer.com/book/10.1007/978-3-658-50592-9
  • 有新帖
  • 无新帖