Results 1 to 2 of 2

Thread: Basic Matlab help please

  1. #1
    Sep 2013

    Basic Matlab help please

    Hi, my code keeps giving me the following error:

    Undefined function or variable 'u'.

    Error in

    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;
    q = d*(symsum(y(z*d),z,1,m-1) + y(m*d));

    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);


    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.
    Last edited by rc2208; Sep 11th 2013 at 01:49 AM.
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Senior Member zzephod's Avatar
    Apr 2012

    Re: Basic Matlab help please

    Why have you declared x to be a symbolic variable?

    Also I don't think quad accepts an upper limit of inf.

    Again, I don't think quad accepts functions with two arguments and you should not need the second one as it is in scope anyway.

    Last edited by zzephod; Sep 11th 2013 at 11:26 PM.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Replies: 4
    Last Post: Mar 6th 2013, 10:03 PM
  2. help with basic matlab input. dot problem
    Posted in the Math Software Forum
    Replies: 1
    Last Post: Aug 2nd 2012, 04:55 AM
  3. Basic Matlab help. Can't seem to grasp basic concept
    Posted in the Math Software Forum
    Replies: 5
    Last Post: Feb 28th 2010, 08:12 PM
  4. Basic MATLAB questions
    Posted in the Math Software Forum
    Replies: 3
    Last Post: May 1st 2009, 03:15 AM
  5. [SOLVED] basic matlab problem giving me errors
    Posted in the Math Software Forum
    Replies: 2
    Last Post: Feb 14th 2009, 01:53 PM

Search Tags

/mathhelpforum @mathhelpforum