Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8085899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:16:48+00:00 2026-06-05T18:16:48+00:00

I have a non ode function that calculates based on the previous time step

  • 0

I have a non ode function that calculates based on the previous time step of a time vector and spatial variable vector.

One of the parameters in this function is constant. However, I want to make that parameter a variable, which will change based at a given time.

Here is some example code to make this clear.

nstrains = 10;
param = .3*rand(1,nstrains);
strtime = rand(1,nstrains);
strtime = round(strtime);
strtime = sort(strtime);

initialconds = .5
t=0:.1:10; %time vector
x=1:.1:10; %spatial vector

k = zeros(numel(x),numel(t))
k = zeros(numel(x)/2,1) = initialconds

for i = 1:(numel(t)-1)

for j = 2:(numel(x)-1)

k(j,i+1) = 5*2+c(j+1,i)+param*c(j,1)+param

end 

end

If param was held constant, this would be no problem. What I want to do is have a vector of random numbers for param, that enter random number for param at random times. The random time is determined by strtime.

So for example, if strtime vector = [2 4 9 10], and 
param vector = [.21 .01 .25 .05]

First, I want an initial param value at time 0 = .2 (arbitrary). As soon as my
time vector matches with my strtime vector, which in this example is 2, then 
my param value is updated to .21. .21 will be used at each time step until my 
time vector matches my strtime vector again, which in this case, would be 4. By 
time step 4, .01 is used as my param value, and so on. 

I cannot really figure out how to get this down since the function is indexed in such a way. Is there a way to do this whilst keeping the function indexed the way it is, just somehow updating param to the new value determined by strtime vector?

Thanks, and hope I was clear enough.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T18:16:50+00:00Added an answer on June 5, 2026 at 6:16 pm

    Create a vector, the same size as your time vector t, with the appropriate parameter value for each time.

    Taking your example data, here is one way to do it:

    First, at the beginning of the strtime and param vectors, add the initial conditions (t>=0, param starts as .2).

    strtime = [0 2 4 9 10];
    param = [.2 .21 .01 .25 .05];

    Next, for each element in t, find the largest element in strtime that is less-than-or-equal-to that time point, and use that index to find the appropriate param. Here, I’ve done this with arrayfun rather than implementing it as a for loop, though conceptually they are the same.

    p = arrayfun(@(x) param(find(strtime<=x,1,’last’)), t);

    Now you’ve got a vector, p, which you can index into with i (replace param in your loop section with p(i)).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In one of the projects I have non-English content (Finnish) available on form data.
I have an (non-virtualized) ItemsControl that binds its ItemsSource to a ObeservableCollection of ViewModel
I want to have an EC2 based cluster that can grow and shrink at
The problem is the following. There are multiple rows that have non-unique identifiers: id
I would like to detect strings that have non-whitespace characters in them. Right now
I have a function which returns non-void. On the caller side, I want to
I've been trying to deal with some delimited text files that have non standard
I have non-looping audio that I need to have as little latency as hardware-ically
I have a static C library where I have non static call back function.
I have the following one-to-one relation in Hibernate (that could be null): <one-to-one name=details

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.