Results 1 to 3 of 3

Math Help - Matlab - Too many inputs to inline function

  1. #1
    Newbie
    Joined
    Sep 2013
    From
    England
    Posts
    4

    Matlab - Too many inputs to inline function

    Hi,

    When I run the following section of my function, (with f a function of x, y and z), I get the following error: "Too many inputs to inline function".

    syms x y z

    a = inline(char(diff(f,x)));

    f = matlabFunction(f);

    if a(x0,y0,z0) == 0
    % something happens
    end


    I think this is because, when you differentiate my function f wrt x, df/dx is only a function of x and z, not of y. I have checked this with a function such that when you differentiate it wrt x, it still remains a function of x, y and z, and my program works fine.

    Could anyone please advise me on how to fix this, so that 'a' just ignores the fact that it's not a function of y and evaluates f at x0 and z0?

    Thankyou




    Follow Math Help Forum on Facebook and Google+

  2. #2
    Super Member
    Joined
    Oct 2012
    From
    Ireland
    Posts
    583
    Thanks
    155

    Re: Matlab - Too many inputs to inline function

    I think the problem is that x0, y0 and z0 are inputs for the function diff(f,x) not for the inline function. If I am interpreting the code correctly I think that a only has one input and that is the value of char(diff(f,x))
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Sep 2013
    From
    England
    Posts
    4

    Re: Matlab - Too many inputs to inline function

    Thanks for your reply. I tried getting rid of the 'char' and then using 'subs' to calculate the values a, b and c at x0, y0, z0. This seems to work but now I have another issue...

    For the following code, the output I get for f(x(1),y(1),z(1)) is not what a numerical answer as I would expect - it still contains x's (and to be honest, I can't work out exactly how the program is calculating the output it gives!). I've checked that x(1), y(1) and z(1) are numerical answers. Basically, I was wondering if anyone can spot anything wrong with this code? I know it should be really basic but I can't work out what's going on!

    syms x y z

    a = diff(f,x);
    b = diff(f,y);
    c = diff(f,z);

    f = matlabFunction(f);

    m0 = input(' % required input ');

    x(1) = x0 - m0*subs(a,[x,y,z],[x0,y0,z0]);
    y(1) = y0 - m0*subs(b,[x,y,z],[x0,y0,z0]);
    z(1) = z0 - m0*subs(c,[x,y,z],[x0,y0,z0]);

    f(x(1),y(1),z(1))



    If it helps, when f = 0.4*x.^2 + 0.2*y.^2 + z.^2 + x*z, (x0,y0,z0) = (1,1,1) and m0 = 0.4, the output I get for f is ((2*x)/5 - 1/5)^2 - (3*x)/25 + 741/3125.

    Thanks for any help
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Replies: 0
    Last Post: March 15th 2012, 09:42 AM
  2. Orthogonal inputs to a function - same expected value?
    Posted in the Discrete Math Forum
    Replies: 0
    Last Post: October 14th 2011, 04:32 AM
  3. Matlab function with vector inputs and matrix outputs
    Posted in the Math Software Forum
    Replies: 3
    Last Post: August 6th 2009, 09:49 PM
  4. Replies: 0
    Last Post: August 5th 2009, 12:51 PM
  5. Inline function
    Posted in the Math Software Forum
    Replies: 1
    Last Post: February 9th 2009, 12:21 AM

Search Tags


/mathhelpforum @mathhelpforum