Message Boards Message Boards

0
|
10690 Views
|
9 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Get the common denominator?

Posted 7 years ago

Hello everybody,

I need your help in doing the same Denominator.

My Input:

b[i_, s_] := 
 Integrate[
  Product[Piecewise[{{1, p == i}}, (p + \[Tau])/(p - i)], {p, 0, s}], {\[Tau], 0, 1}]
MyCoeffs = Table[b[i, s], {s, 0, 4}, {i, 0, s}]

My Output:

{{1}, {3/2, -(1/2)}, {23/12, -(4/3), 5/12}, {55/24, -(59/24), 37/24, -(3/8)}, {1901/720, -(1387/360), 109/30, -(637/360), 251/720}}

Now the Problem is that Mathematica don't let it on the same Denominator. I want to have the same Denominator in each list.

In the end i want to have this

{{1},{3/2,-(1/2)},{23/12, -(16/12), 5/12}, {55/24, -(59/24), 37/24, -(9/24)}, {1901/720, -(2774/720), 2616/720, -(1274/720), 251/720}}

Thanks for your help 

Kind Regards

Zharou Fisher

POSTED BY: Zharou Fisher
9 Replies

How about using Denominator to extract the denominators in each sublist,

http://reference.wolfram.com/language/ref/Denominator.html

use LCM to find the least common denominator,

http://reference.wolfram.com/language/ref/LCM.html

and use it to convert the sublist elements to the same denominator?

POSTED BY: Frank Kampas

A little function to do this follows:

makeCommonDenominators[fractions_] := Module[{comden, numers},
  comden = LCM @@ Denominator /@ fractions;
  numers = fractions*comden;
  (HoldForm[#1/zzz] /. zzz -> comden) & /@ numers
  ]

To get the original reduced fractions back you can use

ReleaseHold /@ fractions

I hope this helps

POSTED BY: John McGee
Posted 7 years ago

Sry i didn't get it. Could you help me in more detail ?

Thanks a lot

Zharou Fisher

POSTED BY: Zharou Fisher

Try:

makeCommonDenominators /@ MyCoeffs

enter image description here

Posted 7 years ago

Thank you all for helping.

My Problem is solved. But i have a question what does this zzz mean. I didn't get it.

Would be nice if anybody could explain it.

Kind regards

Zharou Fisher

POSTED BY: Zharou Fisher
Posted 7 years ago

Thank you all for helping.

My Problem is solved. But i have a question what does this zzz mean. I didn't get it.

Would be nice if anybody could explain it.

Kind regards

Zharou Fisher

POSTED BY: Zharou Fisher
Posted 7 years ago

My Problem isn't solved sry for that reply. i got an error.

I have a problem instead.

If i do

EndCoeffs = makeCommonDenominators /@ MyCoeffs

and i want the Denominator i do

Denominator[EndCoeffs]

but all i get is:

{{1},{1,1},{1,1,1},{1,1,1,1}}

I hope someone can help me.

Kind regards

Zharou Fisher

POSTED BY: Zharou Fisher

Initializations:

b[i_, s_] := 
Integrate[
Product[Piecewise[{{1, p == i}}, (p + \[Tau])/(p - i)], {p, 0, 
s}], {\[Tau], 0, 1}]
makeCommonDenominators[fractions_] := Module[{comden, numers},
comden = LCM @@ Denominator /@ fractions;
numers = fractions*comden;
(HoldForm[#1/zzz] /. zzz -> comden) & /@ numers]
myCoeffs = Table[b[i, s], {s, 0, 4}, {i, 0, s}];
makeCommonDenominators /@ myCoeffs;

and denominators:

In[12]:= Apply[LCM, Denominator /@ Release /@ myCoeffs, {1}]
Out[12]= {1, 2, 12, 24, 720}

What about the following code?

b[i_, s_] := 
 Integrate[
  Product[Piecewise[{{1, p == i}}, (p + \[Tau])/(p - i)], {p, 0, 
    s}], {\[Tau], 0, 1}]
myCoeffs = Table[b[i, s], {s, 0, 4}, {i, 0, s}];

f[l_] := Module[{lcm},
  lcm = LCM @@@ Denominator /@ l;
  l*lcm/Defer /@ lcm]

In[7]:= f[myCoeffs]

Out[7]= {{1/1}, {3/2, -(1/2)}, {23/12, -(16/12), 5/12}, {55/
  24, -(59/24), 37/24, -(9/24)}, {1901/720, -(2774/720), 2616/
  720, -(1274/720), 251/720}}
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