tags:

views:

69

answers:

1
>> fplot(fh,[-2 4])
??? Undefined function or variable "e".

Error in ==> myfun at 3
Y(:,2) = e(:).^x;
Error in ==> fplot at 102
x = xmin; y = feval(fun,x,args{4:end});

I tried to plot two function using this m file.

function Y = myfun(x)
Y(:,1) = 3*x;
Y(:,2) = e(:).^x;
+1  A: 

As Donnie mentioned in their comment, the variable e is undefined in your m-file.

If you have defined e elsewhere, you have to pass it to myfun so that the function knows its value. Since fplot does not accept plotting functions with more than one input value, you need to pass it an anonymous function.

First, you need to change the definition of myfun to include e as input:

function Y = myfun(x,e)
Y(:,1) = 3*x;
Y(:,2) = e(:).^x;

Then, you create your function handle fh like this (fh still only takes one input, Matlab uses the value of e as it was defined in the workspace at the time you create the function handle):

fh = @(x)(myfun(x,e))

Finally, you can call fplot like you used to

fplot(fh,[-2 4])
Jonas
problem solved . But Can some one tell how to get root visually on the graph.?
udsha
In the figure window, click on the data cursor and read the x-value of the root from the datatip, as demonstrated here: http://www.mathworks.com/access/helpdesk/help/techdoc/creating_plots/f4-44221.html
Jonas

related questions