Creating an equation from strings

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt

donihue
Posts: 135
Joined: Wed Oct 07, 2009 8:51 am

Creating an equation from strings

Postby donihue » Mon Dec 05, 2011 12:01 pm

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

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13305
Joined: Tue Sep 16, 2008 5:38 pm

Re: Creating an equation from strings

Postby EViews Gareth » Mon Dec 05, 2011 12:19 pm

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.
Follow us on Twitter @IHSEViews

donihue
Posts: 135
Joined: Wed Oct 07, 2009 8:51 am

Re: Creating an equation from strings

Postby donihue » Mon Dec 05, 2011 1:59 pm

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


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 33 guests