Message Boards Message Boards

0
|
1075 Views
|
7 Replies
|
4 Total Likes
View groups...
Share
Share this post:

How to use ReplaceAll to substitute 0 for particular like terms & eventually generate a string of 0s

Posted 5 months ago

Hello. This is the output

{0, 0, 0, 0, 0, -(1/2)  E^(-t Sqrt[k^2 + 2 \[Sigma]^2])  x  C[4] - 
  1/2  E^(t Sqrt[k^2 + 2 \[Sigma]^2])  x  C[4] + (
  E^(-t Sqrt[k^2 + 2 \[Sigma]^2])  k^2  x  C[4])/(
  2 (k^2 + 2 \[Sigma]^2)) + (
  E^(t Sqrt[k^2 + 2 \[Sigma]^2])  k^2  x  C[4])/(
  2 (k^2 + 2 \[Sigma]^2)) + (
  E^(-t Sqrt[k^2 + 2 \[Sigma]^2])  x  \[Sigma]^2  C[4])/(
  k^2 + 2 \[Sigma]^2) + (
  E^(t Sqrt[k^2 + 2 \[Sigma]^2])  x  \[Sigma]^2  C[4])/(
  k^2 + 2 \[Sigma]^2), -((k^2  u  \[Theta]  C[3])/(2 \[Sigma]^2)) + (
  E^(t Sqrt[k^2 + 2 \[Sigma]^2])  k^2  u  \[Theta]  C[3])/(
  2 \[Sigma]^2) + (k^2  u  \[Theta]  C[3])/(k^2 + 2 \[Sigma]^2) - (
  E^(t Sqrt[k^2 + 2 \[Sigma]^2])  k^2  u  \[Theta]  C[3])/(
  k^2 + 2 \[Sigma]^2) + (k^4  u  \[Theta]  C[3])/(
  2 \[Sigma]^2 (k^2 + 2 \[Sigma]^2)) - (
  E^(t Sqrt[k^2 + 2 \[Sigma]^2])  k^4  u  \[Theta]  C[3])/(
  2 \[Sigma]^2 (k^2 + 2 \[Sigma]^2)) + (
  E^(-t Sqrt[k^2 + 2 \[Sigma]^2])  k  u  \[Theta]  C[3])/Sqrt[
  k^2 + 2 \[Sigma]^2] - (
  E^(t Sqrt[k^2 + 2 \[Sigma]^2])  k  u  \[Theta]  C[3])/Sqrt[
  k^2 + 2 \[Sigma]^2] + (
  E^(-t Sqrt[k^2 + 2 \[Sigma]^2])  k^3  u  \[Theta]  C[3])/(
  2 \[Sigma]^2 Sqrt[k^2 + 2 \[Sigma]^2]) - (
  E^(t Sqrt[k^2 + 2 \[Sigma]^2])  k^3  u  \[Theta]  C[3])/(
  2 \[Sigma]^2 Sqrt[k^2 + 2 \[Sigma]^2]) - (
  E^(-t Sqrt[k^2 + 2 \[Sigma]^2])  k  u  \[Theta]  Sqrt[
   k^2 + 2 \[Sigma]^2]  C[3])/(2 \[Sigma]^2) + (
  E^(t Sqrt[k^2 + 2 \[Sigma]^2])  k  u  \[Theta]  Sqrt[
   k^2 + 2 \[Sigma]^2]  C[3])/(2 \[Sigma]^2) + (
  E^(-t Sqrt[k^2 + 2 \[Sigma]^2])  k  u  x  C[4])/(2 \[Sigma]^2) + (
  E^(t Sqrt[k^2 + 2 \[Sigma]^2])  k  u  x  C[4])/(2 \[Sigma]^2) + (
  k^2  u  \[Theta]  C[4])/(k^2 + 2 \[Sigma]^2)^(3/2) - (
  E^(t Sqrt[k^2 + 2 \[Sigma]^2])  k^2  u  \[Theta]  C[
   4])/(k^2 + 2 \[Sigma]^2)^(3/2) + (k^4  u  \[Theta]  C[4])/(
  2 \[Sigma]^2 (k^2 + 2 \[Sigma]^2)^(3/2)) - (
  E^(t Sqrt[k^2 + 2 \[Sigma]^2])  k^4  u  \[Theta]  C[4])/(
  2 \[Sigma]^2 (k^2 + 2 \[Sigma]^2)^(3/2)) - (
  E^(-t Sqrt[k^2 + 2 \[Sigma]^2])  k  u  x  C[4])/(
  k^2 + 2 \[Sigma]^2) - (
  E^(t Sqrt[k^2 + 2 \[Sigma]^2])  k  u  x  C[4])/(
  k^2 + 2 \[Sigma]^2) - (
  E^(-t Sqrt[k^2 + 2 \[Sigma]^2])  k^3  u  x  C[4])/(
  2 \[Sigma]^2 (k^2 + 2 \[Sigma]^2)) - (
  E^(t Sqrt[k^2 + 2 \[Sigma]^2])  k^3  u  x  C[4])/(
  2 \[Sigma]^2 (k^2 + 2 \[Sigma]^2)) + (2  u  x  C[4])/Sqrt[
  k^2 + 2 \[Sigma]^2] + (E^(-t Sqrt[k^2 + 2 \[Sigma]^2])  u  x  C[4])/
  Sqrt[k^2 + 2 \[Sigma]^2] - (
  5  E^(t Sqrt[k^2 + 2 \[Sigma]^2])  u  x  C[4])/Sqrt[
  k^2 + 2 \[Sigma]^2] + (
  k^2  u  x  C[4])/(\[Sigma]^2 Sqrt[k^2 + 2 \[Sigma]^2]) + (
  E^(-t Sqrt[k^2 + 2 \[Sigma]^2])  k^2  u  x  C[4])/(
  2 \[Sigma]^2 Sqrt[k^2 + 2 \[Sigma]^2]) - (
  5  E^(t Sqrt[k^2 + 2 \[Sigma]^2])  k^2  u  x  C[4])/(
  2 \[Sigma]^2 Sqrt[k^2 + 2 \[Sigma]^2]) - (k^2  u  \[Theta]  C[4])/(
  2 \[Sigma]^2 Sqrt[k^2 + 2 \[Sigma]^2]) + (
  E^(t Sqrt[k^2 + 2 \[Sigma]^2])  k^2  u  \[Theta]  C[4])/(
  2 \[Sigma]^2 Sqrt[k^2 + 2 \[Sigma]^2]) - (
  u  x  Sqrt[k^2 + 2 \[Sigma]^2]  C[4])/\[Sigma]^2 - (
  E^(-t Sqrt[k^2 + 2 \[Sigma]^2])  u  x  Sqrt[k^2 + 2 \[Sigma]^2]  C[
   4])/(2 \[Sigma]^2) + (
  5  E^(t Sqrt[k^2 + 2 \[Sigma]^2])  u  x  Sqrt[k^2 + 2 \[Sigma]^2]
     C[4])/(2 \[Sigma]^2) - (
  E^(1/2 t Sqrt[k^2 + 2 \[Sigma]^2])  k  u  \[Theta]  C[5])/(
  2 x^(3/2)) + (
  E^(1/2 t Sqrt[k^2 + 2 \[Sigma]^2])  k^2  u  \[Theta]^2  C[5])/(
  2 x^(3/2) \[Sigma]^2) + (
  3  E^(1/2 t Sqrt[k^2 + 2 \[Sigma]^2])  u  \[Sigma]^2  C[5])/(
  32 x^(3/2)) - (
  E^(-(1/2) t Sqrt[k^2 + 2 \[Sigma]^2])  k  u  \[Theta]  C[6])/(
  2 x^(3/2)) + (
  E^(-(1/2) t Sqrt[k^2 + 2 \[Sigma]^2])  k^2  u  \[Theta]^2  C[6])/(
  2 x^(3/2) \[Sigma]^2) + (
  3  E^(-(1/2) t Sqrt[k^2 + 2 \[Sigma]^2])  u  \[Sigma]^2  C[6])/(
  32 x^(3/2)) - x g[x, t] + 
\!\(\*SuperscriptBox[\(g\), 
TagBox[
RowBox[{"(", 
RowBox[{"0", ",", "1"}], ")"}],
Derivative],
MultilineFunction->None]\)[x, t] - k x 
\!\(\*SuperscriptBox[\(g\), 
TagBox[
RowBox[{"(", 
RowBox[{"1", ",", "0"}], ")"}],
Derivative],
MultilineFunction->None]\)[x, t] + k \[Theta] 
\!\(\*SuperscriptBox[\(g\), 
TagBox[
RowBox[{"(", 
RowBox[{"1", ",", "0"}], ")"}],
Derivative],
MultilineFunction->None]\)[x, t] + 1/2 x \[Sigma]^2 
\!\(\*SuperscriptBox[\(g\), 
TagBox[
RowBox[{"(", 
RowBox[{"2", ",", "0"}], ")"}],
Derivative],
MultilineFunction->None]\)[x, t]}` . My objective is to obtain a list  `{0, 0, 0, 0, 0, 0, 0}` . That being said on position P[[6]] I have `Simplify[ P[[6]] ] ` which outputs `0` . From P[[7]],  I want to obtain the values of `\[Kappa]` , `\[Sigma]` , `\[Theta]` such that `(E^(-(1/2) t Sqrt[
  k^2 + 2 \[Sigma]^2])  u  (16 k^2 \[Theta]^2 - 
   16 k \[Theta] \[Sigma]^2 + 
   3 \[Sigma]^4)  (E^(t Sqrt[k^2 + 2 \[Sigma]^2])  C[5] + C[
   6]))/(32 x^(3/2) \[Sigma]^2) = 0

