How to replace a hole mathematical expression? [closed]

I have the following function:

Input:

f=-a n^2/v^2 +v/n


I want to Replace v/n by v_new

Attempt: [Failed]

f/. v/n -> v_new


Desired output:

-a/v_new +v_new


closed as off-topic by LLlAMnYP, dr.blochwave, Jason B., user9660, gpapNov 17 '15 at 14:10

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – LLlAMnYP, dr.blochwave, Jason B., Community, gpap
If this question can be reworded to fit the rules in the help center, please edit the question.

• One imediate issue that I can spot is use of underscore _ in the variable you are trying to use to replace 'v/n' – e.doroskevic Nov 17 '15 at 13:35
• As a general rule, structure replacement rules with the LHS of the rule to be as simple as possible to avoid having to handle multiple cases separately. For example, as pointed out in answer by @JasonB, instead of v/n -> v2 use v -> n*v2 – Bob Hanlon Nov 17 '15 at 13:51
• @ Bob Hanlon Thanks! This helps – jasmin Nov 17 '15 at 14:12

Just simplify your replacement rule so that you aren't replacing v/n->v2, but replacing v->n v2

f = -a n^2/v^2 + v/n
(* -((5 n^2)/v^2) + v/n *)

f /. v -> n v2
(* -(5/v2^2) + v2 *)


Overview

I do not know how to evaluate your eq. to the desired output. However if you use ReplaceAll in a following way you can replace 'v/n' term. Please see the implementation below. Also, please refer to this link for information on basic syntax issues.

Input

-a*n^2/v^2 + v/n /. v/n -> v2


Where v2 is the variable which is going to be used for replacement and v/n is going to be the term to be replaced.

Output

-((a n^2)/v^2) + v2

EDIT 1:
Format

• The main point here is that the replacement is not complete. When I replace v/n by v2 there shall be the output -((a/(v2)^2) + v2 . This is the expectation, but what really happening is that: -((a n^2)/v^2) + v2. This is not the output I want – jasmin Nov 17 '15 at 13:43
• -a*n^2/v^2 + v/n /. {v/n -> v2, n^2/v^2 -> v2} - do you mean this? – e.doroskevic Nov 17 '15 at 13:46