Mathematica: how to avoid replacement from taking the previous outputs

  • Context: Mathematica 
  • Thread starter Thread starter kaizen.moto
  • Start date Start date
  • Tags Tags
    Mathematica
Click For Summary

Discussion Overview

The discussion revolves around a problem in Mathematica regarding the replacement syntax and how to prevent previous outputs from influencing subsequent calculations. Participants are exploring how to modify existing code to achieve desired outputs based on specific input values.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant seeks a method to ensure that Mathematica does not use previous outputs as inputs for subsequent cells, preferring expressions to be evaluated independently.
  • Another participant questions whether the submat function produces correct formulas in terms of the variable z, providing an example for verification.
  • A participant confirms that the output of submat[2] is correct but expresses confusion about the outputs of submat[1], submat[2], and submat[3] when z is set to 0, indicating they should yield different results.
  • Another participant provides the expected outputs for submat[1], submat[2], submat[3], and submat[4] when z equals 0, clarifying the intended results.
  • One participant suggests that the issue lies within the submat routine itself, asserting that it produces incorrect outputs and proposing a potential structure for the submat function, though they express uncertainty about the definitions of certain functions involved.

Areas of Agreement / Disagreement

Participants do not appear to reach a consensus on the correctness of the submat routine, with some agreeing on the expected outputs while others challenge the current implementation. The discussion remains unresolved regarding how to modify the code effectively.

Contextual Notes

There are limitations in the clarity of the definitions for the functions a, b, c, d, and e within the submat routine, which may affect the understanding of the problem.

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
5K
  • · Replies 2 ·
Replies
2
Views
2K
  • · 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 ·
Replies
3
Views
3K