forum.alglib.net
http://forum.alglib.net/

Pass results of one variable of ODE solution into array
http://forum.alglib.net/viewtopic.php?f=2&t=4474
Page 1 of 1

Author:  bisk [ Thu Sep 22, 2022 6:45 pm ]
Post subject:  Pass results of one variable of ODE solution into array

So I use the MWE from manual.
Only with the slight difference of adding to variables to solve, so that I get a 2d_array.

Then , I need the solution of each variable seperately into an array to pass to other functions that use arrays. Thing is, this works in 1d_array as mentinoned below, but can't make it work with 2d array.

Any idea/hints?
Code:


#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "diffequations.h"
#include "stdafx.h"




using namespace alglib;
void ode_function_1_diff(const real_1d_array &y, double x, real_1d_array &dy, void *ptr)
{
    // this callback calculates f(y[],x)=-y[0]

//CHANGE -> now it's two functions, f(y,x)=-y[0],-0.5y[0] so it actually returns [y[0] ,y[1]] on results
    dy[0] = -y[0];
    dy[1] = -0.5*y[0];
}

int main(int argc, char **argv)
{
    real_1d_array y;
    double _r1[] = {1, 3};
    y.setcontent(2,_r1);
    real_1d_array x = "[0, 1, 3]";
    double eps = 0.00001;
    double h = 0;
    odesolverstate s;
    ae_int_t m;
    real_1d_array xtbl;
    real_2d_array ytbl;
    odesolverreport rep;
    odesolverrkck(y, x, eps, h, s);
    alglib::odesolversolve(s, ode_function_1_diff);
    odesolverresults(s, m, xtbl, ytbl, rep);
    printf("%d\n", int(m));
    printf("%s\n", xtbl.tostring(2).c_str());
    //double *test = double* xtbl

    double* FC_array = &xtbl.getcontent()[0];  //CHANGE: THIS WORKS -> Can get 1d_array to normal Array and works well
    printf("%f\n", FC_array[1]); // EXPECTED: [0, 1, 3]
    printf("%f\n", xtbl.getcontent()[0]); // EXPECTED: [0, 1, 3]
    printf("going to check 2d_array->array\n"); // here I Tried to do the same, for solution (and then figure out how to get only 1st itme of each row)
//THIS DOESN'T WORK
//double* F2C_array = &ytbl.getcontent()[0];  //

    return 0;
}


Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/