Group Abstract Group Abstract

Message Boards Message Boards

0
|
2.2K Views
|
11 Replies
|
5 Total Likes
View groups...
Share
Share this post:

Why does ReplaceAll not recognize pattern in this expression?

Posted 8 months ago

I have an expression where the result displayed in the Mathematica output includes ArcSin[w0/U]. If I append /. w0/U -> 0 or even /. ArcSin[w0/U] ->0 to the expression, the result still contains ArcSin[w0/U].

Can someone explain why the substitution isn't made? I attached a snippet from a notebook that shows what is happening.

Attachments:
POSTED BY: John Dzielski
11 Replies
Posted 8 months ago
POSTED BY: John Dzielski
POSTED BY: Michael Rogers
Posted 8 months ago

That's basically it give or take a sign. What I am doing is two reference frame transformations. Quaternions and Trig functions, but single axis as I am only testing out a workflow right now on a very simple problem. The problem does not originate from a series, but the expression I'm trying to simplify is a term in a Taylor series, so it's not completely unrelated.

POSTED BY: John Dzielski
Posted 8 months ago
Attachments:
POSTED BY: John Dzielski
Posted 8 months ago

We need to be able to run your code to see what you see and trace through the computation. Since you don't supply Fc, vb, and several other definitions we can't see what's going on. All we can do is guess blindly. If you really want help, you need to provide more information.

POSTED BY: Eric Rimbey

Again, have you tried reversing the order of replacement and Simplify?

Simplify[D[Fc[vb], v] /. u -> U /. v -> 0  /. w -> w0 ] /. 
 U^2 + w0^2 -> U^2

Have you also considered simply w0->0?

POSTED BY: Gianluca Gorni
Posted 8 months ago

Mathematica doesn't automatically eliminate Abs[w0]/Sqrt[w0^2] from an expression

The elimination can be done if w0 is a real number, but not if it is complex. Tell MMA that w0 is real and it will do the elimination.

Simplify[Abs[w0]/Sqrt[w0^2], Assumptions -> Element[w0, Reals]]
(* 1 *)
POSTED BY: Hans Milton

Based on the output of the first line, all subsequent substitutions work for me the way I expect them to, including substituting for Abs[] when tested on outputs that contain Abs[], such as the following:

{{0}, {(-CD)*U + CL\[Alpha]*w0*ArcSin[Abs[w0]/U] - 
          (CL\[Alpha]*U^2*ArcSin[Abs[w0]/U])/Abs[w0]}, {0}} /. 
   Abs[w0]/U -> 0

The outputs of lines 1 and 3 seem inconsistent: Sqrt[w0^2] and Abs[w0] are not equivalent, and it's unlikely Mathematica would transform one into the other without an explicit assumption that w0 is real. There is no such assumption in the notebook's code. I did not really understand your remark about Sqrt[] and Abs[], but maybe it has to do with this.

Or maybe this: Even if a == b, where a and b are distinct but equivalent expressions, then a + b /. a -> 0 results in b. For instance,

(x + 1)^2 + (x^2 + 2 x + 1) /. (x + 1)^2 -> 0
(*  1 + 2 x + x^2  *)

Also 1/Sqrt[x] /. Sqrt[x] -> 1 or Sin[x]/Cos[x] /. Sin[x] -> 1 because the expressions auto-simplify to another form that does not match the replacement rule, similar to how (x^2 + 2 x + 1) is a sum and (x + 1)^2 is a power in my first example.

POSTED BY: Michael Rogers

Wild guess: Are you after this?

Normal[Series[{
   {-((U^2 w0 (CD w0 + CL\[Alpha] U ArcSin[Abs[w0]/U]))/(U^2 + w0^2)^(3/2))},
   {0},
   {(U^2 w0 (CD U - CL\[Alpha] w0 ArcSin[Abs[w0]/U]))/(U^2 + w0^2)^(3/2)}},
  w0 -> 0, Assumptions -> w0 > 0 && U > 0]]

(*  {{-(((CD + CL\[Alpha]) w0^2)/U)}, {0}, {CD w0}}  *)

It's slightly different than the result your substitutions imply, so my guess may be wrong. However, asymptotic expansions are common operations, and you seem to be treating w0 as if it were small and approaching zero. I thought it worth suggesting.

In my experience, algebraic manipulation via substitution rules is tricky and bug-prone. Rules of the form variable -> expr that replace all instances of the variable by the same expr are generally safe. But I find it's more often better to ask Mathematica to calculate the mathematical operation I want. There are exceptions, though.

POSTED BY: Michael Rogers

Maybe you call the replacement before Simplify, while your pattern only appears after Simplify. It's hard to tell without the full value of D[Fc[vb], u].

POSTED BY: Gianluca Gorni
Posted 8 months ago

You need to provide the expression you're applying ReplaceAll to.

POSTED BY: Eric Rimbey
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard