# Math Help - Matlab; Defining a Function with various constants

1. ## Matlab; Defining a Function with various constants

So when I create a function with arbitrary constants, for instance $f(x)=\frac{a}{x}-\frac{b}{x^2}$, how can I make multiple plots of this function using different values for the parameters 'a' and 'b' without having to make a separate file for each pair of (a,b).... My function file looks like this,

function Veff = V(x)
a = 1
b = 1
Veff = a*x.^(-1) - b*x.^(-2)

I also have another file that creates the plot when I run it, although the code I'm using for the x and y labels does not seem to be working. The graph shows up without the labels.

ylabel('Effective Potential');
y = V(x);
plot(x,y)

2. ## Re: Matlab; Defining a Function with various constants

So when I create a function with arbitrary constants, for instance $f(x)=\frac{a}{x}-\frac{b}{x^2}$, how can I make multiple plots of this function using different values for the parameters 'a' and 'b' without having to make a separate file for each pair of (a,b).... My function file looks like this,

function Veff = V(x)
a = 1
b = 1
Veff = a*x.^(-1) - b*x.^(-2)
define a and b at the console or in the outer script, then

Code:
function Veff = V(x)
global a
global b
Veff = a*x.^(-1) - b*x.^(-2);

.