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

  • Home
  • SEARCH
  • 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 8683899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:09:43+00:00 2026-06-12T22:09:43+00:00

Is is it possible to use an ODE solver, such as ode45, and still

  • 0

Is is it possible to use an ODE solver, such as ode45, and still be able to ‘change’ values for the parameters within the called function?

For example, if I were to use the following function:

function y = thisode(t, Ic)
% example derivative function

% parameters
a = .05;
b = .005;
c = .0005;
d = .00005;

% state variables
R = Ic(1);
T = Ic(2);

y = [(R*a)-(T/b)+d; (d*R)-(c*T)];

with this script:

clear all
% Initial conditions
It = [0.06 0.010];
% time steps
time = 0:.5:10;
% ODE solver
[t,Ic1] = ode45(@thisode, time, It);

everything works as I would expect. However, I would like a way to easily change the parameter values, but still run multiple iterations of the ODE solver with just one function and one script. However, it does not seem like I can just add more terms to the ODE solver, for example:

function y = thisode(t, Ic, P)

% parameters
a = P(1);
b = P(2);
c = P(3);
d = P(4);

% state variables
R = Ic(1);
T = Ic(2);

y = [(R*a)-(T/b)+d; (d*R)-(c*T)];

with this script:

clear all
% Initial conditions
It = [0.06 0.010];
P1 = [.05 .005 .0005 .00005]
% time steps
time = 0:.5:10;
% ODE solver
[t,Ic1] = ode45(@thisode, time, It, [], P1);

does not work. I guess I know this shouldn’t work, but I have been unable to come up with a solution. I was also considering an if statement within the function and then hard coding several sets of parameters based to be used (e.g use set 1 when P == 1, set 2 when P == 2, etc) but this also did not work as I don’t where to call the set to be used with an ODE. Any tips or suggestion on how to use one function and one script with an ODE solver while being able to change parameter values would be much appreciated.

Thank you,
Mike

  • 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-12T22:09:44+00:00Added an answer on June 12, 2026 at 10:09 pm

    You’ll have to call the function differently:

    [t,Ic1] = ode45(@(t,y) thisode(t,y,P1), time, It);
    

    The function ode45 assumes all functions passed to it accept only an t and a y. The above call is a standard trick to get Matlab to pass P1, while ode45 will pass it t and y on every call.

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

Sidebar

Related Questions

Can functors be defined locally within the body of a function? One possible use
Possible Duplicate: Use 'class' or 'typename' for template parameters? I see two different template
is it possible use the ko.computed write function on the foreach $data variable like
Is it possible use regex to remove small words in a text? For example,
what could be a possible use of declaring types within a namespace but not
Is it possible use in-explicit constructing with operators ? Just like in this example
Possible Duplicate: How to detect if a function is called as constructor? I would
I have recently started looking into Google Charts API for possible use within the
Is it possible use mod_rewrite to resolve addresses hosted on another server? Say I
Is it possible use a MySQL query to perform this kind of check? If

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.