comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Solving a non-linear equation
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Solving a non-linear equation [message #88241] Wed, 02 April 2014 07:33 Go to next message
Reetsspacey is currently offline  Reetsspacey
Messages: 3
Registered: June 2009
Junior Member
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!
Re: Solving a non-linear equation [message #88242 is a reply to message #88241] Wed, 02 April 2014 08:36 Go to previous messageGo to next message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
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
Re: Solving a non-linear equation [message #88243 is a reply to message #88242] Wed, 02 April 2014 10:45 Go to previous message
Reetsspacey is currently offline  Reetsspacey
Messages: 3
Registered: June 2009
Junior Member
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!
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: services provided by Al madinah international university for students
Next Topic: transfer the specific data in array A to array B

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 11:44:35 PDT 2025

Total time taken to generate the page: 0.00559 seconds