Reputation: 1
This is the first time I'm trying to solve a set of "highly" nonlinear set of equations with R. Please see the following code. The goal is to find Le and c such that Sum_F=0 and Sum_M=0. I get "Error in nleqslv(c(50, 25), fn) : Length of fn result <> length of x!". I'm a newbie in this aspect of R and appreciate if somebody can help me to fix this error. Thanks in advance for your help!
CODE:
library(nleqslv)
Vn<- 1052.676
fc<- 4
epsilon_f<- 0.0035
epsilon_01<- 0.002
epsilon_085<- 0.0038
min_epsilon<- 0.0003
max_epsilon<- 0.0114
bf<- 15.4
g<- 48
fn<- function(x) {
Le<- x[1]
c<- x[2]
if(c>0.75*Le) {c<- 0.75*Le}
if(c<0.1*Le) {c<- 0.1*Le}
fmax<- 0.85*fc
ff<- fmax-(0.15*fmax)*(epsilon_f-epsilon_01)/(epsilon_085-epsilon_01)
c1<- c*(epsilon_01/epsilon_f)
c2<- c-c1
cf1<- (2/3)*bf*fmax*c1
xbar_f1<- (5/8)*c1
cf2<- bf*0.5*(ff+fmax)*c2
xbar_f2<- ((fmax+2*ff)/(3*(fmax+ff)))*c2
epsilon_b<- epsilon_f*(Le-c)/c
if(epsilon_b>max_epsilon) {epsilin_b<- max_epsilon}
if(epsilon_b<min_epsilon) {epsilon_b<- min_epsilon}
if(epsilon_b<epsilon_01){
cb1<- bf*fmax*epsilon_b*(Le-c)*((1/epsilon_01)-epsilon_b/(3*epsilon_01^2))
xbar_b1<- (((2/(3*epsilon_01))-epsilon_b/(4*epsilon_01^2))/
((1/epsilon_01)-epsilon_b/(3*epsilon_01^2)))*(Le-c)
cb2<- 0
xbar_b2<- 0
}
if(epsilon_b>=epsilon_01){
c4<- Le-c-c1
cb1<- (2/3)*WF[i,"bf"]*fmax*c1
xbar_b1<- (5/8)*c1
fb<- fmax-(0.15*fmax)*(epsilon_b-epsilon_01)/(epsilon_085-epsilon_01)
cb2<- bf*0.5*(fb+fmax)*c4
xbar_b2<- ((fmax+2*fb)/(3*(fmax+fb)))*c4
}
show(c(Vn,bf,g,fc,0.5*g,fmax,Le,c, #show values to check fn is working
ff,c1,cf1,xbar_f1,c2,cf2,xbar_f2,epsilon_b,fb,cb1,xbar_b1,c4,cb2,xbar_b2))
Sum_F<- -Vn-cb1-cb2+cf1+cf2
Sum_M<- -Vn*(0.5*g+c)+cb1*xbar_b1+cb2*(c1+xbar_b2)+
cf1*xbar_f1+cf2*(c1+xbar_f2)
show(c(Sum_F,Sum_M))
return(sum(c(Sum_F,Sum_M)))
}
Le_c<- nleqslv(c(50,25),fn)
I've found a few posts about the same error message. However, those cases were simpler than this case and not applicable.
Upvotes: 0
Views: 46