Is there a compact way to Taylor expand all the terms in the equation?

For example a vector:

vec={l (Cos[φ1[t]] + Cos[φ2[t]] +
Cos[φ3[t]] + Cos[φ4[t]] +
Cos[φ5[t]] + Cos[φ6[t]] +
Cos[φ7[t]] + Cos[φ8[t]] +
1/2 Cos[φ9[t]]),
l (-Sin[φ1[t]] – Sin[φ2[t]] –
Sin[φ3[t]] – Sin[φ4[t]] –
Sin[φ5[t]] + Sin[φ6[t]] +
Sin[φ7[t]] + Sin[φ8[t]] +
1/2 Sin[φ9[t]])}

And I want to use Taylor Expansion on ALL Cos and Sin terms (up to first order). So I want to use something like Series[Cos[x],{x,1}] but I don’t want to write that for every variable, because there can be nnn variables where nnn is defined by the user.

So is there a more compact and faster way or do I really have to Taylor expand one term at once for all of them?

=================

2

 

Does this do it? vec /. {(a : Cos | Sin)[x_] :> Normal@Series[a[x], {x, 0, 1}]}. (I assumed you wanted to expand about 0 in each case, but if not, change the 0 to something else.)
– march
Mar 25 at 19:43

  

 

@march: It sure does! Thanks!
– skrat
Mar 25 at 19:57

  

 

Are you expanding at t=0? If so, could just do Series[vec, {t, 0, 2}].
– Daniel Lichtblau
Mar 25 at 21:51

=================

2 Answers
2

=================

Here is one straight-forward way. Taking

vec = l*{
Cos[f1[t]] + Cos[f2[t]] + Cos[f3[t]] + Cos[f4[t]] + Cos[f5[t]] + Cos[f6[t]] + Cos[f7[t]] + Cos[f8[t]] + 1/2 Cos[f9[t]],
-Sin[f1[t]] – Sin[f2[t]] – Sin[f3[t]] – Sin[f4[t]] – Sin[f5[t]] + Sin[f6[t]] + Sin[f7[t]] + Sin[f8[t]] + 1/2 Sin[f9[t]]
};

we have

vec /. {Cos[x_] :> Normal@Series[Cos[x], {x, 0, 1}], Sin[x_] :> Normal@Series[Sin[x], {x, 0, 1}]}
(* {(17 l)/2, l (-f1[t] – f2[t] – f3[t] – f4[t] – f5[t] + f6[t] + f7[t] + f8[t] + f9[t]/2)}

We can package the two rules together using Alternatives (|) on Sin or Cos and naming the pattern:

vec /. {(a : Cos | Sin)[x_] :> Normal@Series[a[x], {x, 0, 1}]}

Per a comment by the OP, here’s a slightly more general version:

vec = {a Cos[x[t] + d] x'[t], b Sin[x[t] + y[t] + d] x'[t] y'[t]};
vec /. {(a : Cos | Sin)[x_] :> (Normal@Series[a[y], {y, 0, 1}] /. y -> x)}
(* {a x'[t], b (d + x[t] + y[t]) x'[t] y'[t]} *)

Alternatively, adapting Jens’ solution,

vec /. {(a : Cos | Sin)[x_] :> (Normal@Series[a[ϵ x], {ϵ, 0, 1}] /. ϵ -> 1)}

1

 

Really compact: vec /. f_[t_] :> Normal[f[t] + O[t]^2]
– J. M.♦
Mar 26 at 0:42

  

 

This works.. nicely until you come across something like Cos[x[t]+y[t]]. Is it possible to extend your idea for this case to?
– skrat
Mar 31 at 17:17

  

 

@skrat. I’m pretty sure that Jens’ solution below actually works for the general case, so perhaps you should accept his answer instead!
– march
Mar 31 at 18:27

  

 

The problem with Jens’ solution is that is too general! For example the result of this Normal[Series[ Cos[x1[t] – x2[t]] x1′[t] x2′[t] /. h_[t] :> \[Epsilon] h[t], {\[Epsilon], 0, 1}]] /. \[Epsilon] -> 1 is zero while i want it to be (x1[t] – x2[t])x1′[t] x2′[t]. So Jens’ method, as he wrote works also on products etc.. which is not something I would like at the moment.
– skrat
Mar 31 at 18:32

1

 

@skrat. See updated post.
– march
Mar 31 at 18:42

To be more general and also allow it to work to the desired order when products of cosines or sines appear, I would do the following:

Normal[
Series[vec /. h_[t] :> ϵ h[t], {ϵ, 0, 1}]] /. ϵ -> 1

(*
==> {(17 l)/2,
-l φ1[t] – l φ2[t] – l φ3[t] –
l φ4[t] – l φ5[t] + l φ6[t] +
l φ7[t] + l φ8[t] + 1/2 l φ9[t]}
*)

This will also apply without modification to expressions involving functions other than Sin or Cos. The replacement multiplies every function of t by a small parameter ϵ and expands with respect to that. Then I set the parameter to 1 in the end.

Edit after question was modified in comment

The above approach will of course continue to yield consistent expansions if there are products of small quantities that you would like to keep. All you need to do is increase the order of expansion in ϵ to the desired power. Specifically, for the example in the comment to @march’s answer, you would do this:

Normal[
Series[Cos[x1[t] – x2[t]] x1′[t] x2′[t] /.
h_[t] :> ϵ h[t], {ϵ, 0, 2}]] /. ϵ -> 1

(* ==> Derivative[1][x1][t] Derivative[1][x2][t] *)

One should emphasize that my goal here is to obtain consistent expansions. If you want inconsistent approximations (which I wouldn’t recommend doing), then of course a more selective use of replacement rules would be required.