Rookie ROOT Graphing Issues

I have three problems that I’ve been trying to tackle for a while now.

1) I have a code for the bisection method. I would like to use TLine *line = new TLine function to create the lines that you normally see in the bisection method.

These lines from a to F(a) are the ones I am talking about.

I have a for statement that does the following:

[code]for(int i = 0; i < 10; i++) //try 10 steps
{
c = 0.5*(x1+x2); // new midpoint
tempy= f->Eval©;

w[i]=x1;
y[i]=x2;

if( fabs(tempy) < 0.00001 ) break;// found it!

if( tempy*f(x1) > 0 ) x1 =c;
else x2=c;

cout<<"\nThe value is: “;
cout<< c <<”\n\n The function value at this point is: "<<tempy<<endl;

cout<<“x1 = “<<w[i]<<”, x2 = " <<y[i]<<endl ;
cout<<”\n\n Function evaluated at x1 = “<Eval(w[i])<<”\n\n Function evaluated at x2 = "<Eval(y[i])<<endl;

}[/code]

And this works great! I get the x1 and x2 values that I need into the w[i] and y[i] arrays, and I can even evaluate them at my function.

But when I type something like:

TLine *line2 = new TLine(w[i], 0, w[i], f->Eval(w[i])); TLine *line3 = new TLine(y[i], 0, y[i], f->Eval(y[i])); line2->SetLineColor(kBlack); line3->SetLineColor(kBlack); line2->Draw("SAME"); line3->Draw("SAME");

In a different for statement, it ruins the code.
I’m guessing this is because when I create the TLine i am creating just one TLine called ‘line2’ and trying to feed it many different lines.
But, I do not know how to make it so that I can get TLine *linei where i goes through the for loop i++.

2) The exponential function.
I am using root and I want to graph a function that looks like the following:
v = (a/b) (1-e^(-bt))

I try to define the exponential function part as float expo = exp(-b*t)
but this doesn’t seem to work. I am guessing the exponential function does not work with root.
How can I get this to work? I know that there is some TMath:: things out there, but I have never been able to get them to work.

3. I am trying to write text on my graph, but It wont let me use a variable.

I have a simple TF1 graph that depicts free fall motion. I have solved it using the quadratic formula to find the root aka the time it takes for the particle to reach the floor.
I have this root labeled as t.

In my code I have the following:

TF1 *fa1 = new TF1("fa1","[0]*x*x+[1]*x+[2]",0,2*t); fa1->SetParameters(-0.5*g,v,h); fa1->SetTitle("Projectile Motion"); fa1->GetYaxis()->SetTitle("Height in meters"); fa1->GetXaxis()->SetTitle("Time in seconds"); TLine *line = new TLine(0,0,2*t,0); line->SetLineColor(kBlue); TText *z = new TText(.5, -20, "Solution for t = ", t); z->SetTextSize(0.02); fa1->Draw(); line->Draw(); z->Draw();

As you can see, I am trying to use TText to let me write on the graph the "solution for t = " t.
But this doesn’t work. The TText doesn’t seem to know what to do when I simply write t.

Any suggestions on these three problems?

I thank you all greatly.

It would have been better to do 3 posts.

can ou post a small example showing the “ruined” lines ?

saame as for 1) can you post a piece of code showing what you do ?

  1. can you provide a running example ? what you sent gives me:
input_line_15:2:47: error: use of undeclared identifier 't'
 (new TF1(("fa1", "[0]*x*x+[1]*x+[2]", 0, 2 * t)))
                                              ^
input_line_16:2:56: error: use of undeclared identifier 'g'
 (((*(class TF1 **)0x1090b7ab8))->SetParameters(-0.5 * g, v, h))
                                                       ^
input_line_16:2:59: error: use of undeclared identifier 'v'
 (((*(class TF1 **)0x1090b7ab8))->SetParameters(-0.5 * g, v, h))
                                                          ^
input_line_16:2:62: error: use of undeclared identifier 'h'
 (((*(class TF1 **)0x1090b7ab8))->SetParameters(-0.5 * g, v, h))