[Tutor] leastsquares.py

Jason Child jasonchild at cnsp.com
Wed Dec 29 20:17:30 CET 2004


mdcooper wrote:

>Hello all,
>
>I am trying to use a least squares method (the one written by Konrad Hinsen), 
>but I do not want the method to be able to generate negative values. Is there 
>a way to stop least squares programs from doing so?
>
>I have probably not included enough information but I am not sure what people 
>need so I will wait for a response.
>
>Thanks,
>
>Matt
>mdcooper at uvic dot ca
>
>
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>  
>
i seem to recal a recent thread about this....

the short answer (imo):

check for negitive values in the output:

##############################
if output < 0:                                       #is it a neg num?
    print 'err: output would be negitive!' #if so, then display some 
sort of error msg
else:                                                    #otherwise its 
a valid value
    print str(output)                               #and we convert to a 
string and display
##############################


now, I am not sure what you are doing with the code, or what it looks 
like. a simple if check should let you do something with negitive 
numbers (at the least show an err msg). I guess another (retarded) 
option would be to abs(output) and get the non-signed version (if abs() 
is the absolute-value func...never used it myself)....

-- 
Jason Christopher Child

Computer Network Service Professionals
VOZ Online



More information about the Tutor mailing list