How to solve nonlinear optimization problem in R Suppose I have a set of data and reason to believe the following relation holds
y ~ a0 + a1*x1 + a2*x2 + a3*log(x3)
How can I use R to solve for the coefficients {a0, ... a3}, supposing I want to minimize the squared error of my data?  Also, can I do this using weights?
As an example suppose I give you the data
set.seed(2014)
df <- expand.grid(x1 = c(1,1.5,2,2.5,3), 
                 x2 = c(1,1.5,2,2.5,3),
                 x3 = c(5000, 10000, 20000, 40000, 50000))
df$y <- 5 + 10*df$x1 + 5*df$x2 + 3*log(df$x3) + rnorm(nrow(df))
head(df)
   x1  x2   x3     y
1 1.0 1.0 5000 44.99
2 1.5 1.0 5000 50.87
3 2.0 1.0 5000 55.68
4 2.5 1.0 5000 61.90
5 3.0 1.0 5000 64.26
6 1.0 1.5 5000 48.37

Without cheating, how can you figure out that a0 = 5, a1 = 10, a2 = 5 and a3 = 3?
 A: I am confused here. Why would you treat this as the nonlinear optimization problem, given that you set it up as an ordinary linear regression problem? To me this is exactly the ordinary linear regression. Given that you add random errors to the response, you would not expect the obtain exactly the parameter values.
> fit <- lm(y ~ x1 + x2 + log(x3), data = df)
> summary(fit)

Call:
lm(formula = y ~ x1 + x2 + log(x3), data = df)

Residuals:
     Min       1Q   Median       3Q      Max 
-3.02223 -0.58469 -0.01113  0.60692  2.30452 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)   7.0027     1.1682   5.994 2.17e-08 ***
x1            9.7412     0.1359  71.684  < 2e-16 ***
x2            4.8860     0.1359  35.955  < 2e-16 ***
log(x3)       2.8834     0.1120  25.737  < 2e-16 ***
---
Signif. codes:  
0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 1.074 on 121 degrees of freedom
Multiple R-squared:  0.9832,    Adjusted R-squared:  0.9828 
F-statistic:  2365 on 3 and 121 DF,  p-value: < 2.2e-16

The estimates are very close to the true values of the parameters $a0, a1, a2, a3$, given that the sample size is 125.
Hope this helps.
