Page 1 of 1

Creating an equation from strings

Posted: Mon Dec 05, 2011 12:01 pm
by donihue
Hello,
I would like to create a simulation model from equations generated using matrices of coefficients obtained from Matlab through xget, but am unsure of the syntax to use.

I naively tried the following
' create model from dr.ghx and dr.ghu
model mod1
%eq = " "
%eq = %eq + "+" + dr_ghx(1,1) + "*" + "r(-1)" + "+" + dr_ghx(1,2) + "*" + "pi(-1)" "+" + dr_ghx(1,3) + "*" + "y(-1)" "+" + dr_ghu(1,1) + "*" + "eas" "+" + dr_ghu(1,2) + "*" + "eis" "+" + dr_ghu(1,3) + "*" + "emp"
%eq = "r =" + %eq
mod1.append %eq
but it failed, with the error message
%EQ is not defined or is an illegal command in "%EQ = " " + "+" + DR_GHX(1,1) + "*" + "R(-1)" + "+" + DR_GHX(1,2) + "*" + "PI(-1 ...
Could someone help with the correct syntax, please?

Thanks and regards
Donihue

Re: Creating an equation from strings

Posted: Mon Dec 05, 2011 12:19 pm
by EViews Gareth
Your idea is right, your execution is not :D

You're missing a bunch of pluses in your definition. For example, you currently have:

Code: Select all

"pi(-1)" "+"
when you probably want:

Code: Select all

"pi(-1)" + "+"
or:

Code: Select all

"pi(-1) +"
Also, you don't mention what DR_GHX and DR_GHU are. If they're matrices, then you probably want to put @str around them to convert the elements into strings.

Re: Creating an equation from strings

Posted: Mon Dec 05, 2011 1:59 pm
by donihue
Thanks very much, Gareth, for catching those silly errors. Also, I had not realised that I needed to use the "@str" syntax. I have corrected and it runs pefectly now.
Regards
Donihue