Skip to main content
deleted 105 characters in body
Source Link
Mr.Wizard
  • 275.5k
  • 35
  • 608
  • 1.5k

Suppose I have an expression of the this type:

Quantity["Epsilonzero"]  a (b + c Sin[\[Omega]Sin[ω t])^2

where t is time. I am interested in "extracting" the non time-dipendent part. I can expand the expression to show the time dependent terms:

Expand[%]
mysum = TrigReduce[%]

and obtain for mysum

a c^2 Cos[2 t \[Omega]]ω] (Quantity[-(1/2), "ElectricConstant"]) + 
a b c Cos[t \[Omega]]ω] (Quantity[-I, "ElectricConstant"]) + 
a b c Cos[t \[Omega]]ω] (Quantity[I, "ElectricConstant"]) + 
a c^2 (Quantity[1/2, "ElectricConstant"]) + 
a b^2 (Quantity[1, "ElectricConstant"]) + 
a b c (Quantity[2, "ElectricConstant"]) Sin[t \[Omega]]ω] + 
a c^2 (Quantity[-(I/4), "ElectricConstant"]) Sin[2 t \[Omega]]ω] + 
a c^2 (Quantity[I/4, "ElectricConstant"]) Sin[2 t \[Omega]]ω]

Now I want only the terms that do not contain any dependence on t. I could do:

mysum /. {Cos[t \[Omega]]ω] -> 0, Cos[2 t \[Omega]]ω] -> 0, Sin[t ω] -> 0, Sin[2 t ω] -> 0}

Sin[t [Omega]] -> 0, Sin[2 t [Omega]] -> 0}

But because of the presence of Quantity[1, "ElectricConstant"], I get:

 b c (Quantity[0, "ElectricConstant"]) + 
 a c^2 (Quantity[0, "ElectricConstant"]) + 
 a c^2 (Quantity[1/2, "ElectricConstant"]) + 
 a b^2 (Quantity[1, "ElectricConstant"])

i.e., the terms that are effectively 0 are not dropped.

I could also do:

Collect[mysum, {Cos[t \[Omega]]ω], Cos[2 t \[Omega]]ω], Sin[t \[Omega]]ω], Sin[2 t \[Omega]]ω]}]

and then just pick out the terms of the sum that do not contain the unwanted terms. However, the order in which these terms appear is dependent on the exact form of the original expression, so I'd have to adjust them on a case-by-case basis.

