# Math Help - function name on graph

1. ## function name on graph

Code:
x=-10:.1:10;
y=sin(x);
plot(x,y);
How can i display the function name on the graph in mat-lab

2. You can use something like:

Code:
title sin(x)
or you can do some nicer things such as:

Code:
close all
x=-10:.1:10;
y=sin(x/2).^(1/2);
plot(x,y);
xlabel x
ylabel y
title('$$Sin\left(\frac{x}{2}\right)^{1/2}$$','Interpreter','latex')

Regards Elbarto

3. but if i pass the function to a method

Code:
function a(f)

title f;

end
now if i call the above function

Code:
a('x+5');
the title will still be f

How can i get through this problem?

4. okay i got it

you can use title(f);

5. Correct. Good work.

Elbarto

6. now i need to have the function name displayed close to the actual graph. ( close to the curve) How can i do it.

7. Code:
>>help text
Much the same as "title" but you provide the position where to place it on the graph.

Elbarto

8. Originally Posted by ilikec
Code:
x=-10:.1:10;
y=sin(x);
plot(x,y);
How can i display the function name on the graph in mat-lab
2-D line plot - MATLAB

CB