I am trying to make a composite function consisting of 3 exponential functions:
rm(list=ls())
library(mosaic)
library(ggplot2)
# 3 functions
NVent=makeFun(161*exp(-x/51028)~x) # from x [0;259200[
Vent3_4=makeFun(1262*exp(-x/48398)~x) # from x [0;345600[
SVent=makeFun(118*exp(-x/217427)~x) # from x [0;1036800]
#composite function
QTOT <- function(x) {
if (x<259200) return(NVent(x)+Vent3_4(x)+SVent(x)),
if (259200<x<345600) return(Vent3_4(x) + SVent(x)),
if (345600<x<1036800) return(SVent(x))
}
but get an error:
Error: unexpected '<' in:
" if (x<3) return(NVent(x)+Vent3_4(x)+SVent(x))
if (3<x<"
> if (4<x<12) return(SVent(x))
Error: unexpected '<' in " if (4<x<"
> }
Error: unexpected '}' in "}"
>
As far as understand I don´t write the intervals correctly, but have not been able to correct it nor find examples that can help me, so I would really appreciate your input !