Liberty BASIC Community Forum
« Syntax error »

Welcome Guest. Please Login or Register.
Sep 21st, 2017, 7:55pm


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Syntax error  (Read 247 times)
bencooper
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 3
xx Syntax error
« Thread started on: Oct 21st, 2015, 05:45am »

I have struggled to find why I have a syntax error toward the end of this coding, variable y2 (but not y1 and x1). Please identify my obvious error!

Code:
'CirclInt -circle-line intersection algorithm by solution of quadratic equation
'-    Circle, centre a,b and radius r has the equation (x-a)^2 +(y-b)^2=r^2    ……………. 1
'-    Line, gradient s through c,d has the equation (y-d) = (x-c)*s, or x=(y-d)/s  + c ……. 2
'Substituting 2 in 1,
'((y-d)/s+c-a)^2 +y^2-2yb+b^2=r^2                     …………….  multiply by s^2
'((y-d) +s(c-a))^2 +s^2.y^2 - 2ybs^2=(r^2-b^2)s^2   …………..  e= s(c-a)-d           'simplify equation
'y^2 +2ye+e^2 +y^2s^2 -2ybs^2 -(r^2-b^2)=0
'y^2(1+s^2) +y(2e-2bs^2) -(r^2-b^2)=0          ……ditto      f= (1+s^2),  g=2*(e-b*s^2),  h=-(r^2-b^2)*s^2    'simplify equation
a=0                 'test data input from Main Program - a is x coord of the line
b=0                 'b is the y coordinate of the line
s1=1                's1 is the slope of the line - if slope is vertical ie infinite
                    'value, program to set to 9999 at data input stage and the subroutine
                    'will automatically detect and deal with evaluation of coords.
c=4                 'Easting of circle centre
d=4                 'Northing of circle centre
r=1                 'radius of circle
GOSUB [CirclInt]
LET e=s(c-a)-d
LET f=(1+s^2)
LET g=2*(e-b*s^2)
LET h= (b^2-r^2)*s^2
If (g^2-4*f*h) >0 THEN GOTO 10            'real roots
If (g^2-4*f*h) <0 THEN GOTO 5             'imaginary roots
Print "Singular roots - line tangential"   ' =0, therefor Single root (but what if not zero, due to rounding errors?)
Flag=1
GOTO 10                                     ' - need to develop error trap routine for all similar
5 Print "CirclInt - No Solution"           'show which routine error occurs!
Goto 20
10 y1=(-g(g^2-4*f*h)^0.5)/(2*f)
x1= (y1-d)/s
If Flag=1 THEN GOTO 20                     'Single root
y2 =(-g-(g^2-4*f*h)^0.5)/(2*f)             'CAN'T UNDERSTAND SYNTAX ERROR HERE?
x2= (y2-d)/s +c
20 Stop                'stop only for testing
Return 

« Last Edit: Oct 23rd, 2015, 3:52pm by Stefan Pendl » User IP Logged

tsh73
Board Moderator

member is offline

Avatar

Anatoly (real name)


PM

Gender: Male
Posts: 1681
xx Re: Syntax error
« Reply #1 on: Oct 21st, 2015, 07:56am »

LB does not allow "-g"
You can write "0-g" or "-1*g"
User IP Logged

damned Dog in the Manger
G. Rahman
Guru
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 1145
xx Re: Syntax error
« Reply #2 on: Oct 21st, 2015, 11:38am »



and (0-g(blah blah) .... and so on .....

?

g() is a function or an array.

Gordon
User IP Logged

Gordon Rahman

http://www.libertybasic.nl
bencooper
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 3
xx Re: Syntax error
« Reply #3 on: Oct 22nd, 2015, 05:41am »

Thanks Anatoli - quite unusual, but now I recall reading that somewhere (g is a variable).
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls