How Can I Edit Inputs in a Mathematica .nb File for Different Calculations?

In summary, the file sent to me with already defined inputs had calculations done for me. I was wondering how I could edit those inputs, keeping the rest of the calculations the same, to find out what the result would be. I was warned previously that this may break the code, but with none of the people who have seen my various posts having any idea about what I am going to change s0 to then none of us will likely be able to tell you whether it will work or not. So hope for the best and figure out how to fix it if this breaks it.
  • #1
StevieTNZ
1,933
878
Hi there

I was sent a .nb file with calculations already done for me, for various inputs.

I was wondering how I can edit those inputs, keeping the rest of the calculations the same, to find out what the result would be?

(see attached file for example)
 

Attachments

  • example.jpg
    example.jpg
    24.5 KB · Views: 387
Physics news on Phys.org
  • #2
/. is Mathematica for "substitute in the previous expression using the following rules."

var->expression is Mathematica for a rule.

If you insert

somevar=someconstant

before any of your lines giving your substitutions it is possible and perhaps even likely that it will break the code for one or more complicated reasons.

If you could be more specific about what you want to edit and what you want to keep the same then it should be possible for someone to give you an idea how to proceed.
 
  • #3
All the lines with //Simplify // Expand are the rules I wish to keep. Its just the input s0 I wish to change, which will change what's under s2 and before s3... if that makes any sense?
 
  • #4
StevieTNZ said:
Its just the input s0 I wish to change

Then try changing the
s0:=stuff
to
s0:=newstuff

and then evaluate the notebook. Then CAREFULLY CHECK to see if you get the correct result.

As I warned previously, this may break the code, but with none of the people who have seen your various posts having any idea about what you are going to change s0 to then none of us will likely be able to tell you whether it will work or not. So hope for the best and figure out how to fix it if this breaks it. I hope it works.
 
  • #5
Well that didn't turn out to be that hard... managed to get the calculation.

(Figured out that bH should be changed to -bH to convert H into - H)
 
  • #6
It seems that displaying an output based on my input, running the calculation backwards, i.e. output -> input, turns up a different result.

Would that be an indication that my input (into what was there previously) has changed something?

[Equation 1: There is an input where it calculates an output.
Equation 2: Based on that output, I can insert that somewhere else where it will run the calculation backward and turn up the input I placed in Equation 1.]
 
Last edited:
  • #7
Take a few minutes and really try to imagine yourself in this position:
You know a fair amount about subject X.
Someone far from you who knows a lot less about X is trying to do something nontrivial.
You have not been peeking over their shoulder watching what they have been doing.
You have no access to all the ideas that have been going through their mind.

If you can really put yourself into that mindset and think about it then this may help.
How are you going to get them to explain the task in a way you can help?
What are you going to ask them to provide you so you can get it right the first time?

I realize that being in the middle of things you have been working on for hours or weeks may make it difficult to adopt the "bug on the wall watching this happen" mindset that may help you think what it is like for someone else who isn't there to try to understand what you are asking and what the answer is.

If you could attach a notebook that shows the exact steps in the exact order that you evaluated them and the results that you have and exactly what it is that seems incorrect then perhaps someone can offer some ideas. But this is made much more complicated if you evaluate the notebook and then go back into the middle of it, make changes, evaluate parts of it again, etc. Having "nonlinear" paths through an interactive dynamic evaluation of a notebook can make it far harder to pin down and reproduce exactly what you are trying to do and how to likely fix the problem.

I hope something in this was helpful
 
  • #8
See attached the .nb file, unedited with my own inputs (i.e. the file sent to me with already defined inputs).

Changing the first input from bH*cV to bV*-cH produces an output. Copying that output into the next calculation, where the input is defined as bHpp*cVpp, produces an output different to the input bV*-cH which was used for the top calculation.
 

Attachments

  • State transformations.nb
    18.7 KB · Views: 401
Last edited:
  • #9
It is difficult for me to understand exactly what you think the problem is.

One guess is that in your "forward" calculation you turn bH into bHp+I*cHp. In your "reverse calculation you seem to attempt to reverse that by subtracting I*cHp. That certainly seems like it would reverse the process. But in both cases you also divide by Sqrt[2]. That seems to break your attempt at reversing the process.

My guess is you need to multiply by Sqrt[2] to reverse the previous division by Sqrt[2].

This guess seem compatible with you appearing to end up with an extra division by 2 at the end of your attempt to reverse the process.

But you also end up with extra minus signs and powers of bH and cV.

I am guessing, but nothing more than that, that there are other little errors in your long chain of substitutions that attempt to reverse the process.

Does any of this make sense?
 
  • #10
I've been told perhaps it is best to use Ket notions to solve the issue at hand.

I was helped with the input, as well as where to place the complex number i in the s1 = ... equation. (I wonder if what I have written is correct, in terms of Ket notions written in Mathematica?)

But I'm not entirely sure how to pass the result of s1 into s3, for conversion into R/L polarisations, especially if I am required to place the i outside the Ket function. Also, if I define Ket[hp, b] ->, would that also take those Ket's with [hp, b], as well as i, before them?
 

Attachments

  • Mathematica-2.nb
    50.1 KB · Views: 398

1. Can I edit a Mathematica file without having the software?

Yes, you can open and edit a Mathematica file using any text editor. However, without the software, you will not be able to run any computations or evaluate the code.

2. How can I re-work a Mathematica file if I am not familiar with the language?

You can use the Wolfram Language Documentation Center to learn the basics of Mathematica and its syntax. You can also find tutorials and resources online to help you understand and modify the code in your file.

3. What is the best way to make changes to a Mathematica file without affecting its functionality?

The safest way to make changes to a Mathematica file is by making a copy of the original file and editing the copy. This way, you can always refer back to the original file if needed.

4. Can I re-work a Mathematica file to make it run faster?

Yes, there are several ways to optimize code and improve the performance of a Mathematica file. This includes using built-in functions, avoiding unnecessary loops, and using appropriate data structures.

5. Is it possible to re-work a Mathematica file to make it more readable?

Yes, you can improve the readability of a Mathematica file by following good coding practices such as using meaningful variable names, adding comments, and organizing the code into logical sections. You can also use indentation and formatting to make the code easier to understand.

Similar threads

Replies
3
Views
1K
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
9K
Replies
0
Views
873
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
10K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
1K
Back
Top