Page 1 of 1

replace variables in a bunch of systems

Posted: Thu Dec 08, 2016 7:46 am
by 309blank
What I have is a bunch of equation systems, and in order to clean them up and correct a consistent error in all of them I have written the following bit of code:

Code: Select all

for %sys {%system_list_3f} svector equations = {%sys}.@svectornb 'The lines of the system are here 'Create a temporary system for safety reasons system tempsys for !x=1 to (@rows(equations)) %equation = equations(!x) for !y=1 to (@wcount(%eq_3f_or)) 'replace the wrong parts of the equations %equation = @replace(%equation, @word(%eq_3f_or, !y), @word(%eq_3f_re, !y)) next 'append the corrected to tempsys tempsys.append {%equation} next {%sys}.@svectornb = tempsys.@svectornb next
Basically what it does is replace a bunch of expressions everywhere they occur in the equations, but I can't assign the correct equations to the original eq systems. How should I do that? Should I overwrite the systems completely because I will have to reestimate them anyways?

best regards,

Re: replace variables in a bunch of systems

Posted: Thu Dec 08, 2016 8:21 am
by 309blank
alright, I just went with the absolute tabula rasa method (obviously not before a backup), and this seems to work even if it's not very elegant:

Code: Select all

for %sys {%system_list_3f} svector equations = {%sys}.@svectornb 'The lines of the system are here %command = {%sys}.@command'The command to estimate the system delete {%sys} 'delete the original system 'Create a temporary system for safety reasons system tempsys system {%sys} for !x=1 to (@rows(equations)) %equation = equations(!x) for !y=1 to (@wcount(%eq_3f_or)) 'replace the wrong parts of the equations %equation = @replace(%equation, @word(%eq_3f_or, !y), @word(%eq_3f_re, !y)) next 'append the corrected to tempsys tempsys.append {%equation} {%sys}.append {%equation} next {%sys}.{%command} next