forum.alglib.net

ALGLIB forum
It is currently Fri Dec 13, 2024 5:52 am

All times are UTC


Forum rules


1. This forum can be used for discussion of both ALGLIB-related and general numerical analysis questions
2. This forum is English-only - postings in other languages will be removed.



Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Pass results of one variable of ODE solution into array
PostPosted: Thu Sep 22, 2022 6:45 pm 
Offline

Joined: Wed Jul 20, 2022 11:27 pm
Posts: 4
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;
}



Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group