Firstly I want to put together like terms of g[x,t] and equate to 0. This is my attempt ReplaceAll[g[x, t] -> 0][EDs[[7]]] (* This syntax is not correct *) , but it is not correct. Then from this level, it is to obtain the real values of \[Kappa] , \[Sigma] , \[Theta] so that I end up with a list {0, 0, 0, 0, 0, 0, 0} .

POSTED BY: Nomsa Ledwaba
7 Replies

You want the function g to be replaced with the constant zero function? This is the way:

Simplify[p] /. g -> Function[0]
Solve[% == 0]
POSTED BY: Gianluca Gorni
Posted 5 months ago

Thank you for responding. Using the syntax which you suggested still gives exactly same output as before when I used the command ReplaceAll. I wanted g[x,t] which is 0 to make every term which is multiplied by g[x,t] to be 0. The solve the remaining expression. As for the command Solve, the output give message Solve:: This system cannot be solved with the methods available to Solve. Try Reduce or FindInstance instead. This was my attempt

Solve[(E^(-(1/2) t Sqrt[k^2 + 2 \[Sigma]^2])
     u  (16 k^2 \[Theta]^2 - 16 k \[Theta] \[Sigma]^2 + 
     3 \[Sigma]^4)  (E^(t Sqrt[k^2 + 2 \[Sigma]^2])  C[5] + C[6]))/(
  32 x^(3/2) \[Sigma]^2) == 0, \[Theta], \[Kappa], \[Sigma], Reals]

