Using Collect in functions, Mathematica

In summary, you can use the Collect command to factorize an expression by specific variables, such as β and γ, in a given function.
  • #1
carmenquezada
1
0
Hello!:

I want to know if it's possible to use the Collect command in a function. For example, I have this code:


Subscript[E, 1] = \!\(
\*SubscriptBox[\(\[PartialD]\),
SubscriptBox[\(\[Omega]\), \(1\)]]
\*SubscriptBox[\(\[Pi]\), \(m1\)]\);
Subscript[E, 2] = \!\(
\*SubscriptBox[\(\[PartialD]\),
SubscriptBox[\(\[Omega]\), \(2\)]]
\*SubscriptBox[\(\[Pi]\), \(m2\)]\);

osol = Solve[
Subscript[E, 1] == 0 && Subscript[E, 2] == 0, {Subscript[\[Omega],
1], Subscript[\[Omega], 2]}];

(*Solucion*)
Subscript[\[Omega], 1] = Subscript[\[Omega], 1] /. osol[[1, 1]];
Subscript[\[Omega], 2] = Subscript[\[Omega], 2] /. osol[[1, 2]];

And I want [\[Omega], 1] to be factorized by \gamma and \beta, because the expresion that mathematica gives to me it's huge. So I would like to do something like:
Collect[Subscript[\[Omega], 1] = Subscript[\[Omega], 1] /. osol[[1, 1]];,{β,γ}]

I apologize for my English. I'm from Chile =)

Thank you very much.
 
Physics news on Phys.org
  • #2
Yes, you can use the Collect command in a function. You can use the following syntax:Collect[expression, variables, Simplify] In your case, you could use something like this:Collect[Subscript[\[Omega], 1] = Subscript[\[Omega], 1] /. osol[[1, 1]], {β,γ}, Simplify] This should give you the desired result.
 

1. How do I use the Collect function in Mathematica?

The Collect function in Mathematica is used to gather terms in an expression that have the same coefficient. It takes two arguments: the expression and the variable to collect. For example, Collect[3x^2 + 2x^2 + 5x, x] will return 5x + 5x^2.

2. Can I use Collect to collect terms with different powers of the same variable?

Yes, you can use Collect to collect terms with different powers of the same variable. For example, Collect[3x^2 + 2x + 5x^3, x] will return 2x + 3x^2 + 5x^3.

3. How does the Collect function handle expressions with multiple variables?

The Collect function can handle expressions with multiple variables by specifying which variable to collect. For example, Collect[3xy + 2xy + 5x, x] will return 5x + 5xy.

4. Can the Collect function be used to factor polynomials?

Yes, the Collect function can be used to factor polynomials. By collecting terms with the same variable, it can group them together and make it easier to factor them out. For example, Collect[x^2 + 2x + 1, x] will return (x + 1)^2.

5. Are there any limitations to using the Collect function in Mathematica?

One limitation of the Collect function is that it only works on polynomials. It cannot be used on expressions with transcendental functions like trigonometric or exponential functions. Additionally, the Collect function may not always give the desired result if the expression is too complex.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
255
Replies
6
Views
844
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • Programming and Computer Science
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
Replies
1
Views
921
Back
Top