Message Boards Message Boards

0
|
7702 Views
|
4 Replies
|
2 Total Likes
View groups...
Share
Share this post:

[?] Avoid division by zero?

Posted 7 years ago

Hello, I have two lists

p={2,5,-6,8,3}

and

q ={3,-4,0,5,0}

I want to get the list

p/q = {2/3,5/-4,8/5}

which is obtained by dividing elements of p by elements of q one by one avoiding division by zeros. Code p/q yields

"infinite expression 1/0 encountered"

Please help. Thanks and regards

POSTED BY: jagannath debata
4 Replies

Hello Frank, Thanks a lot. It helped me write a code for simplex method in OR.

POSTED BY: jagannath debata
Divide @@@ Pick[Transpose[{p, q}], Unitize@q, 1]
POSTED BY: Kuba Podkalicki

Elegant !

POSTED BY: Roman Pohorecki
p = {2, 5, -6, 8, 3}; q = {3, -4, 0, 5, 0};

Off[Power::infy]

Select[p/q, NumberQ[#] &]

{2/3, -(5/4), 8/5}
POSTED BY: Frank Kampas
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract