comp.lang.idl-pvwave archive - RDF feed
type: channel
description: Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
items: Solving a non-linear equation
items: Re: Solving a non-linear equation

Solving a non-linear equation
type: item
description: Hi, My problem is this: I have a non-linear equation, of the form y = exp(x)+x. I have a large matrix of Y values, and for each cell (Y-value) I would like to calculate a best-fit X. How can I do this??? I have tried defining a function (exp(x)+x), which I could then get the root of by a number of methods. However I would need to first subtract my Y, before I found the root. The problem then becomes, how can I tell IDL to find the root of exp(x)+x-Y, for a range of Y values? Eeek my brain!
creator: Reetsspacey
date: 2014-04-02T14:33:43-00:00

Re: Solving a non-linear equation
type: item
description: On Wednesday, April 2, 2014 10:33:43 AM UTC-4, Reetsspacey wrote: > Hi, > > > > My problem is this: I have a non-linear equation, of the form y = exp(x)+x. I have a large matrix of Y values, and for each cell (Y-value) I would like to calculate a best-fit X. How can I do this??? The easiest way is to use Newton's method. If you're trying to find the root of f(x), given a trial solution of x0, the next best solution is, x = x0 - f(x0) / f'(x0) where f'(x0) is the derivative of the function. Now you have a new x0 and can try again for multiple iterations. For you, this would be, in IDL language, for i = 0, n_iter-1 do begin x = x0 - (x + exp(x) - y)/(1 + exp(x)) x0 = x endfor Your function is very well behaved (no extrema) so you should be able to pick x0=0 as your starting point and then keep iterating until you achieve the desired precision. Craig
creator: Craig Markwardt
date: 2014-04-02T15:36:15-00:00

Re: Solving a non-linear equation
type: item
description: On Wednesday, 2 April 2014 11:36:15 UTC-4, Craig Markwardt wrote: > On Wednesday, April 2, 2014 10:33:43 AM UTC-4, Reetsspacey wrote: > >> Hi, > >> > >> > >> > >> My problem is this: I have a non-linear equation, of the form y = exp(x)+x. I have a large matrix of Y values, and for each cell (Y-value) I would like to calculate a best-fit X. How can I do this??? > > > > The easiest way is to use Newton's method. > > > > If you're trying to find the root of f(x), given a trial solution of x0, the next best solution is, > > x = x0 - f(x0) / f'(x0) > > where f'(x0) is the derivative of the function. Now you have a new x0 and can try again for multiple iterations. > > > > For you, this would be, in IDL language, > > for i = 0, n_iter-1 do begin > > x = x0 - (x + exp(x) - y)/(1 + exp(x)) > > x0 = x > > endfor > > > > Your function is very well behaved (no extrema) so you should be able to pick x0=0 as your starting point and then keep iterating until you achieve the desired precision. > > > > Craig Brilliant, that makes sense! Thank you!
creator: Reetsspacey
date: 2014-04-02T17:45:05-00:00