Message Boards Message Boards

GROUPS:

Solve a simple nonlinear equation numerically?

Posted 11 days ago
291 Views
|
14 Replies
|
2 Total Likes
|

I am trying to solve a simple nonlinear equation numerically. it is Tangent[alpha]+alpha=0 It is embedded in an "If" statement. So the the pertinent parts of the input and output are

input: Tan[alpha]+alpha=0 along with my algorithm where alpha zero is 2.02 to start out with. Output Tan[2.02 + 0.5 (2.02 - 1. [Alpha][-1.])] is part of the algorithm to solve for alpha's

The problem is with the output. The square bracket at the end of the out put belongs next to the number "2.02" (the way I typed) and instead it has included "+ 0.5 (2.02 - 1. [Alpha][-1.])" which is part of the "If " statement that I'm using to calculate the eigenvalues (or alpha's). I don't know why it is doing this or how to fix it. I tried too post a file but could not do it. I am using Mathematica 11.2 I am sure there are bugs in my algorithm but can not do anything until I fix this prolbem.

14 Replies
Posted 11 days ago

If you can scrape the essential part of your code from your notebook and edit your post above to paste that onto the screen with four leading blanks (white space) in front of each line then that will let the posting process that you mean the paste to be code instead of interpreting some of that as formatting directions.

If you can include enough of the code that it should be able to be run by someone else who doesn't have anything other than what they read on the screen and you include the input, what the output is and what the output should be instead then perhaps someone can spot it issue and help you get it working.

Thanks Bill, I very much appreciate the time you spent helping me. I am not very savvy when it comes to Mathematica and I use it to do mathematical things only if I absolutely have to. I am just trying to calculate eigenvalues for the so called "free surface outflow boundary condition" of the heat equation. And that is why I need mathematica--to numerically calculate eigenvalues for the outflow condition.

I'm starting out with a very simple equation: Tan[alpha] + alpha=0 where Tan[alpha] is always negative and alpha is always positive.. The code I'm using is very simple. Just the Table function, the equation I just mentioned and an "If" statement. Unfortunately I can not print it out in any reasonable way for you to see.

I don't know much about code. I'm sure I'm doing something wrong. I will print out your reply and re-read it several times. I know it will be helpful.

Thanks again.

Mike Bernthal

Bill,

Sorry I'm not computer savvy. Did you mean to post my code to this discussion and let other people try it to see if they have the same problem? I can do the code by simply typing it in. lt's only two or three lines.

Mike

Posted 10 days ago

If you can type in a few lines of code, with four spaces at the beginning of each line so the posting process doesn't change the contents, and give an example input and current incorrect output and desired output and why then hopefully I or someone else can help you resolve the problem and let you move on to the next challenge.

Hi Bill, It's a tricky problem for me. I am pretty sure the code is wrong. However nothing like this has ever happened to me even with a flawed program.

I am 61 and am a slow worker but I am patient and don't give up very easily . I'm still working on the right algorithm. There has to be a simple answer.

I will post it as soon as I know I've got the right code.

Thanks for your patience.

Mike

I

Bill, I forgot that Mathematica has a FiindRoot function to an arbitrary precision. This will be a great help because I would like to know the right algorithm and put it in my C math programs too. I think I'll figure it out. It's nothing deep but still confusing.

If I still have this trouble I'll post it using the procedure you suggested.

Thank you Bill,

Mike

Guten Tag Michael.

Try (you can transfer the following line to a notebook via copy and paste)

Plot[Tan[x] - x, {x, 0, 15}]

From the plot you can see that the zeros are in the vicinity of startvalues (given below. You may well use other startvalues). Then apply Findroot to each of them to get the zeros (here FindRoot is incorporated in a Function which is applied to the list of startvalues).

In[19]:= startvalues = {4, 7, 10.5, 14};
FindRoot[Tan[x] - x == 0, {x, #}, WorkingPrecision -> 20] & /@ startvalues

Out[20]= {{x -> 4.4934094579090641753}, {x -> 7.7252518369377071642},
{x -> 10.904121659428899827}, {x -> 14.066193912831473480}}

For example

In[22]:= Tan[10.9041216594288] - 10.9041216594288

Out[22]= -1.19265*10^-11

From a Plot like

Plot[Tan[x] - x, {x, 15, 35}, Epilog -> {PointSize[.02], Red, Point /@ Table[{(2 j - 1) Pi/2, 0}, {j, 20}]}]

one may conclude that the zeros of Tan[x]-x approach (2 n - 1) Pi / 2.

I hope this helps.

To whom it may concern

What you did worked like a charm, especially since I've got to calculate a lot of eigenvalues. The code is simple and priceless. .

Thank you, thank you, thank you,

Yours truly,

Mike Bernthal

Whether the zeros approach really (2 j + 1 ) Pi / 2 is an open question. At least the 1st hundred lie near to these values

ListPlot[Table[ (2 j + 1) Pi/2 - (x /. FindRoot[Tan[x] - x == 0, {x, (2 j + 1) Pi/2 - .1}, 
      WorkingPrecision -> 40]), {j, 1, 100}]]

Dear Professor Dulhaine,

I am reading this great book" Fourier Series and Orthogonal Functions" by Harry Davis in order to resolve some promising leads in a problem I worked on 26 years ago. I was able to solve

                             D c(x,t)' '  -  u c(x,t)'  -k c(x,t)  = c'(x,t) 

Where the primes on the left are derivatives with respect to "x" and the derivative prime on the right of the equal sign is the derivative of c(x,t) with respect to " t " the heat equation with some whistles.

Where the boundary at x=0 is Co Exp[- b t] = C(0,t)

And the boundary conditions are dC(L,t)/dx + h C(L,t) = 0 (solution is Exp-ht]??)like the one you just mentioned

and C(0,t) = 0

where D, u, k, b, L are constants. The first boundary condition is what you helped me with. I never dreamed that it had so much beauty in it and I also noted the fact that it is the ODE for an exponential function h Exp[-h x] where h is positive.

My question for you is: is it worth my time ie does it have any application in the real world

The only appliication I have is a groundwater equation for a system undergoing Dispersion Advection Reaction l and I know of someone who gave a very elegant solution with c only a function of x but not t.

I can get a very nice solution with t if I let h = b which are constants in the BC.

I could go on and on about this old equation and I was able to solve the equation for a limited domain. Do you think it is possible to solve this equation for Exp[-b t}= C(o,t) and c(infinity, t) = 0 and C(t,o)=0?

I don't think so because of the "sink" in the equation would give me a negative C(x,t) eventually.

I would be very interested to know if I am wasting your and my time.

Thanks so much for your help. I promise not to bug you with this differential equation except of course for now.

Thanks some more for your recent reply! I will look into it.

Mike Bernthal

I made a mistake In my haste to post this blog I should have mentioned. I got it right 26 years ago but did not get it right ironically as I was checking it for "bugs".The outflow condition should be as Dr. Dolhaine wrote it. Tan(x) - x = 0 not Tan(x) + x.=0

Mike Bernthal

Hello Mike,

My question for you is: is it worth my time ie does it have any application in the real world

In fact I don't know.

D c(x,t)' '  -  u c(x,t)'  -k c(x,t)  = D[c(x,t) , t ]

With k = 0 this is a diffusion - equation "with drift". I encountered a problem like this when we had to describe the behaviour of "heavy" (meaning very high molecular weight) particles stored in a narrow, but very high tank. It was noticed that due to gravity after some time there was a non-uniform concentration to be found in the tank, higher at the bottom, lower at the top. After all it followed a "barometric formula" and the interesting question was, how fast is this equlibrium attained. Of course the initial and boundary conditions must be changed so that the system is closed (zero flux at the boundaries). I attach a notebook about that. Don't run it: that will not work; it was meant to be pure text and after all it was distributed as pdf.

With k greater zero there is a term which could be interpreted to describe a reaction of 1st order which leads to a disappearance of the substance in question, perhaps hydrolysis if the substance is an ester stored in water. I have no experience with that.

But you may find it interesting to have a look in the (very good) book

"Conduction of Heat in Solids"

by Carslaw and Jaeger

https://www.amazon.de/Conduction-Science-Publications-Carslaw-1986-04-10/dp/B00M0R1W0I/ref=sr_1_2?__mk_de_DE=%C3%85M%C3%85%C5%BD%C3%95%C3%91&keywords=carslaw+jaeger&qid=1558090626&s=books&sr=1-2-spell

Perhaps there are examples of your type of equation.

Greetings HD

Attachments:

Dr. Dolhaine

Thank you very much for your help.

You mentioned something about a notebook that you sent to me. I looked for it but could not find it and your code has been very valuable to me. Oops I see it thanks! Briefly looking at it there are some striking similarities but I think I have my work cut out for me.

I would not have guessed using a diffusion and drift equation for your tower and would have tried something along the Stokes flow approach but I think friction is involved there maybe.. And since the tower was high and narrow you can use a one dimensional flow with your version of the diffusion equation which is like a blessing from heaven.

Sorry but what is "barometric flow"? Is it the opposite of Stokes flow? I haven't taken a physics class in a while. Googling did not help very much.

Dr. Dolhaine ,as a matter of fact I do have a copy of Carslaw and Jaeger. I could not have solved my differential equation without it. Today I looked for the transformation equation that takes the very same differential equation I am using and turns it into a simple diffusion equation but could not find it today. However I did write it down and use it often..
. However the most elegant form of what I'm working on is the simple ODE. It was not my idea and was so simple that I could kick myself.

The ordinary differential equation is

D C"(x) - u C'(x) - k C(x) ==0

and of course it has cases depending on the coefficients. This model was custom made for Uranium Roll front deposits. Because of the cases associated with the constants each combination of constants D, u, k is a period in the life time of the deposit. It was hinted to me that if D and u are known then the reaction rate can be estimated-- something not known back in 1982.

Once again, Thanks very much.

Very truly yours,

Mike Bernthal

Sorry but what is "barometric flow"?

Not barometric flow, but barometric equation.

https://en.wikipedia.org/wiki/Barometric_formula

If you have the diffusion equation with drift

D c''[ x, t ] - u c' [x, t] == D[c[ x, t ], t]

it should be the solution for the steady state, when D [ c[ x, t ], t ] =0 and c is a function of x only.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract