0

我已经开始使用 R 来解决一个复杂的方程。生成方程后,我尝试使用Ryacas. 不幸的是,不是给我结果,而是Ryacas返回以下内容:

CommandLine(1):达到最大评估堆栈深度。请根据需要使用 MaxEvalDepth 增加堆栈大小。
CommandLine(1):达到最大评估堆栈深度。请根据需要使用 MaxEvalDepth 增加堆栈大小。

你能告诉我如何增加堆栈大小Ryacas吗?我尝试了很多方法,但我真的不知道如何利用Ryacas给我的建议。

===== 编辑 =======

所以这是导致生成我想要求解的方程的代码。

#define net and gross values
net=10000
gross=12563.49

#construct an array for cash flows
flows=matrix(nrow=1, ncol=60)

#populate the array with cash flows
flows[c(1:60)]=c(-297.21)

#generate the equation
#flows
eq1=NULL
for (i in 1:60) {
  eq1=paste(eq1," + ", toString(flows[i]),"/((1 + x)^(",i, "/60)", ") ", collapse="")
}
#complete
equation=paste(toString(net), eq1, " == ", toString(gross), collapse="")

然后我尝试使用解决它Solve(equation, "x").

4

1 回答 1

1

这看起来像 APR 的方程。尝试像这样的简单迭代:

#inputs
instalments=60
net=12800
monthly=387.63
interest=0.1890

#function
CalculateAPR <- function(InitialPayout, InterestRate, N, MonthlyRepayment) {
  i <- InterestRate 
  repeat{
    DF <- sapply(1:N, function(N) { MonthlyRepayment/((1+i)^(N/12)) } )
    if(InitialPayout>=sum(DF)) break()
    i <- i + 0.00001
  }
return(i)
}

#output
ans=CalculateAPR(net, interest, instalments, monthly)
rm(list = c('instalments', 'interest', 'monthly', 'net'))
print(ans)

您可能想尝试一种比这个更有效的算法,它只是在每次迭代中增加 0,001%。

于 2013-09-24T12:32:14.140 回答