Re: Trouble with FindRoot
- To: mathgroup at smc.vnet.net
- Subject: [mg79149] Re: Trouble with FindRoot
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Fri, 20 Jul 2007 03:14:15 -0400 (EDT)
- Organization: The Open University, Milton Keynes, UK
- References: <f7n4rs$28h$1@smc.vnet.net>
Sooraj R wrote: > Hi all > I have an equation involving Airy Functions, and > Mathematica gives the roots when I use FindRoot. > I need to find the roots for a series of values.(LH > and F) > The result(eh) is an array of 10x16 elements > The initial guess for the first row is given by > ZeroField. > Now for the initial guess for second row, I need to > use the first row as the initial guess, and so on. > How do I do this? > The problem is that I am unable to get rid of the > brackets() and ->. > Does anyone know how to get rid of these two while > using FindRoot. > In that case It would have been more conveninet to > store as an array and manipulate the results at a > later stage. > Here is the code. > > eh = Table[0, {10}, {16}]; > m = 3.85857975 10^-31; > charge = 1.602 10^-19; > hbar = 1.054571 10^-34; > LH = {88.83663979522105, 93.83693172861489, > 98.83720928295747, > 103.83746882256844, 108.83770913229637, > 113.837930338503, > 118.83813328307562, 123.83831915913095, > 128.83848929997706, > 133.8386450587284, 138.83878774185274, > 143.8389185748323, > 148.8390386868427, 153.83914910653547, > 158.83925076412058, > 163.83934449683832}; > F = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} 10^6; > ZeroField = Table[0, {16}]; > For[i = 1, i < 17, i++, > ZeroField[[i]] = (Pi hbar)^2/(2 m charge (LH[[i]] > 10^-10)^2)] > ZeroField // MatrixForm; > For[j = 1, j < 11, j++, > For[i = 1, i < 17, i++, > > eh[[j, i]] = > FindRoot[ > AiryAi[-( (2*m)/(charge* hbar *F[[j]])^2)^(1/ > 3) (Eh charge + charge*F[[j]]*(LH[[i]] > 10^-10)/2)] > AiryBi[-( (2*m)/(charge* hbar *F[[j]])^2)^(1/ > 3) (Eh charge - charge*F[[j]]*(LH[[i]] > 10^-10)/2)] == > AiryAi[-( (2*m)/(charge* hbar *F[[j]])^2)^(1/ > 3) (Eh charge - charge*F[[j]]*(LH[[i]] > 10^-10)/2)] > AiryBi[-( (2*m)/(charge* hbar *F[[j]])^2)^(1/ > 3) (Eh charge + charge*F[[j]]*(LH[[i]] > 10^-10)/2)], {Eh, > ZeroField[[i]]}]]] > eh // MatrixForm > > Many thanks in advance for any help > best regards > Sooraj Please, find below a modified version of your code with some comments. (* We initialize the matrix with the symbolic value 'Eh' -- note that Eh is not a string but just a symbol -- rather than zeros so we will be able to replace them by the numerical values returned by FindRoot. Indeed, FindRoot returns a transformation rule of the from symbolname -> value. Later we will use the replacement operator /. to replace the symbols by their values. *) eh = Table[Eh, {10}, {16}]; m = 3.85857975 10^-31; charge = 1.602 10^-19; hbar = 1.054571 10^-34; LH = {88.83663979522105, 93.83693172861489, 98.83720928295747, 103.83746882256844, 108.83770913229637, 113.837930338503, 118.83813328307562, 123.83831915913095, 128.83848929997706, 133.8386450587284, 138.83878774185274, 143.8389185748323, 148.8390386868427, 153.83914910653547, 158.83925076412058, 163.83934449683832}; F = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} 10^6; ZeroField = Table[0, {16}]; For[i = 1, i < 17, i++, ZeroField[[i]] = (Pi hbar)^2/(2 m charge (LH[[i]] 10^-10)^2)] (* Added Print function so ZeroField is displayed *) Print[ZeroField // MatrixForm]; For[j = 1, j < 11, j++, For[i = 1, i < 17, i++, (* Here we are: the symbol Eh located at (j, i) is going to be replace by the value returned by FindRoot by applying the replacement operator /. to the transformation rule of the form {Eh -> somenumber} *) eh[[j, i]] = Eh /. FindRoot[ AiryAi[-((2*m)/(charge*hbar*F[[j]])^2)^(1/3) (Eh charge + charge*F[[j]]*(LH[[i]] 10^-10)/ 2)] AiryBi[-((2*m)/(charge*hbar*F[[j]])^2)^(1/ 3) (Eh charge - charge*F[[j]]*(LH[[i]] 10^-10)/2)] == AiryAi[-((2*m)/(charge*hbar*F[[j]])^2)^(1/3) (Eh charge - charge*F[[j]]*(LH[[i]] 10^-10)/ 2)] AiryBi[-((2*m)/(charge*hbar*F[[j]])^2)^(1/ 3) (Eh charge + charge*F[[j]]*(LH[[i]] 10^-10)/2)], {Eh, ZeroField[[i]]}]]] eh // MatrixForm Regards, Jean-Marc