Error while drawing graph

root

variable length array declaration not allowed at file scope
Double_t x[n], y[n], x1[n], y1[n];

Add const:

const Int_t n = 20;

or use a std::vector<double> if you don’t know the length during compile time.

Thank you very much.
This time the error looks like this.

/home/souvik/Downloads/root/SB_root/./gra2.cc:4:30: error: redefinition of ‘y1’ as different kind of symbol
Double_t x[n], y[n], x1[n], y1[n];
^
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:251:13: note: previous definition is here
__MATHCALL (y1, (Mdouble));

Unfortunately y1 is a function (bessel y1, see here: https://www.gnu.org/software/libc/manual/html_node/Special-Functions.html or http://reference.wolfram.com/language/ref/BesselY.html for an explanation), so you cannot use the name “y1” in interactive code. Simply use a different name for the variable.

To look at y1(x):

TF1 *f = new TF1("f", "y1(x)", 0.1, 30);
f->Draw();

On the other hand, it is not a problem to use the name y1 for normal local variables. So are copy-pasting the code into ROOT interacrively? Or are you missing a function name in the macro, i.e. does your macro start with just { instead of void functionName() { ?

I tried with the above method defining y1(x). But it is showing error. Mine is unnamed macro.

Thanks.

I didn’t show a method defining y1! I showed how y1 is defined and how to look at the graph of the y1 function. The y1 function is the reason for the error message!

So either use a different name or (better) name your macro!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.