Reputation: 121
I cannot for the life of me figure out why these two functions produce different answers, both of which do the same thing.
avocado = function(Tx,Tn,P,b1=17.71,b2=-0.29,b3=3.25,b4=-0.14,b5=1.00,b6=-0.31,b7=-288.09){
yield_anomaly = (b1*Tx)+(b2*(Tx^2))+(b3+Tn)+(b4*(Tn^2))+(b5*P)+(b6*(P^2))+b7
return(yield_anomaly)
}
avocado(Tx=34,Tn=17,P=2) #Answer = -40.65 tons/acre
and the one that produces the wrong answer
avo.yield = function(tmax, tmin, prcp,tmax.c1=17.71, tmax.c2 = -0.29, tmin.c1 = 3.25, tmin.c2 = -0.14, prcp.c1=1, prcp.c2 = -0.31){
yeild = (tmax.c1*tmax)+(tmax.c2*(tmax^2)) + (tmin.c1*tmin)+(tmin.c2*(tmin^2)) + (prcp.c1*prcp)+(prcp.c2*(prcp^2)) - 288.09
return(yeild)
}
avo.yield(tmax=34, tmin=17, prcp=2) #answer -5.64
Upvotes: 0
Views: 61
Reputation: 12418
In the first function you have
(b3+Tn)
In the second function you have
(tmin.c1*tmin)
One is multiplication, one is addition
Upvotes: 3