Message Boards Message Boards

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

Why does ReplaceAll not recognize pattern in this expression?

Posted 19 days 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 18 days ago

First off, thank you for the suggests and help. The following is information in case somebody has an idea. I think I need to do a little work to isolate the issue, and that may resolve it.

In response to Gianluca's suggestion to move the Simplify before the ReplaceAll's, I found that all of the substitutions fail entirely now. In other words, // Simplify /. u -> U /. v -> 0 /. w -> w0 yields exactly the same output as // Simplify. In response to Eric's suggestion to post my code, I agree that's a good idea, but rather than dump the whole thing, I feel I have an obligation to try and find the simplest case that recreates the issue. The first iteration of that was to just see if Mathematica failed to be able to do the substitution into ArcSin[Abs[w0]/U], and it does not fail. Given what I said in the opening two sentences, I think I have an idea of where to focus. If I can't figure it out after I find time to spend another hour or two on it, I'll just upload the whole notebook. Both U>0, u, v, w, and w0 are declared to be Reals in an $Assumption statement.

This is something of an aside, but the reason w->w0 gets in here and not w->0 is because I was getting errors due to a divide by zero error when I tried to evaluate even though things cancel. This could be related to the above. w!=0 is physically reasonable, so might as well include it.

POSTED BY: John Dzielski

the reason w->w0 gets in here and not w->0 is because I was getting errors due to a divide by zero error

It's too bad you haven't told us what answer you expect to get, because then I would know whether this is right:

Limit[-((CD U)/Sqrt[((U^2 + w0^2)/U^2)]) - 
  CL\[Alpha] U^2 (1/Sqrt[w0^2] -
  w0/(U^2 Sqrt[(U^2 + w0^2)/U^2])) ArcSin[Sqrt[w0^2]/U],
 w0 -> 0]

(*  -((CD + CL\[Alpha]) U)  *)
POSTED BY: Michael Rogers
Posted 18 days 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 18 days ago

Thanks for the suggestions. I thought attaching a snippet from a notebook was the best way to show what was going on. When I cut-and-paste, the result seems to be not intelligible. I tried the suggestion of moving the simplify, but the substitution still doesn't work. One interesting thing that I noticed is elsewhere in the full notebook Mathematica doesn't automatically eliminate Abs[w0]/Sqrt[w0^2] from an expression, but it does use the substitution in what is attached to this post.

What I am trying to do is an order-of-magnitude reduction on the full expression (there are more). Based on limited prior experience, I did not expect Mathematica to do all of the work for me, and figured manual substitutions would be necessary. I'm a little surprised that this one doesn't seem to work.

After trying a few other things, I think it looks like the Abs[] function is maybe a bit of a blind spot for Mathematica. It does recognize and substitute for Sqrt[w0^2] but not Abs[w0].

I've added an update to the notebook snippet.

Attachments:
POSTED BY: John Dzielski
Posted 18 days 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 18 days 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 19 days 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

Group Abstract Group Abstract