which gave an error.

POSTED BY: Nomsa Ledwaba

Wrong syntax, the unkonwns, if more than one, must be wrapped in a list:

Solve[(E^(-(1/2) t Sqrt[k^2 + 2 \[Sigma]^2]) u (16 k^2 \[Theta]^2 - 
       16 k \[Theta] \[Sigma]^2 + 
       3 \[Sigma]^4) (E^(t Sqrt[k^2 + 2 \[Sigma]^2]) C[5] + 
       C[6]))/(32 x^(3/2) \[Sigma]^2) == 0,
 {\[Theta], \[Kappa], \[Sigma]}, Reals]
POSTED BY: Gianluca Gorni

With ReplaceAll[g[x, t] -> 0], the derivatives of g will not become zero:

ReplaceAll[g[x, t] -> 0][Derivative[1, 0][g][x, t]]

Compare with

Derivative[1, 0][g][x, t] /. g -> Function[0]

This is because the internal representation Derivative[1, 0][g][x, t] does not contain the expression g[x, t], and nothing gets replaced.

POSTED BY: Gianluca Gorni
Posted 5 months ago

Update: From your previous response I have finally used

ReplaceAll[g[x, t] -> 0] Derivative[0, 1][g][x, t] /. 
 g -> Function[0] [ Derivative[1, 0][g][x, t] Derivative[2, 0][g][x, t] /.   g -> Function[0]]

and the output is 0 (which is correct).
Now using the Solve command for

Solve[(E^(-(1/2) t Sqrt[k^2 + 2 \[Sigma]^2])
     u  (16 k^2 \[Theta]^2 - 16 k \[Theta] \[Sigma]^2 + 
     3 \[Sigma]^4)  (E^(t Sqrt[k^2 + 2 \[Sigma]^2])  C[5] + C[6]))/(
  32 x^(3/2) \[Sigma]^2) == 0, \[Theta], \[Kappa], \[Sigma], Reals]

