How to simulate an equation with variables that change?How to sort a dataframe by multiple column(s)How to join (merge) data frames (inner, outer, left, right)How to sum a variable by groupHow to change facet labels?How to make a great R reproducible exampleChanging column names of a data frameAdding Regression Line Equation and R2 on graphHow do I replace NA values with zeros in an R dataframe?How to check if object (variable) is defined in R?How can we make xkcd style graphs?

Can taking my 1-week-old on a 6-7 hours journey in the car lead to medical complications?

Project Euler Problem 45

What are some countries where you can be imprisoned for reading or owning a Bible?

Golfball Dimples on spaceships (and planes)?

How do I write a vertically-stacked definition of a sequence?

Who's this voice acting performer?

Could this estimate of the size and mass of the Chicxulub Impactor be accurate?

Friend is very nit picky about side comments I don't intend to be taken too seriously

What is the justification for Dirac's large numbers hypothesis?

Are language and thought the same?

What quests do you need to stop at before you make an enemy of a faction for each faction?

GFI outlets tripped after power outage

Was Rosie the Riveter sourced from a Michelangelo painting?

How do I make my fill-in-the-blank exercise more obvious?

How do I delete cookies from a specific site?

Why Is Sojdlg123aljg a Common Password?

What is the name for quantum gates that can be reversed?

Can you fix a tube with a lighter?

Looking for the comic book where Spider-Man was [mistakenly] addressed as Super-Man

Is future tense in English really a myth?

Why are UK MPs allowed to not vote (but it counts as a no)?

Matlab fmincon for a problem with many nonlinear constraints

How to interpret or parse this confusing 'NOT' and 'AND' legal clause

Did the Byzantines ever attempt to move their capital to Rome?



How to simulate an equation with variables that change?


How to sort a dataframe by multiple column(s)How to join (merge) data frames (inner, outer, left, right)How to sum a variable by groupHow to change facet labels?How to make a great R reproducible exampleChanging column names of a data frameAdding Regression Line Equation and R2 on graphHow do I replace NA values with zeros in an R dataframe?How to check if object (variable) is defined in R?How can we make xkcd style graphs?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















The problem is to simulate an equation with variables that change. All the variables are fixed, expect for lower case s and treat_date. Here is the error message:



Error in checkFunc(Func2, times, y, rho) : The number of derivatives
returned by func() (202) must equal the length of the initial
conditions vector (2)


I have tried moving things around but I honestly have no idea what I am doing



seasonal_SI <- function (t, y, parameters) 
S <- y[1]
I <- y[2]
with(as.list(parameters),
julian_date <- t %% 365
v <- ifelse(julian_date >= treat_date &
julian_date < (treat_date + 10) &
treatment, 0.9, v)
beta <- beta0 + s*beta0*sin(2*pi*(julian_date)/365)
dSdt <- b*(1-c*(S+I))*(S+rho*I)-d*S-beta*S*I
dIdt <- beta*S*I-(d+v)*I
res <- c(dSdt, dIdt)
list(res)
)


initials <- c(S=99, I=1)
params <- c(b=.5, c=.01, beta0=5e-3, v=.05, rho=.3, treatment=TRUE,
s=as.numeric(seq(from=0, to=1, by=.01)),
treat_date=as.numeric(seq(from=0, to=355, length.out=101)))
t <- 0:1

library("deSolve")
lsoda(y=initials, times=t, parms=params, func=seasonal_SI)


I would like for it to run and return a graph.










