peter lopez
peter lopez

Reputation: 1

Problem in curve fitting library minpack.lm, nlsLM. "R"

In an internal combustion engine project, I am modeling the fraction of fuel combusted in a Diesel engine as a function of the crankshaft displacement angle, using the Wiebe Triple equations. I was able to adjust with simple Wiebe, but when adapting it with triple Wiebe, it gives me an error. The parameters I have are:

B: Fraction of fuel consumed a: A dimensionless parameter that adjusts the speed of combustion. A higher value of 𝑎 a indicates faster combustion. It is adjustable and is determined empirically so that the model fits the experimental data. m: A dimensionless shape parameter that determines the shape of the mass fraction burned curve. It influences the progression of combustion. Typical values of 𝑚 m are usually between 2 and 3 for combustion in gasoline engines. Like 𝑎 a, it is adjusted empirically so that the model fits the experimental data. x: Represents the angle dt: The duration of the combustion stage Vectors:

x <- c(-2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80)
y <- c(0.0000000000, -0.0008498228, 0.0026669466, 0.0137066362, 0.0350628717, 0.0651226751, 0.1044401254, 0.1601040186, 0.2250765891, 0.2956831501, 0.3639996732, 0.4270331941, 0.4860570974, 0.5413469643, 0.5959598595, 0.6469872638, 0.6954183545, 0.7405939517, 0.7823187572, 0.8224111204, 0.8594575094, 0.8893692055, 0.9127143894, 0.9333008633, 0.9507713251, 0.9659867742, 0.9790950325, 0.9886601504, 0.9969754388, 1.0043024466, 1.0091244301, 1.0124438334, 1.0145376061, 1.0162124373, 1.0176002043, 1.0179056936, 1.0173053806, 1.0170185611, 1.0162144572, 1.0144884869, 1.0130148340, 1.0114058985, 1.0094877589, 1.0085280356, 1.0079127146, 1.0064885630, 1.0052025852, 1.0041812397, 1.0025294652, 1.0009113773, 0.9995867446, 0.9980699113, 0.9968017347, 0.9955057367, 0.9940506704, 0.9930958819, 0.9923287468, 0.9915419585, 0.9908831396, 0.9901665134, 0.9896797411, 0.9894449691, 0.9893329073, 0.9893900038, 0.9892629625, 0.9893904248, 0.9897536193, 0.9900880068, 0.9906745593, 0.9912219929, 0.9918945864, 0.9925614367, 0.9927732484, 0.9927850417, 0.9930300302, 0.9934880235, 0.9938521069, 0.9943406575, 0.9950791599, 0.9960654992, 0.9974121017, 0.9987179396, 1.0000000000)
x <- data3$angulo
y <- xb_exp

triple_wiebe <- function(B1, B2, t2, t3, a1, a2, a3, m1, m2, m3, dt1, dt2, dt3) {
  return(
    (B1 * (1 - exp(-a1 * ((x - (-2)) / dt1)^(m1 + 1)))) +
    ((B2 * ((1 + sign(x - t2)) / 2) * (1 - exp(-a2 * ((x - t2) / dt2)^(m2 + 1))))) +
    (((1 - B1 - B2) * ((1 + sign(x - t3)) / 2) * (1 - exp(-a3 * ((x - t3) / dt3)^(m3 + 1)))))
  )
}

ajuste <- nlsLM(
  y ~ triple_wiebe(B1, B2, t2, t3, a1, a2, a3, m1, m2, m3, dt1, dt2, dt3), 
  start = c(a1 = 3, a2 = 3, a3 = 3, m1 = 5, m2 = 5, m3 = 5, B1 = 0.3, B2 = 0.3, t2 = 10, t3 = 20, dt1 = 5, dt2 = 25, dt3 = 35),
  lower = c(a1 = 2.3, a2 = 2.3, a3 = 2.3, m1 = 1, m2 = 1, m3 = 1, B1 = 0, B2 = 0, t2 = 0, t3 = 10, dt1 = -2, dt2 = 5, dt3 = 15),
  upper = c(a1 = 6.9, a2 = 6.9, a3 = 6.9, m1 = 10, m2 = 10, m3 = 10, B1 = 0.5, B2 = 0.4, t2 = 15, t3 = 30, dt1 = 40, dt2 = 60, dt3 = 81),
  control = nls.lm.control(ftol = 1e-8, ptol = 1e-8, maxfev = 5000)
)
summary(ajuste)

I need to obtain the values of: B1, B2, t2, t3, a1, a2, a3, m1, m2, m3, dt1, dt2, dt3.

I am encountering the error: "Error in numericDeriv(form[[3L]], names(ind), env): missing value or an infinity produced when evaluating the model".

Upvotes: 0

Views: 10

Answers (0)

Related Questions