Hi, my code keeps giving me the following error:

Undefined function or variable 'u'.

Error in

program1/@(x)exp(-v.^3*a*x.^-3*q)/(x*(exp(u*x/(k*S))-1))

Error in quadgk/evalFun (line 339)

fx = FUN(x);

Error in quadgk/f2 (line 370)

[y,too_close] = evalFun(t2t);

Error in quadgk/vadapt (line 258)

[fx,too_close] = f(x);

Error in quadgk (line 205)

[q,errbnd] = vadapt(@f2,interval);

Error in program1 (line 46)

Q = quad(f,0,inf);

I have tried for ages to figure out what the problem is but I'm not getting anywhere, so if anyone could offer some advice it would be much appreciated.

Here is the problem section of the code:

for m = 1:n

if m == 1

q = 0;

else

q = d*(symsum(y(z*d),z,1,m-1) + y(m*d));

end

syms x

f = @(x,u) exp(-v.^3*a*x.^-3*q)/(x*(exp(u*x/(k*S))-1));

Q = quad(f,0,inf);

g = @(u) abs(2*pi*k*a*R.^2*v.^3*c.^-2*u*(m*d).^2*Q - B*(H-u).^2);

u1 = 0;

u2 = H;

if g(u1) < 500

y(m) = u1;

elseif g(u2) < 500

y(m) = u2;

elseif g(u2) <= g(u1)

u1 = 0.5*(u1+u2);

elseif g(u1) < g(u2)

u2 = 0.5*(u1+u2);

end

Basically, the code is trying to solve the equation 2*pi*k*a*R.^2*v.^3*c.^-2*u*(m*d).^2*Q = B*(H-u).^2 for u using an iterative method.

d, n, v, a, S, k, c, H, b are all constants that have been defined earlier in the program.

I'm fairly new to matlab by the way, so I'm sure the error is something stupid on my part. For example, I'm not sure if I've defined the functions f and g correctly for how I want to use them - I have tried several different ways of defining them but had no luck

Thanks again for any help.