Normally one would complete the squares for

Solve[16  k^2 \[Theta]^2 - 16  k  \[Theta] \[Sigma]^2 + 3 \[Sigma]^4 == 0, {\[Theta], \[Kappa], \[Sigma]}, Reals]

to obtain the values of \[Theta], \[Kappa], \[Sigma] because one cannot equate exponential expressions to 0 since e gives an asymptote at 0.
The syntax for using Solve command is not correct. Is there a way to write a syntax such that the completing the squares is featured in order to obtain the values for \[Theta], \[Kappa], \[Sigma]?

POSTED BY: Nomsa Ledwaba

The unknowns must be collected into a list:

Solve[(E^(-(1/2) t Sqrt[k^2 + 2 \[Sigma]^2]) u (16 k^2 \[Theta]^2 - 
       16 k \[Theta] \[Sigma]^2 + 
       3 \[Sigma]^4) (E^(t Sqrt[k^2 + 2 \[Sigma]^2]) C[5] + 
       C[6]))/(32 x^(3/2) \[Sigma]^2) == 0,
 {\[Theta], \[Kappa], \[Sigma]}, Reals]
POSTED BY: Gianluca Gorni
Posted 4 months ago

Due to the global rules, created by SetDelayed on ReplaceAll operator, this is what I decided to in order to get the derivatives replaced as well as evaluated in the computation. My concern is I am unable to check to confirm if the computation is accurate. Please help. Here is the code

(* Update LXi, LPhi and substitute again.
'{LXi = x*D[Xi[2][t],t]+Sqrt[x]h[t], Xi[2][t]};   LPhi= { \ (p[t]+f[x,t])u+g[x,t]}; f[x,t]=Subscript[\[ConstantC], \1][t]+(-((4 k \[Theta] h[t])/Sqrt[x])+6 Sqrt[x] (k h[t]+2 \
(h^\[Prime])[t])+6 x (k \ (Xi[2]^\[Prime])[t]+(Xi[2]^\[Prime]\[Prime])[t]))/(8 k \[Theta])' *)


'{LXi, LPhi} = 
ReplaceAll[{LXi = {x*D[Xi[2][t], t] + Sqrt[x] h[t], Xi[2][t]},
LPhi = { (p[t] + 
1/(8 k \[Theta]) (-(1/Sqrt[x]) 4 k \[Theta] h[t] + 
6 Sqrt[x] (k (*h[t]*)+ 2 D[h[t], t]) + 
6 x (k D[Xi[2][t], t] + D[Xi[2][t], {t, 2}]))) u + 
g[x, t]}}, {h[t] -> 
E^((Sqrt[k] t Sqrt[3 k + 8 \[Theta]])/(2 Sqrt[3]))  C[1] + 
E^(-((Sqrt[k] t Sqrt[3 k + 8 \[Theta]])/(2 Sqrt[3])))  C[2], 
p[t] -> C[3] - (
3  E^(-((t Sqrt[k (3 k + 8 \[Theta])])/Sqrt[
3]))  (-1 + E^((t Sqrt[k (3 k + 8 \[Theta])])/Sqrt[
3]))  (-3 k + 
3 E^((t Sqrt[k (3 k + 8 \[Theta])])/Sqrt[3]) k - 8 \[Theta] + 
8 E^((t Sqrt[k (3 k + 8 \[Theta])])/Sqrt[3]) \[Theta] + 
Sqrt[3] Sqrt[k (3 k + 8 \[Theta])] + 
Sqrt[3] E^((t Sqrt[k (3 k + 8 \[Theta])])/Sqrt[3]) Sqrt[
k (3 k + 8 \[Theta])])  C[5])/(8 (3 k + 8 \[Theta])) - (
3  E^(-((t Sqrt[k (3 k + 8 \[Theta])])/Sqrt[
3]))  (-1 + E^((t Sqrt[k (3 k + 8 \[Theta])])/Sqrt[
3]))  (3 Sqrt[3] k + 
3 Sqrt[3] E^((t Sqrt[k (3 k + 8 \[Theta])])/Sqrt[3]) k + 
8 Sqrt[3] \[Theta] + 
8 Sqrt[3] E^((t Sqrt[k (3 k + 8 \[Theta])])/Sqrt[
3]) \[Theta] - 3 Sqrt[k (3 k + 8 \[Theta])] + 
3 E^((t Sqrt[k (3 k + 8 \[Theta])])/Sqrt[3]) Sqrt[
k (3 k + 8 \[Theta])])  C[6])/(
8 (3 k + 8 \[Theta]) Sqrt[k (3 k + 8 \[Theta])]), 
Xi[2][t] -> 
C[4] + (Sqrt[3]
E^(-((t Sqrt[k (3 k + 8 \[Theta])])/Sqrt[
3]))  (-1 + E^((2 t Sqrt[k (3 k + 8 \[Theta])])/Sqrt[3]))  C[
5])/(2 Sqrt[k (3 k + 8 \[Theta])]) + (
3  E^(-((t Sqrt[k (3 k + 8 \[Theta])])/Sqrt[
3]))  (-1 + E^((t Sqrt[k (3 k + 8 \[Theta])])/Sqrt[3]))^2  C[
6])/(2 k (3 k + 8 \[Theta])), 
D[h[t], t] -> (
E^((Sqrt[k] t Sqrt[3 k + 8 \[Theta]])/(2 Sqrt[3]))  Sqrt[k]
Sqrt[3 k + 8 \[Theta]]  C[1])/(2 Sqrt[3]) - (
E^(-((Sqrt[k] t Sqrt[3 k + 8 \[Theta]])/(2 Sqrt[3])))  Sqrt[k]
Sqrt[3 k + 8 \[Theta]]  C[2])/(2 Sqrt[3]), 
D[Xi[2][t], t] -> 
E^((t Sqrt[k (3 k + 8 \[Theta])])/Sqrt[3])  C[5] - 
1/2  E^(-((t Sqrt[k (3 k + 8 \[Theta])])/Sqrt[
3]))  (-1 + E^((2 t Sqrt[k (3 k + 8 \[Theta])])/Sqrt[3]))  C[
5] + (Sqrt[
3]  (-1 + E^((t Sqrt[k (3 k + 8 \[Theta])])/Sqrt[3]))  Sqrt[
k (3 k + 8 \[Theta])]  C[6])/(k (3 k + 8 \[Theta])) - (
Sqrt[3]  E^(-((t Sqrt[k (3 k + 8 \[Theta])])/Sqrt[
3]))  (-1 + E^((t Sqrt[k (3 k + 8 \[Theta])])/Sqrt[
3]))^2  Sqrt[k (3 k + 8 \[Theta])]  C[6])/(
2 k (3 k + 8 \[Theta])), 
D[Xi[2][t], {t, 2}] -> (
2  E^((t Sqrt[k (3 k + 8 \[Theta])])/Sqrt[3])
k  (3 k + 8 \[Theta])  C[5])/(
Sqrt[3] Sqrt[k (3 k + 8 \[Theta])]) + (
E^(-((t Sqrt[k (3 k + 8 \[Theta])])/Sqrt[
3]))  (-1 + E^((2 t Sqrt[k (3 k + 8 \[Theta])])/Sqrt[
3]))  k  (3 k + 8 \[Theta])  C[5])/(
2 Sqrt[3] Sqrt[k (3 k + 8 \[Theta])]) - (
2  E^((t Sqrt[k (3 k + 8 \[Theta])])/Sqrt[3])  Sqrt[
k (3 k + 8 \[Theta])]  C[5])/Sqrt[
3] + ((-2 (-1 + E^((t Sqrt[k (3 k + 8 \[Theta])])/Sqrt[
3])) k (3 k + 8 \[Theta]) + 
1/2 E^(-((t Sqrt[k (3 k + 8 \[Theta])])/Sqrt[
3])) (-1 + E^((t Sqrt[k (3 k + 8 \[Theta])])/Sqrt[
3]))^2 k (3 k + 8 \[Theta]) + 
3/2 E^(-((t Sqrt[k (3 k + 8 \[Theta])])/Sqrt[
3])) (2/3 E^((2 t Sqrt[k (3 k + 8 \[Theta])])/Sqrt[3])
k (3 k + 8 \[Theta]) + 
2/3 E^((t Sqrt[k (3 k + 8 \[Theta])])/Sqrt[
3]) (-1 + E^((t Sqrt[k (3 k + 8 \[Theta])])/Sqrt[
3])) k (3 k + 8 \[Theta])))  C[6])/(
k (3 k + 8 \[Theta]))}]'
POSTED BY: Nomsa Ledwaba
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