Thanks, but I think "if iter > 2" (line 21) makes sure that x_previous is 
defined in the previous iteration. Just to be clear, the condition to check 
here was "g_norm > g_norm_old", but I changed it to get there as early as 
the second iteration.  

On Tuesday, April 28, 2015 at 9:13:49 PM UTC-4, Avik Sengupta wrote:
>
> I'm seeing the error in line 22 of your gist where you are trying to print 
> the current value of "x_previous". However, x_previous is first defined in 
> line 38 of your gist, and so the error is correct and doesnt have anything 
> to do with Optim, as far as I can see. 
>
> On Wednesday, 29 April 2015 01:39:02 UTC+1, Pooya wrote:
>>
>> Hi all,
>>
>> I have a problem that has made me scratch my head for many hours now! It 
>> might be something obvious that I am missing. I have a Newton-Raphson code 
>> to solve a system of nonlinear equations. The error that I get here does 
>> not have anything to do with the algorithm, but just to be clear, I need to 
>> find the best possible solution if the equations are not solvable, so I am 
>> trying to stop simulation when the direction found by Newton-Raphson is not 
>> correct! In order to do that I put an if-loop in the beginning of the main 
>> loop to take x from the previous iteration (x_previous), but I get 
>> x_previous not defined! I am using the Optim package to do a line search 
>> after the direction has been found by Newton-Raphson. If Optim is not used, 
>> things work perfectly (I tried by commenting out those lines of code). 
>> Otherwise I get the error I mentioned. My code is here: 
>> https://gist.github.com/prezaei85/372bde76012472865a94, which solves a 
>> simple one-variable quadratic equation. Any thoughts are very much 
>> appreciated.
>>
>> Thanks,
>> Pooya
>>
>

Reply via email to