Division by Zero Error

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Division by Zero Error

Richmond Mathewson via use-livecode
I often find that I have to deal with a division by zero error message in plotting functions, solving equation etc. Are there methods or techniques used to programmatically handle or work-around a possible division by zero? e.g. If I want to evaluate y= 1/(x-3), what can I do to deal with a possible x=3 situation?

Thanks for your help,

Roger
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Division by Zero Error

Richmond Mathewson via use-livecode
Usually, I can predict that a numerator is going to be 0, e.g. in
1/(x^2). I just check the value of the numerator before doing the division.

In rare cases, I can't predict the value of the numerator. In those
cases, I put a try control structure around the offending lines and some
code to clean up after the "final" line.

Kind regards,

Mark Schonewille
http://economy-x-talk.com
https://www.facebook.com/marksch

Buy the most extensive book on the
LiveCode language:
http://livecodebeginner.economy-x-talk.com

Op 08-Jul-17 om 05:35 schreef Roger Guay via use-livecode:

> I often find that I have to deal with a division by zero error message in plotting functions, solving equation etc. Are there methods or techniques used to programmatically handle or work-around a possible division by zero? e.g. If I want to evaluate y= 1/(x-3), what can I do to deal with a possible x=3 situation?
>
> Thanks for your help,
>
> Roger
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Division by Zero Error

Richmond Mathewson via use-livecode
oh! denominator!

Kind regards,

Mark Schonewille
http://economy-x-talk.com
https://www.facebook.com/marksch

Buy the most extensive book on the
LiveCode language:
http://livecodebeginner.economy-x-talk.com

Op 08-Jul-17 om 09:03 schreef Mark Schonewille:

> Usually, I can predict that a numerator is going to be 0, e.g. in
> 1/(x^2). I just check the value of the numerator before doing the division.
>
> In rare cases, I can't predict the value of the numerator. In those
> cases, I put a try control structure around the offending lines and some
> code to clean up after the "final" line.
>
> Kind regards,
>
> Mark Schonewille
> http://economy-x-talk.com
> https://www.facebook.com/marksch
>
> Buy the most extensive book on the
> LiveCode language:
> http://livecodebeginner.economy-x-talk.com
>
> Op 08-Jul-17 om 05:35 schreef Roger Guay via use-livecode:
>> I often find that I have to deal with a division by zero error message
>> in plotting functions, solving equation etc. Are there methods or
>> techniques used to programmatically handle or work-around a possible
>> division by zero? e.g. If I want to evaluate y= 1/(x-3), what can I do
>> to deal with a possible x=3 situation?
>>
>> Thanks for your help,
>>
>> Roger
>> _______________________________________________
>> use-livecode mailing list
>> [hidden email]
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Division by Zero Error

Richmond Mathewson via use-livecode
In reply to this post by Richmond Mathewson via use-livecode
-- d0 is what you judge as "is at about zero" for your input
-- select it such in size, that you don't get an "overflow" or
-- such that 1/d0 is your max ± vertical plot value (= clipping)

function f3 x
   local d0=0.001
   if abs(x-3) < d0 then
      return empty -- don't plot in case of an empty return
   else return 1/(x-3)
end f3


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Division by Zero Error

Richmond Mathewson via use-livecode
I use the try/catch/finally method mark mentions if there is a chance of
divide by 0 errors.  That way, no need to predict, just try it, and if
theres an error, respond accordingly.

On Sat, Jul 8, 2017 at 1:08 AM, hh via use-livecode <
[hidden email]> wrote:

> -- d0 is what you judge as "is at about zero" for your input
> -- select it such in size, that you don't get an "overflow" or
> -- such that 1/d0 is your max ± vertical plot value (= clipping)
>
> function f3 x
>    local d0=0.001
>    if abs(x-3) < d0 then
>       return empty -- don't plot in case of an empty return
>    else return 1/(x-3)
> end f3
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Division by Zero Error

Richmond Mathewson via use-livecode
Thanks very much Mark, Herman and Mike. I am using the try/catch method you mention, but it doesn’t seem to work reliably. I’m probably doing something else wrong . . . I’ll keep trying. Thanks again for your time.

Roger
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Division by Zero Error

Richmond Mathewson via use-livecode
On 07/08/2017 08:26 AM, Roger Guay via use-livecode wrote:
> I am using the try/catch method you mention, but it doesn’t seem to work reliably.

That's a bit disturbing. Can you post your code?

--
  Mark Wieder
  [hidden email]

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Division by Zero Error

Richmond Mathewson via use-livecode
Yes, but first let me play with it to see if I am doing something else to cause my problem.

Roger

> On Jul 8, 2017, at 10:42 AM, Mark Wieder via use-livecode <[hidden email]> wrote:
>
> On 07/08/2017 08:26 AM, Roger Guay via use-livecode wrote:
>> I am using the try/catch method you mention, but it doesn’t seem to work reliably.
>
> That's a bit disturbing. Can you post your code?
>
> --
> Mark Wieder
> [hidden email]
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Division by Zero Error

Richmond Mathewson via use-livecode
try
-- some code here
catch theError
breakpoint
end try

see what theError contains.

Bob S


> On Jul 9, 2017, at 08:00 , Roger Guay via use-livecode <[hidden email]> wrote:
>
> Yes, but first let me play with it to see if I am doing something else to cause my problem.
>
> Roger


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Loading...