Post Reply 
Problems with return value of function
06-25-2017, 02:44 PM
Post: #1
Problems with return value of function
I am starting to program the HP Prime again after a long time!
Try to start with a simple program that is running almost perfect.
See program below.
In the export function a call the subroutine Eccentricity is placed, this should give back a value of E.
It's give the value "0" back. But when I print it before the Return it has a value.
I can't understand why this is happens. Please need some help!

Thanks for any help

Code:
Eccentricity(ecc,M) ;

EXPORT KEPLER(ecc,M)
BEGIN
PRINT;  //Clear screen
LOCAL E; //Local variable
E=Eccentricity(ecc,M);
PRINT("E="+E);
HAngle:=0;
END;


Eccentricity(ecc,M)  // kepler's routine
BEGIN
LOCAL Rad2Deg,E,F,err,iter;
print("ecc = "+ecc);  //ecentricity
print("M = "+M);
HAngle:=1; //Degree mode
Rad2Deg := 180 / pi; 
//start values for iteration
E := M + (ecc * sin(M) * (1.0 + (ecc * cos(M))));
F := E - (E - (Rad2Deg * ecc * sin(E)) - M) / (1 - ecc * cos(E));
err := abs(F - E);
iter:=0;
print(err);
WHILE (err > 1e-9) DO
  iter := iter + 1;
  F := E - (E - (Rad2Deg * ecc * sin(E)) - M) / (1 - ecc * cos(E));
  err := abs (F - E);
  //print(err);
  E := F;
END;
print("iterations = "+iter);
print("E = "+E);
print("F = "+F);
RETURN E;
END;
Find all posts by this user
Quote this message in a reply
06-25-2017, 03:11 PM
Post: #2
RE: Problems with return value of function
A ":" is missing in this line: E:=Eccentricity(ecc,M);
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)