Hi, I need to put some equation into array(located inside function). This equation was made inside class (with method) and passed to vector. The equation is further used in another source code. The compiler doesn't give any error, but program can't start and then there is a windows error. If I write equation[1] mannually like other 2 it works perfectly. I'm new with C++, and learning it for few weeks now. These are the important parts of my code, I can post it whole if needed, please help.
This is function which is used in another source code:
1 2 3 4 5 6 7 8 9 10
double equation[3];
void f(double t, double x[3]) // These pamarameters are passed inside this
// function by the other source code (which is
// using this function)
{
equation[0] = eqP[0];
equation[1] = 0.5*x[0]-0.25*x[1];
equation[2] = 0.25*x[1]-0.1666*x[2];}
I will have to replace the other 2 equations as well, with eqP[1] and [2] but I want to try it by steps if it works. Also there will be more variables then d, in class method, these variables are calculated inside another method of class (this works fine).
#include <iostream>
#include <vector>
#include <cmath>
#include "Elementys.h"
usingnamespace std;
int main ()
{
int N;
vector<object>PotVect;
for (N=0; N<6;N++)
{
object *point_pot = new p(5.0,5.0,5.0,5.0,5.0); //there will be allways another input from text file
point_pot -> Calc();
point_pot -> SetParam(5);
PotVect.push_back(*point_pot);
}
return 0;
}
And finnally here are the objects, it's called "Elementys.h" (will be more of them later):
#include <iostream>
#include <vector>
#include <cmath>
usingnamespace std;
constdouble Pi = 3.14159;
constdouble Ro = 1000;
constdouble v = 5.0;
constdouble V = 5.0;
constint P=7;
double equation[P];
double x[P];
vector<double>eqP;
class object
{
protected:
int type; //These will be used later
int Number;
int Group;
public:
object() {}
virtual ~object (){}
virtualvoid Calc(){}
virtualvoid SetParam(double s){}
};
class p : public object
{
protected:
double d;
double min;
double max;
double ksi_m;
double l;
public:
p(double diam, double leng,double z_begin, double z_end, double ksi_loc)
{ d=diam;
l=leng;
z_begin=min;
z_end=max;
ksi_loc=ksi_m;}
virtual ~p(){};
double Re; double ka; double lambda;
virtualvoid Calc()
{
Re=((d*v)/V);
ka=(Pi*pow(d,2.0)/(4.0*Ro*l));
if (Re < 2300.0)
lambda = (64.0/Re);
else
lambda = (0.3164/(pow(Re,0.25)));
}
virtualvoid SetParam(double s)
{ double equationE;
equationE = (-0.5*x[0]*Re*s*d+ka*x[1]); //I altered the equation a bit
eqP.push_back(equationE);
{ cout << ka << "\t" << lambda << "\t" << Re <<"\t";}}
};
It's not everything in one main function, but it will be in the end.
Everything works fine, however I need to create lot of objects with lot of different functions, and then pass them into RK program. I repeat that I'm new into C++ so maybe there are some stupid things in code (I believe you could write it in better way)
Ok, so I put the whole thing under one main function and now it can be compiled and started, however the term eqP[0]=-0.5*x[0]*Re*s*d+ka*x[1] is taken as zero, and it's not used with RK-system as an array. Any advice how to get it to work?