User forums > Using Code::Blocks
[SOLVED] koolplot: merging several functions expressions to one graph
(1/1)
Glxblt76:
Dear Code::Blocks users and developers, :)
I'm looking for the right platform to ask my question but it turns to be quite difficult. It concerns the koolplot plugin implemented in Code::blocks EP, which enables to print graphs easily from C code. More information >> here <<.
My question is simple. How to specify to koolplot functions a "spline" function, that is, a function which follows different expressions in different ranges? For example, from x=-6 to x=-4, I want a kind of minus inverse function, then from -4 to -3 I want a linear function, and from -3 to 0 I want a constant function (horizontal line). How to specify such thing to Plotdata or whatever so it displays only one function with these 3 behaviors?
I tried to put several functions and to use breakplot, but I couldn't specify the range in which each function is defined, so for example I had the minus inverse function, the linear function and the horizontal line superimposed from -6 to 0.
Any help would be greatly appreciated. :)
Glxblt76:
Trying to look for the answer myself, I found the solution to this problem. The solution was to use only one function, and generate manually all points using a function that I defined myself, then to append all points to the koolplot function. The code looks like this:
My user defined function:
--- Code: ---double ts_f_ln_c(double x, double tension_surface_cmc, double cmc, double pc20)
{
/*all variables declarations and constants calculations*/
if(x < log(cmc/1000.0)/2.303)
{
if(x < -pc20)
{
y = /*something of minus inverse type*/;
}
else
{
y = /*something of linear type */;
}
}
else
{
y = /*something constant*/;
}
return y;
}
--- End code ---
And the koolplot part in my main:
--- Code: --- /**kooplot graph of function with three different expressions**/
plotdata x, y;
clear(x);
clear(y);
for(i = 0 ; i < 1000 ; i ++)
{
x_graphe[i] = 0.0;
y_graphe[i] = 0.0;
x_graphe[i] = log(cmc/1000.0)/2.303 - 4.5 + 6.0 / 1000.0 * i;
y_graphe[i] = ts_f_ln_c(x_graphe[i], tension_surface_cmc, cmc, pc20);
}
insert(x, x_graphe, 1000);
insert(y, y_graphe, 1000);
axesBotLeft(x, y, log(cmc/1000.0)/2.303 - 4.5, 20);
axesTopRight(x, y, log(cmc/1000.0)/2.303 + 1.5, 80);
plot(x, y);
--- End code ---
So I consider this topic as SOLVED :)
Navigation
[0] Message Index
Go to full version