I was trying to obtain mles of the scale and shape parameter for the weibull distribution using the optim function.
The code is as follows:
weibull_data= rweibull(1000,shape=2,scale=3)
log_lik_weibull=function(par,obs_data){
n=length(obs_data)
a=par[1]
b=par[2]
n*(log(a)-log(b))+(a-1)(sum(log(obs_data))-nlog(b))-(a/b)*
sum(obs_data)
}

optim(c(1,1),log_lik_weibull,obs_dat=weibull_data,control = list(fnscale=-1))$par
This gives parameter estimates of 0.86, 2.63 which is significantly different from my shape and scale parameters.
I feel the log likelihood function is correct however I am not able to obtain reliable estimates.
Any help will be appreciated.

Thank you so much. My log likelihood function was wrong. I had the power in the wrong place. I corrected it:
weibull_data= rweibull(1000,shape=2,scale=3)
log_lik_weibull=function(par,obs_data){
n=length(obs_data)
a=par[1]
b=par[2]
sumobs=sum(obs_data)
sumlog_obs= sum(log(obs_data))
n*(log(a)-log(b))+(a-1)(sumlog_obs-nlog(b))-(1/b^a)*sum(obs_data^a)
}

Got 1.93 & 2.96 now. Didn't know about the fitdistr. I will look into it.
About missing the * it's in my code somehow when I copy the code here it's not showing.