Matlab; Defining a Function with various constants

So when I create a function with arbitrary constants, for instance $\displaystyle 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.

xlabel('Radial Distance');

ylabel('Effective Potential');

y = V(x);

plot(x,y)

Re: Matlab; Defining a Function with various constants

Quote:

Originally Posted by

**adkinsjr** So when I create a function with arbitrary constants, for instance $\displaystyle 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);

should work, otherwise add them as additional arguments.

.

Re: Matlab; Defining a Function with various constants

Quote:

Originally Posted by

**adkinsjr** 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.

xlabel('Radial Distance');

ylabel('Effective Potential');

y = V(x);

plot(x,y)

Do the plot before adding the labels.

.