share|improve this question


























  • Running yout code I got. Error in ifelse(julian_date >= treat_date & julian_date < (treat_date + : object 'treat_date' not found

    – LocoGris
    Mar 28 at 5:10











  • You should put your parameters into a list rather than into a vector. Try params <- list(b=.5, c=.01, <...>). There are further issues, though, but this could be a start.

    – jay.sf
    Mar 28 at 7:55

















0















The problem is to simulate an equation with variables that change. All the variables are fixed, expect for lower case s and treat_date. Here is the error message:



Error in checkFunc(Func2, times, y, rho) : The number of derivatives
returned by func() (202) must equal the length of the initial
conditions vector (2)


I have tried moving things around but I honestly have no idea what I am doing



seasonal_SI <- function (t, y, parameters) 
S <- y[1]
I <- y[2]
with(as.list(parameters),
julian_date <- t %% 365
v <- ifelse(julian_date >= treat_date &
julian_date < (treat_date + 10) &
treatment, 0.9, v)
beta <- beta0 + s*beta0*sin(2*pi*(julian_date)/365)
dSdt <- b*(1-c*(S+I))*(S+rho*I)-d*S-beta*S*I
dIdt <- beta*S*I-(d+v)*I
res <- c(dSdt, dIdt)
list(res)
)


initials <- c(S=99, I=1)
params <- c(b=.5, c=.01, beta0=5e-3, v=.05, rho=.3, treatment=TRUE,
s=as.numeric(seq(from=0, to=1, by=.01)),
treat_date=as.numeric(seq(from=0, to=355, length.out=101)))
t <- 0:1

library("deSolve")
lsoda(y=initials, times=t, parms=params, func=seasonal_SI)


I would like for it to run and return a graph.










share|improve this question


























  • Running yout code I got. Error in ifelse(julian_date >= treat_date & julian_date < (treat_date + : object 'treat_date' not found

    – LocoGris
    Mar 28 at 5:10











  • You should put your parameters into a list rather than into a vector. Try params <- list(b=.5, c=.01, <...>). There are further issues, though, but this could be a start.

    – jay.sf
    Mar 28 at 7:55













0












0








0








The problem is to simulate an equation with variables that change. All the variables are fixed, expect for lower case s and treat_date. Here is the error message:



Error in checkFunc(Func2, times, y, rho) : The number of derivatives
returned by func() (202) must equal the length of the initial
conditions vector (2)


I have tried moving things around but I honestly have no idea what I am doing



seasonal_SI <- function (t, y, parameters) 
S <- y[1]
I <- y[2]
with(as.list(parameters),
julian_date <- t %% 365
v <- ifelse(julian_date >= treat_date &
julian_date < (treat_date + 10) &
treatment, 0.9, v)
beta <- beta0 + s*beta0*sin(2*pi*(julian_date)/365)
dSdt <- b*(1-c*(S+I))*(S+rho*I)-d*S-beta*S*I
dIdt <- beta*S*I-(d+v)*I
res <- c(dSdt, dIdt)
list(res)
)


initials <- c(S=99, I=1)
params <- c(b=.5, c=.01, beta0=5e-3, v=.05, rho=.3, treatment=TRUE,
s=as.numeric(seq(from=0, to=1, by=.01)),
treat_date=as.numeric(seq(from=0, to=355, length.out=101)))
t <- 0:1

library("deSolve")
lsoda(y=initials, times=t, parms=params, func=seasonal_SI)


I would like for it to run and return a graph.










share|improve this question
















The problem is to simulate an equation with variables that change. All the variables are fixed, expect for lower case s and treat_date. Here is the error message:



Error in checkFunc(Func2, times, y, rho) : The number of derivatives
returned by func() (202) must equal the length of the initial
conditions vector (2)


I have tried moving things around but I honestly have no idea what I am doing



seasonal_SI <- function (t, y, parameters) 
S <- y[1]
I <- y[2]
with(as.list(parameters),
julian_date <- t %% 365
v <- ifelse(julian_date >= treat_date &
julian_date < (treat_date + 10) &
treatment, 0.9, v)
beta <- beta0 + s*beta0*sin(2*pi*(julian_date)/365)
dSdt <- b*(1-c*(S+I))*(S+rho*I)-d*S-beta*S*I
dIdt <- beta*S*I-(d+v)*I
res <- c(dSdt, dIdt)
list(res)
)


initials <- c(S=99, I=1)
params <- c(b=.5, c=.01, beta0=5e-3, v=.05, rho=.3, treatment=TRUE,
s=as.numeric(seq(from=0, to=1, by=.01)),
treat_date=as.numeric(seq(from=0, to=355, length.out=101)))
t <- 0:1

library("deSolve")
lsoda(y=initials, times=t, parms=params, func=seasonal_SI)


I would like for it to run and return a graph.







r






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 7:53









jay.sf

10.8k3 gold badges21 silver badges46 bronze badges




10.8k3 gold badges21 silver badges46 bronze badges










asked Mar 28 at 4:25









Amos EpelmanAmos Epelman

61 bronze badge




61 bronze badge















  • Running yout code I got. Error in ifelse(julian_date >= treat_date & julian_date < (treat_date + : object 'treat_date' not found

    – LocoGris
    Mar 28 at 5:10











  • You should put your parameters into a list rather than into a vector. Try params <- list(b=.5, c=.01, <...>). There are further issues, though, but this could be a start.

    – jay.sf
    Mar 28 at 7:55

















  • Running yout code I got. Error in ifelse(julian_date >= treat_date & julian_date < (treat_date + : object 'treat_date' not found

    – LocoGris
    Mar 28 at 5:10











  • You should put your parameters into a list rather than into a vector. Try params <- list(b=.5, c=.01, <...>). There are further issues, though, but this could be a start.

    – jay.sf
    Mar 28 at 7:55
















Running yout code I got. Error in ifelse(julian_date >= treat_date & julian_date < (treat_date + : object 'treat_date' not found

– LocoGris
Mar 28 at 5:10





Running yout code I got. Error in ifelse(julian_date >= treat_date & julian_date < (treat_date + : object 'treat_date' not found

– LocoGris
Mar 28 at 5:10













You should put your parameters into a list rather than into a vector. Try params <- list(b=.5, c=.01, <...>). There are further issues, though, but this could be a start.

– jay.sf
Mar 28 at 7:55





You should put your parameters into a list rather than into a vector. Try params <- list(b=.5, c=.01, <...>). There are further issues, though, but this could be a start.

– jay.sf
Mar 28 at 7:55












1 Answer
1






active

oldest

votes


















0
















I agree with the former comment, that you may consider to use a parameter list. However, you may also consider to use a forcing function or the event mechanism.



You find help pages in deSolve:



?forcings
?events



and a short tutorial here: https://tpetzoldt.github.io/deSolve-forcing/deSolve-forcing.html






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );














    draft saved

    draft discarded
















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55390152%2fhow-to-simulate-an-equation-with-variables-that-change%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0
















    I agree with the former comment, that you may consider to use a parameter list. However, you may also consider to use a forcing function or the event mechanism.



    You find help pages in deSolve:



    ?forcings
    ?events



    and a short tutorial here: https://tpetzoldt.github.io/deSolve-forcing/deSolve-forcing.html






    share|improve this answer





























      0
















      I agree with the former comment, that you may consider to use a parameter list. However, you may also consider to use a forcing function or the event mechanism.



      You find help pages in deSolve:



      ?forcings
      ?events



      and a short tutorial here: https://tpetzoldt.github.io/deSolve-forcing/deSolve-forcing.html






      share|improve this answer



























        0














        0










        0









        I agree with the former comment, that you may consider to use a parameter list. However, you may also consider to use a forcing function or the event mechanism.



        You find help pages in deSolve:



        ?forcings
        ?events



        and a short tutorial here: https://tpetzoldt.github.io/deSolve-forcing/deSolve-forcing.html






        share|improve this answer













        I agree with the former comment, that you may consider to use a parameter list. However, you may also consider to use a forcing function or the event mechanism.



        You find help pages in deSolve:



        ?forcings
        ?events



        and a short tutorial here: https://tpetzoldt.github.io/deSolve-forcing/deSolve-forcing.html







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Apr 2 at 14:56









        tpetzoldttpetzoldt

        1014 bronze badges




        1014 bronze badges





















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.




















            draft saved

            draft discarded















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55390152%2fhow-to-simulate-an-equation-with-variables-that-change%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript