Re: Iterative solution to a transcendental equation.

*To*: mathgroup at smc.vnet.net*Subject*: [mg125067] Re: Iterative solution to a transcendental equation.*From*: Bill Rowe <readnews at sbcglobal.net>*Date*: Mon, 20 Feb 2012 02:49:31 -0500 (EST)*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com

On 2/19/12 at 6:30 AM, peter.livingston at cox.net (peter livingston) wrote: >I am in the process or porting over into MATHEMATICA a long program >that describes non-linear processes in optical fiber amplifiers=97an >area of my specialty. >There is a transcendental equation in this long program that, >written in dimensionless form, shows the amplified signal in the >cladding-pumped fiber. The particular snippet of code is in a nb >file (I prefer to use the nb as a front end), but I transcribe it >below. As you shall see, this equation is unlike the examples in >the manual, and I have not found any =91handle=92 on how to approach >it. >1. Divide the fiber length L into Mmax =150 steps >X = Table[1-i/Mmax,{i,Mmax}]; >X = L N[x]; All built-in functions in Mathematica begin with an uppercase letter. Additionally, There are several built-in functions named with a single uppercase letter such as N, E, I, D and more. Consequently, it is good practice to use lower case letters to begin the names of functions you create and avoid using a single upper case letter as a variable. This will ensure no conflict with built-in objects and likely save you quite a bit of trouble. So, I would code the above as: x = len Table[1-k/mMax, {k, mMax}]//N; Here, I've done a couple of other things to improved readability, replace i with k and L with len. This makes it more apparent what L represents and avoids mistaking i or l for 1. >2. For every interval x[[i]], find the root w of this >expression. (I chose a single value for x just to see if the method >would work. It didn't. But when it does, I want to operate on the >whole row vector produced by Table, element by element. >fn[w]:=-a ln[w] =96 w + 1 + b [1 - e^(-alpha x[[i]])] by ln you probably meant Log and by e you probably meant E. Remember, anything that begins with a lower case letter is something you have to define. Note, I assume the =96 is an artifact of email rather than what was actually input to Mathematica. If not, this would not be valid syntax here. There is another potential problem with the way you have defined fn. It depends on global values for a, b, alpha, x and i. While this does not violate any syntax rules for Mathematica, this practice is likely to mean fn will produce unexpected results in a large notebook as a result of reassigning values to these global values. >The constant a is 0.4, the constant b is 90 and the constant alpha >is 0.53 >The root w is number that is always greater than or equal to 1. (It >is the ratio of the signal power in the fiber amplifier to the input >signal power.) >3. The construct I used is >Soln=NSolve[fn[w]==0,w] NSolve won't be successful here as the variable i used in your definition of fn has not been given a numeric value. Nor will any of the numerical alternatives work for the same reason. >Needless to say, I am baffled. It appears that coming from a >progressive computing background, I know how to iteratively solve >the equation. I can do it in about 10 steps on a pocket calculator. >And I kow how to write do loops. However, I believed that the >power of MATHEMATICA was such that I should expect the kernel to >figure out how to iteratively solve the transcendental equation. >By the way, how do you get the kernel to spit out numbers with all >of the arithmetic done, not just sums of products and such. If you use machine precision values and have numerical values assigned to all variables the result will be a machine precision values. =46or example 1 + Sqrt[2] will not return a single number but 1.0 + Sqrt[2] will return a single number. Also, something to keep in mind, most functions in Mathematica have the attribute Listable. That allows you do do things like: In[2]:= x = RandomReal[{-1, 1}, 5]; Exp[x] Out[3]= {0.477844,1.09401,0.890513,0.415329,0.771684} rather than doing something like: In[4]:= Table[Exp[x[[k]]], {k, 5}] Out[4]= {0.477844,1.09401,0.890513,0.415329,0.771684}

**Re: How to change individual colors of an image**

**Re: what type of InterpolatingFunction?**

**Re: Iterative solution to a transcendental equation.**

**How to Multiply a Sequence of #s that depends on the previous #**