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 332207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:50:45+00:00 2026-05-12T09:50:45+00:00

I am using OdePkg in Octave to solve a system of stiff ODEs, e.g.

  • 0

I am using OdePkg in Octave to solve a system of stiff ODEs, e.g. by ode5r:

function yprime = myODEs(t,Y,param)
    yprime = [
        - param(1) * Y(1);                      # ODE for Y(1)
        param(1) * Y(1) - param(2) Y(2) * Y(3); # ODE for Y(2)
        param(2) Y(2) * Y(3)                    # ODE for Y(3)
                                                # etc.
];

time_span = [1, 24]         # time span of interest
Y0        = [1.0, 1.1, 1.3] # initial values for dependent variables Y
param     = [7.2, 8.6, 9.5] # parameters, to be optimized

[t, Y] = ode5r(@myODEs, time_span, Y0, ..., param);

The solver stores the dependent variables Y in a matrix with respect to time t (vector):

t     Y(1)  Y(2)  Y(3)
0.0   1.0   1.1   1.3
0.1   ...   ...   ...
0.5   ...   ...   ...
0.9   ...   ...   ...
...   ...   ...   ...
4.0   ...   ...   ...
...   ...   ...   ...
24.0  ...   ...   ...

I want to fit the parameters in param, so that the resulting variables Y best fit my reference values, e.g.:

t         Y(1)  Y(2)  Y(3)
0.5       1.1   N/A   N/A
1.0       1.9   N/A   N/A
4.0       2.3   2.7   2.1
5.0       N/A   2.6   2.2
24.0      0.9   1.5   2.0

Which Octave/Matlab (other languages are welcome) routine can perform a multi-parameter (least square / spline) fit?
How is it possible to combine parameter sets for different initial values Y0 in the fit?
I would be glad if you could provide me with some hints and possibilities.

Best regards,
Simon

  • 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-05-12T09:50:45+00:00Added an answer on May 12, 2026 at 9:50 am

    This should be relatively straightforward with scipy. scipy.optimize.leastsq() takes a function that should return an array of residuals for a given parameter vector. It will minimize the sum of the squares of the residuals. To handle multiple datasets with different initial values, you just run the ODE once for each dataset, compute the residuals for each dataset/run pair, and then concatenate the residual vectors together. Here is a rough sketch:

    import numpy
    from scipy import integrate, optimize
    
    # The initial guess.
    p0 = numpy.array([7.2, 8.6, 9.5])
    
    # The collected datasets.
    # A list of (t, y0, y) tuples.
    # The y's are all (len(y0), len(t))-shaped arrays. The output of
    # integrate.odeint is also in this format.
    datasets = [...]
    
    def odes(y, t, params):
        dydt = [
            -params[0] * y[0],
            params[0]*y[0] - params[1]*y[1]*y[2],
            params[1]*y[1]*y[2],
        ]
        return np.array(dydt)
    
    def residuals(params, datasets):
        res = []
        for t, y0, y in datasets:
            res.append(integrate.odeint(odes, y0, t, args=(params,)) - y)
    
        # Stack them horizontally and flatten the array into the expected vector.
        # You're on your own for handling missing data. Look into the numpy.ma
        # module.
        all_residuals = numpy.hstack(res).ravel()
        return all_residuals
    
    opt_params, err = optimize.leastsq(residuals, p0, args=(datasets,))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Delphi 2010. I am looking for (possibly) a function or procedure which can
Using online interfaces to a version control system is a nice way to have
Using C# and System.Data.SqlClient, is there a way to retrieve a list of parameters
Using a CSS image sprite, I'm creating an 'interactive' image where hovering over certain
Using a populated Table Type as the source for a TSQL-Merge. I want to
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
Using SQL Server 2008 R2 we are looking for a way to select the
Using CI for the first time and i'm smashing my head with this seemingly
Using the Redis info command, I am able to get all the stats of
Using Location.getBearing(); I seem to get randomly changing bearings. Aka, I can turn the

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.