Any other idea? The only thing I came out with so far (and it's not too bad) is to replace Quantity["Epsilonzero"] in the original expression with a normal symbol (not a Quantity), and only put the quantity back in place later.

Suppose I have an expression of the this type:

Quantity["Epsilonzero"]  a (b + c Sin[\[Omega] t])^2

where t is time. I am interested in "extracting" the non time-dipendent part. I can expand the expression to show the time dependent terms:

Expand[%]
mysum = TrigReduce[%]

and obtain for mysum

a c^2 Cos[2 t \[Omega]] (Quantity[-(1/2), "ElectricConstant"]) + 
a b c Cos[t \[Omega]] (Quantity[-I, "ElectricConstant"]) + 
a b c Cos[t \[Omega]] (Quantity[I, "ElectricConstant"]) + 
a c^2 (Quantity[1/2, "ElectricConstant"]) + 
a b^2 (Quantity[1, "ElectricConstant"]) + 
a b c (Quantity[2, "ElectricConstant"]) Sin[t \[Omega]] + 
a c^2 (Quantity[-(I/4), "ElectricConstant"]) Sin[2 t \[Omega]] + 
a c^2 (Quantity[I/4, "ElectricConstant"]) Sin[2 t \[Omega]]

Now I want only the terms that do not contain any dependence on t. I could do:

mysum/. {Cos[t \[Omega]] -> 0, Cos[2 t \[Omega]] -> 0, 

Sin[t [Omega]] -> 0, Sin[2 t [Omega]] -> 0}

But because of the presence of Quantity[1, "ElectricConstant"], I get:

 b c (Quantity[0, "ElectricConstant"]) + 
 a c^2 (Quantity[0, "ElectricConstant"]) + 
 a c^2 (Quantity[1/2, "ElectricConstant"]) + 
 a b^2 (Quantity[1, "ElectricConstant"])

i.e., the terms that are effectively 0 are not dropped.

I could also do:

Collect[mysum, {Cos[t \[Omega]], Cos[2 t \[Omega]], Sin[t \[Omega]], Sin[2 t \[Omega]]}]

and then just pick out the terms of the sum that do not contain the unwanted terms. However, the order in which these terms appear is dependent on the exact form of the original expression, so I'd have to adjust them on a case-by-case basis.

Any other idea? The only thing I came out with so far (and it's not too bad) is to replace Quantity["Epsilonzero"] in the original expression with a normal symbol (not a Quantity), and only put the quantity back in place later.

Suppose I have an expression of the this type:

Quantity["Epsilonzero"]  a (b + c Sin[ω t])^2

where t is time. I am interested in "extracting" the non time-dipendent part. I can expand the expression to show the time dependent terms:

Expand[%]
mysum = TrigReduce[%]

and obtain for mysum

a c^2 Cos[2 t ω] (Quantity[-(1/2), "ElectricConstant"]) + 
a b c Cos[t ω] (Quantity[-I, "ElectricConstant"]) + 
a b c Cos[t ω] (Quantity[I, "ElectricConstant"]) + 
a c^2 (Quantity[1/2, "ElectricConstant"]) + 
a b^2 (Quantity[1, "ElectricConstant"]) + 
a b c (Quantity[2, "ElectricConstant"]) Sin[t ω] + 
a c^2 (Quantity[-(I/4), "ElectricConstant"]) Sin[2 t ω] + 
a c^2 (Quantity[I/4, "ElectricConstant"]) Sin[2 t ω]

Now I want only the terms that do not contain any dependence on t. I could do:

mysum /. {Cos[t ω] -> 0, Cos[2 t ω] -> 0, Sin[t ω] -> 0, Sin[2 t ω] -> 0}

But because of the presence of Quantity[1, "ElectricConstant"], I get:

 b c (Quantity[0, "ElectricConstant"]) + 
 a c^2 (Quantity[0, "ElectricConstant"]) + 
 a c^2 (Quantity[1/2, "ElectricConstant"]) + 
 a b^2 (Quantity[1, "ElectricConstant"])

i.e., the terms that are effectively 0 are not dropped.

I could also do:

Collect[mysum, {Cos[t ω], Cos[2 t ω], Sin[t ω], Sin[2 t ω]}]

and then just pick out the terms of the sum that do not contain the unwanted terms. However, the order in which these terms appear is dependent on the exact form of the original expression, so I'd have to adjust them on a case-by-case basis.

Any other idea? The only thing I came out with so far (and it's not too bad) is to replace Quantity["Epsilonzero"] in the original expression with a normal symbol (not a Quantity), and only put the quantity back in place later.

Post Reopened by Mr.Wizard
added 535 characters in body
Source Link

this may be a stupid question, but I can't find my way around it. (andSuppose I have searchedan expression of the forum for a similar issue, but with no luck...)this type:

Quantity["Epsilonzero"]  a (b + c Sin[\[Omega] t])^2

I have a sum (let's call it mysum) of many terms. Some of them contains the expressions Sin[w t] and Cos[w t] (for context, herewhere t is time). The sum uses Units. Since I'm onlyI am interested in "extracting" the non-time time-varyingdipendent part of the sum,. I would likecan expand the expression to drop allshow the time dependent terms involving:

Expand[%]
mysum = TrigReduce[%]

and obtain for mysum

a c^2 Cos[2 t \[Omega]] (Quantity[-(1/2), "ElectricConstant"]) + 
a b c Cos[t \[Omega]] (Quantity[-I, "ElectricConstant"]) + 
a b c Cos[t \[Omega]] (Quantity[I, "ElectricConstant"]) + 
a c^2 (Quantity[1/2, "ElectricConstant"]) + 
a b^2 (Quantity[1, "ElectricConstant"]) + 
a b c (Quantity[2, "ElectricConstant"]) Sin[t \[Omega]] + 
a c^2 (Quantity[-(I/4), "ElectricConstant"]) Sin[2 t \[Omega]] + 
a c^2 (Quantity[I/4, "ElectricConstant"]) Sin[2 t \[Omega]]

Now I want only the aforementioned expressionsterms that do not contain any dependence on t. I haven't found an elegant way tocould do this. These are the strategies that got me closer:

mysum/. {Sin[wCos[t t]\[Omega]] -> 0, Cos[wCos[2 t]t \[Omega]] -> 0}, 

UnfortunatelySin[t [Omega]] -> 0, Sin[2 t [Omega]] -> 0}

But because of the presence of Quantity[1, "ElectricConstant"], I get:

 b c (Quantity[0, "ElectricConstant"]) + 
 a c^2 (Quantity[0, "ElectricConstant"]) + 
 a c^2 (Quantity[1/2, "ElectricConstant"]) + 
 a b^2 (Quantity[1, "ElectricConstant"])

i.e., the terms containing zerothat are effectively 0 are not dropped. 

I think it has tocould also do with units (for example they contain terms like (0 epsilonzero), that is clearly zero, but Mathematica does not drop for some reason.:

Collect[mysum, {Sin[wCos[t t]\[Omega]], Cos[wCos[2 t]}]
%[[{1t \[Omega]], 3Sin[t \[Omega]], Sin[2 t \[Omega]]}]]]

Where {1, 3} areand then just used as examples here. In fact, this is the problem. The above works, butpick out the positionterms of the terms involvingsum that do not contain the unwanted expressions dependsterms. However, the order in which these terms appear is dependent on the specificexact form of mythe original formexpression, so II'd have to select indexesadjust them on a case-by-case basis.

mysum/.{Sin[w t] -> removeme, Cos[w t] -> removeme}
Collect[%, removeme]
%[[;; -2]]

This works, butAny other idea? The only in the case in which none of the unwanted expressions existthing I came out with so far (and it's not too bad) is to replace Quantity["Epsilonzero"] in the original sum. Plusexpression with a normal symbol (not a Quantity), it doesn't really look elegantand only put the quantity back in place later.

Any suggestions?

this may be a stupid question, but I can't find my way around it. (and I have searched the forum for a similar issue, but with no luck...)

I have a sum (let's call it mysum) of many terms. Some of them contains the expressions Sin[w t] and Cos[w t] (for context, here t is time). The sum uses Units. Since I'm only interested in the non-time-varying part of the sum, I would like to drop all the terms involving the aforementioned expressions. I haven't found an elegant way to do this. These are the strategies that got me closer:

mysum/.{Sin[w t] -> 0, Cos[w t] -> 0}

Unfortunately, the terms containing zero are not dropped. I think it has to do with units (for example they contain terms like (0 epsilonzero), that is clearly zero, but Mathematica does not drop for some reason.

Collect[mysum, {Sin[w t], Cos[w t]}]
%[[{1, 3}]]

Where {1, 3} are just used as examples here. In fact, this is the problem. The above works, but the position of the terms involving the unwanted expressions depends on the specific form of my original form, so I have to select indexes on a case-by-case basis.

mysum/.{Sin[w t] -> removeme, Cos[w t] -> removeme}
Collect[%, removeme]
%[[;; -2]]

This works, but only in the case in which none of the unwanted expressions exist in the original sum. Plus, it doesn't really look elegant.

Any suggestions?

Suppose I have an expression of the this type:

Quantity["Epsilonzero"]  a (b + c Sin[\[Omega] t])^2

where t is time. I am interested in "extracting" the non time-dipendent part. I can expand the expression to show the time dependent terms:

Expand[%]
mysum = TrigReduce[%]

and obtain for mysum

a c^2 Cos[2 t \[Omega]] (Quantity[-(1/2), "ElectricConstant"]) + 
a b c Cos[t \[Omega]] (Quantity[-I, "ElectricConstant"]) + 
a b c Cos[t \[Omega]] (Quantity[I, "ElectricConstant"]) + 
a c^2 (Quantity[1/2, "ElectricConstant"]) + 
a b^2 (Quantity[1, "ElectricConstant"]) + 
a b c (Quantity[2, "ElectricConstant"]) Sin[t \[Omega]] + 
a c^2 (Quantity[-(I/4), "ElectricConstant"]) Sin[2 t \[Omega]] + 
a c^2 (Quantity[I/4, "ElectricConstant"]) Sin[2 t \[Omega]]

Now I want only the terms that do not contain any dependence on t. I could do:

mysum/. {Cos[t \[Omega]] -> 0, Cos[2 t \[Omega]] -> 0, 

Sin[t [Omega]] -> 0, Sin[2 t [Omega]] -> 0}

But because of the presence of Quantity[1, "ElectricConstant"], I get:

 b c (Quantity[0, "ElectricConstant"]) + 
 a c^2 (Quantity[0, "ElectricConstant"]) + 
 a c^2 (Quantity[1/2, "ElectricConstant"]) + 
 a b^2 (Quantity[1, "ElectricConstant"])

i.e., the terms that are effectively 0 are not dropped. 

I could also do:

Collect[mysum, {Cos[t \[Omega]], Cos[2 t \[Omega]], Sin[t \[Omega]], Sin[2 t \[Omega]]}]

and then just pick out the terms of the sum that do not contain the unwanted terms. However, the order in which these terms appear is dependent on the exact form of the original expression, so I'd have to adjust them on a case-by-case basis.

Any other idea? The only thing I came out with so far (and it's not too bad) is to replace Quantity["Epsilonzero"] in the original expression with a normal symbol (not a Quantity), and only put the quantity back in place later.

Post Closed as "Not suitable for this site" by Dr. belisarius, m_goldberg, xzczd, Jens, bbgodfrey
Routine clean-up
Source Link
m_goldberg
  • 108.7k
  • 16
  • 107
  • 263

this may be a stupid question, but I can't find my way around it. (and I have searched the forum for a similar issue, but with no luck...)

I have a sum (let's call it mysum) of many terms. Some of them contains the expressions Sin[w t]Sin[w t] and Cos[w t]Cos[w t] (for context, here t is time). The sum uses Units. Since Since I'm only interested in the non time-time-varying part of the sum, I would like to drop all the terms involving the aforementioned expressionexpressions. I haven't found an elegant way to do this. These are the strategies that got me closer:

mysum/.{Sin[w t] -> 0, Cos[w t] -> 0}

Unfortunately, the terms containing zero are not dropped. I think it has to do with units (for example they contain terms like (0 epsilonzero0 epsilonzero), that is clearly zero, but MathematicaMathematica does not drop for some reason.

Collect[mysum, {Sin[w t], Cos[w t]}]
%[[{1, 3}]]

Where {1,3}{1, 3} are just used as examples here. In fact, this is the problem. The above works, but the position of the terms involving the unwanted expressions depends on the specific form of my original form, so I have to select indexes on a case-by-case basis.

mysum/.{Sin[w t] -> removeme, Cos[w t] -> removeme}
Collect[%, removeme]
%[[;; -2]]

This works, but only in the case in which nonnone of the unwanted expressions exist in the original sum. Plus, it doesn't really look elegant...

Any suggestions?

Thanks

Giacomo

this may be a stupid question, but I can't find my way around it. (and I have searched the forum for a similar issue, but with no luck...)

I have a sum (let's call it mysum) of many terms. Some of them contains the expressions Sin[w t] and Cos[w t] (for context, here t is time). The sum uses Units. Since I'm only interested in the non time-varying part of the sum, I would like to drop all the terms involving the aforementioned expression. I haven't found an elegant way to do this. These are the strategies that got me closer:

mysum/.{Sin[w t] -> 0, Cos[w t] -> 0}

Unfortunately, the terms containing zero are not dropped. I think it has to do with units (for example they contain terms like (0 epsilonzero), that is clearly zero, but Mathematica does not drop for some reason.

Collect[mysum,{Sin[w t],Cos[w t]}]
%[[{1,3}]]

Where {1,3} are just used as examples here. In fact, this is the problem. The above works, but the position of the terms involving the unwanted expressions depends on the specific form of my original form, so I have to select indexes on a case-by-case basis.

mysum/.{Sin[w t] -> removeme, Cos[w t] -> removeme}
Collect[%,removeme]
%[[;;-2]]

This works, but only in the case in which non of the unwanted expressions exist in the original sum. Plus, it doesn't really look elegant...

Any suggestions?

Thanks

Giacomo

this may be a stupid question, but I can't find my way around it. (and I have searched the forum for a similar issue, but with no luck...)

I have a sum (let's call it mysum) of many terms. Some of them contains the expressions Sin[w t] and Cos[w t] (for context, here t is time). The sum uses Units. Since I'm only interested in the non-time-varying part of the sum, I would like to drop all the terms involving the aforementioned expressions. I haven't found an elegant way to do this. These are the strategies that got me closer:

mysum/.{Sin[w t] -> 0, Cos[w t] -> 0}

Unfortunately, the terms containing zero are not dropped. I think it has to do with units (for example they contain terms like (0 epsilonzero), that is clearly zero, but Mathematica does not drop for some reason.

Collect[mysum, {Sin[w t], Cos[w t]}]
%[[{1, 3}]]

Where {1, 3} are just used as examples here. In fact, this is the problem. The above works, but the position of the terms involving the unwanted expressions depends on the specific form of my original form, so I have to select indexes on a case-by-case basis.

mysum/.{Sin[w t] -> removeme, Cos[w t] -> removeme}
Collect[%, removeme]
%[[;; -2]]

This works, but only in the case in which none of the unwanted expressions exist in the original sum. Plus, it doesn't really look elegant.

Any suggestions?

Source Link
Loading