rm(list = ls())
fel1= read.csv("fel1.csv", header =TRUE)
Docao=c(0.2, 0.6, -0.5, 0.6, -0.3, -1.0, 1.9, 2.4, 2.2, 2.6, 3.0, 1.7, 2.0, 2.1, 2.0 , 1.5 ,-4.0, -8.0, 4.0, 8.0)
MUL=c(0.65105471, 0.63637423, 0.65823176, 0.60723248, 0.66687195, 0.51560137, 0.30664784, 0.34455834, 0.28627146 ,0.29141037,
0.27963273, 0.35984204, 0.34687026 ,0.35898475, 0.34282619, 0.38650902, 0.03333333, 0.00100000, 0.10000000, 0.10000000)
plot(MUL~Docao,fel1)
min_el=-10
funfel1 = function(Docao,a1,a2,el1,el2,apha,beta) ((1-a1)*(1-exp(-((Docao-min_el)/(el1-min_el)^apha)))+a1)*(exp(-((Docao-min_el)/(el2-min_el))^beta))+(a2*(1-(exp(-((Docao-min_el)/(el2-min_el))^beta))))
model2 <- nls(MUL~funfel1(Docao,a1,a2,el1,el2,apha,beta),data=fel1 ,start=list(a1=0.02,a2=0.1,el1=-1,el2=1.5,apha=12,beta=5.9),trace=T)
summary(model2)
# [Error in nlsModel(formula, mf, start, wts) :
singular gradient matrix at initial parameter estimates]
m = predict(model2,newdata=Docao)
plot(MUL~Docao,fel1,ylim=c(0,1),xlim=c(-10,10),xlab="Elevation (m)",ylab="Multipler (MUL)")
curve(funfc(Docao,a1=0.02,a2=0.1,el1=-1,el2=1.5,apha=12,beta=5.9),add = TRUE, col = "red",lwd=2)