Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am trying to create a Mathematica function that basically splits up a continuous function (in this case a physical potential) into steps (strips as it were) and returns the value of the function at that step (i.e., the potential at respective strip boundary). This is used to calculate a transmission coefficient (it's just some function) at every point in that potential.

I have tried to use the in-built function RecurrenceTable, but did not work out (i.e. I get a relation but it's wrong and gives me errors.). I have not fully quit on it, but it would take me too long to explain the inner workings.

Either way, my recurrence relation for some Z is:

Zinput[i] ==  Z0[i]*((Zinput[i + 1] Cosh[k[i] l]) - (Z0[i] Sinh[k[i] l])) / 
((Z0[i] Cosh[k[i] l]) - (Zinput[i + 1] Sinh[k[i] l]))  

I want to plug this into a Do or For loop so that each value depends on the previous one. This should be easy to achieve, but I have no idea how to set the function to do this.


Just for clarification, the dependence on i is defined as follows:

k[i_] := (Sqrt[2. m (V[i] - En)]/hbar);
Z0[i_] := (- I h  k[i])/m
V[i_] := potential[( i/100.)];
potential[x_] :=  Piecewise[{{((V0/2. )*(Cos[(2. Pi / λ) (x - λ/2)] + 1)), 
  0 <= x <= M λ}}];

Where h, V0, λ, and M are constants defined by me (basically they scale the potential).

I have attempted to use the nest list function

b[c_] := NestList[Z0[i]*((Zinput[i + 1]Cosh[k[i]l])-(Z0[i]Sinh[k[i]l]))/
  ((Z0[i] Cosh[k[i] l]) - (Zinput[i + 1] Sinh[k[i] l])), Zinput[i], c]

However, this does not give me something I can plot. I am trying to apply the formula for Zinput (the big long $\sinh$ and $\cosh$ thing) to be the next input while Z0 is the initial value to start with. I also should've mentioned the splitting of the potential is done from right to left (and this is something I cannot change).

share|improve this question
    
I wrote an answer but then it occurred to me that I was specifying the values in terms of i, while my idea of answer would have worked without i at all. Please clarify why Z0 is a function of i and how it should be updated in i+1, for example. –  Peltio Nov 14 '13 at 17:18
    
Are you saying that input at time i depends on input at time i+1 ?? Normal recurrence is where future values depends on past values, this way the system can be initialized correctly. –  Nasser Nov 14 '13 at 17:20
    
@Nasser, by solving the given eq wrt Zinput[i+1] you get a function of values at index i only. Problem is: how Zo and k vary with i is left unspecified. If explicit forms for such relationships are given, a NestList will help unravel the "i-me" evolution of Zinput. –  Peltio Nov 14 '13 at 17:22
    
Your definition appears to have neither a initial condition (z0 is not defined) nor a possibility for terminating. You define zInput[i] in terms of zInput[i+1], the latter which is not known (nor can it be computed). –  David Carraher Nov 14 '13 at 18:02
    
You may wish to examine the way factorial can be defined recursively, and work from there. reference.wolfram.com/mathematica/tutorial/… –  David Carraher Nov 14 '13 at 18:07

1 Answer 1

I am not sure to have understood the problem but, if the index i represents the step, you could solve your equation for Zinput[i+1] (which I will call Zin for brevity), getting

Zin[i+1] == Z0[i] * (Z0[i] Sinh[l k[i]] + Zin[i] Cosh[l k[i]]) /
                    (Z0[i] Cosh[l k[i]] + Zin[i] Sinh[l k[i]])

Then, after defining the value at i=0 or i=1 to stop the recursion, you could compute the next step for Zin with

Zin[i_]:= Z0[i-1] * (Z0[i-1] Sinh[l k[i-1]] + Zin[i-1] Cosh[l k[i-1]]) /
                               (Z0[i-1] Cosh[l k[i-1]] + Zin[i-1] Sinh[l k[i-1]])

Problem is you did not define how Z0 and k depends on i. If you can give a functional dependance of such variables from i, you could compute all three i-dependent values with a function nextStep[{Zin,Zo,k}] that, given the values at i will give you back the values at i+1. Such function could then be used inside a NestList, along with the respective initial values at i=0 or 1, whatever, and the number of steps (or strips) to take.

Somehow I have this feeling that you might be better off with a NestList.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.