Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations SSS148 on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

GNU Octave Syntax Error- Help!

Status
Not open for further replies.

Mechomatic

Mechanical
Apr 23, 2013
50
Hello all-

I've recently installed GNU Octave 3.6.4 on my Windows XP workstation and have been plugging along smoothly on a heat transfer FEA problem. I'm getting a syntax error back from Octave but I can't understand why. Attached is a folder of the .m files needed for the script (bathdrain.m). If somebody more familiarw ith the program could point me in the right direction, I would very much appreciate it! Here's the error that Octave spits out at me:

parse error near line 104 of file C:\Program Files\Octave-3.6.4\share\octave\3.6.4\m\bathdrain.m
syntax error
>>> C(i,nodematnum(m,n+7*(o-1)))= k*2*z(m,n+7*(o-1))*dx^2/dz + k*(xu(m,n+7*(o-1))+xd(m,n+7*(o-1))+...*dx^2;

The arrow indicating where the error occurs is under the 1 shown bold and underlined.

The script is finding the temperature profile of a steel plate subjected to forced convection in cold air, free convection, and forced convection in hot water. I set up a cell array to model the mesh nodes and converted it to a matrix, then am using the cell array indices m, n, and o to map the adjacent node temperatures. In the error, matrix "nodematnum" is a matrix relating a unique index number to each actual node (empty nodes are numbered 1 and used a cell padding so that matrix indices work when running the loops to create a coefficient matrix).

I'm not sure why it's getting a syntax error on the 1, but if somebody who's more knowledgeable could set me straight, I'd appreciate it!
 
Replies continue below

Recommended for you

Problem is actually in the line before. Look closely at the parentheses in the if statement. A text editor that highlights matching parentheses makes this easier. I think there's at least one missing closing parenthesis in the if statement, and maybe a pair of them too.

In general, the syntax checker can only do so much - unmatched delimiters can send it way off the mark. When fault finding, reduce the code to the last known good state, and add in new things one at a time. Will narrow your search considerably!
 
Thank you! It was quite obviously the end of the work day on Friday when I was working on that. I appreciate the help with finding my error!
 
Of course, I turn around to fix something else and I break the script again...

"error: subscript indices must be either positive integers or logicals"

Error on line 92, col 37.

h(int8(abs(m)),int8(abs(n+7*(o-1)))) <<error here>> =h(L,check(m,n+7*(o-1)),Ts(m,n+7*(o-1)), Tinf(m,n+7*(o-1)));

I have added the int8() and abs() functions to guarantee the system was reading the indices as positive integers, but received the same error with and without those added functions. The code section is a set of nested for loops: for o=2:4, for n=2:6, and for m=2:15. These counters and indices are used elsewhere in the script with no issue. Matrix h is pre-sized as h=zeros(16,25). I inserted two lines of debugging code to see when the script breaks (displays the counters m,n,o and what they compute to (m,n+7*(o-1)) to see on what pass the code breaks and to ensure they are producing useable indices). The code breaks on the first pass at o=2,n=2,m=2 (indices show (2,9)). The script works with this problem line of code commented out, and the counters and indices run through the for loops just fine.

Thoughts on why Octave is being so problematic?
 
 http://files.engineering.com/getfile.aspx?folder=0f5335a5-fe44-49eb-8b56-722c0f7f1eb1&file=bathdrain.zip
Found my error. Note to self, don't try to name a variable the same as a function...

Thanks again for the help.
 
Note to WPratsi:

Be careful with built-ins too, like i and j. i is a common indexing variable in many languages, but all bets are off when it somehow becomes sqrt(-1).

BTW, your code (what you have shown) looks like it could probably be written in a single line, with no loops.

- Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor