Mathematica Mathematica: how to avoid replacement from taking the previous outputs

  • Thread starter Thread starter kaizen.moto
  • Start date Start date
  • Tags Tags
    Mathematica
Click For Summary
The discussion revolves around issues with replacement syntax in Mathematica, specifically how to prevent previous outputs from influencing subsequent calculations. The user seeks a method to express replacements in terms of expressions rather than relying on prior results. They provide examples of their function, submat, and express confusion over its outputs when substituting z with 0. The expected outputs for submat[1], submat[2], submat[3], and submat[4] are specified, but the current implementation yields incorrect results. The conversation highlights the need to modify the submat routine to achieve the desired outputs, with suggestions to redefine the function in a clearer format, although the specific definitions for the components of the function remain unclear.
kaizen.moto
Messages
94
Reaction score
0
Hi all,

Please help me with regard to my problems about replacement syntax.

Iam looking for a method such that Mathematica won't use the previous output as an input for the subsequent cells or codes. Instead, I wish Mathematica express the replacement in terms of expressions for the subsequent cells.

Please help me to solve this matter. I,ve attached the notebook for your reference.

Thanks in advance for any response.
 

Attachments

Physics news on Phys.org
Does your submat function produce the correct formulas in terms of z? E.g. submat[2] evaluates to {{2 + 15 z + 3 z (3 + 3 z + 2 z^2)}, {3 + 9 z + 2 z^2 + z^2 (2 + 11 z)}}. Is that correct?
 
Thank you for reply.
Yes, that is absolutely correct
submat[1] = sub [1] = matDstar[z].matX + matH1sar[z,1];
submat[2] = {{2 + 15 z + 3 z (3 + 3 z + 2 z^2)}, {3 + 9 z + 2 z^2 +
z^2 (2 + 11 z)}}.

Now, this is the interesting part:
submat[1] /. z-> 0 returning {2,3}, submat[2] /. z-> 0 gives {2,3}; submat[3] /. z-> 0 generates {2,3} and so on.

It supposed to be like these:
submat[1] /. z-> 0 returning {2,3}, submat[2] /. z-> 0 gives {26,20}; submat[3] /. z-> 0 generates {158,142} and so on.

My question is that how to modify the existing codes so that they would generate the desired outputs as above.

Thank you
 
submat[3] evaluates to

{{2 + 21 z + 3 z (3 + 3 z + 2 z^2) + 3 z (3 + 9 z + 2 z^2 + z^2 (2 + 11 z))},
{3 + 18 z + 2 z^2 + z^2 (2 + 11 z) + z^2 (2 + 15 z + 3 z (3 + 3 z + 2 z^2))}}

What should it evaluate to?
 
I apologize for my wrong expressions, it should be read as follows:

submat[1] = {{2 + 11 z}, {3 + 3 z + 2 z^2}};
submat[2] = {{26 + 64 z}, {20 + 6 z + 26 z^2}}
submat[3] = {{158 + 432 z}, {142 + 9 z + 158 z^2}}
submat[4] = {{1028 + 7221 z}, {801 + 4 z + 1028 z^2}}

so if z = 0;
submat[1] = {2,3};
submat[2] = {26,20};
submat[3] = {158,142};
submat[4] = {1028,801};
 
So the problem is clearly not in the substitution z->0 but in your submat routine. It gives the wrong output. That said, I have no idea how to fix the submat routine. You can write it as:

submat[n_]:={{a[n] + b[n] z},{c[n] + d[n] z + e[n] z^2}}

But it is not clear from your description what the functions a,b,c,d,e are.
 

Similar threads

  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 13 ·
Replies
13
Views
8K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
4K
Replies
3
Views
3K
Replies
2
Views
2K