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

• Mathematica
• kaizen.moto
In summary: You should provide more information or maybe consult a Mathematica expert for help.In summary, the person is seeking help with a method to prevent Mathematica from using previous output as input. They are also experiencing issues with their submat function giving incorrect outputs and are looking for ways to modify it to generate desired outputs. They have provided sample code and requested for possible solutions or advice from a Mathematica expert.
kaizen.moto
Hi all,

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.

Thanks in advance for any response.

#### Attachments

• Matrices.nb
24.6 KB · Views: 485
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?

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.

## 1. How can I prevent Mathematica from automatically replacing previous outputs?

By default, Mathematica will automatically replace previous outputs with the most recent one. To avoid this, you can use the semicolon (;) at the end of a command. This will suppress the output and prevent it from being replaced.

## 2. How do I store and access multiple outputs in Mathematica?

To store multiple outputs in Mathematica, you can use the Out[] function. This allows you to assign a label to each output, which can then be called using the In[] function. Alternatively, you can also use the % symbol followed by a number to access the previous outputs.

## 3. Is there a way to save all outputs from a Mathematica session?

Yes, you can use the command File > Save As... to save all outputs from your Mathematica session. This will create a .nb file that contains all of your inputs and outputs, which can be reopened and accessed at a later time.

## 4. Can I clear all previous outputs in Mathematica without restarting the session?

Yes, you can use the command Edit > Clear All Output to clear all previous outputs in your Mathematica session. This will not affect any of your saved variables or functions, but it will clear all of the outputs from your current session.

## 5. How do I suppress specific outputs in Mathematica?

To suppress specific outputs in Mathematica, you can use the command ; Out[number] at the end of a command. This will suppress the output with the corresponding number, which can be accessed later using the In[number] function.

• MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
3K
• MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
• MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
3K
• MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
• MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
• MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
• MATLAB, Maple, Mathematica, LaTeX
Replies
13
Views
8K
• MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
• MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
4K
• Nuclear Engineering
Replies
3
Views
2K