# Matlab - Too many inputs to inline function

• Sep 24th 2013, 08:10 AM
rc2208
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

• Sep 24th 2013, 08:16 AM
Shakarri
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))
• Sep 25th 2013, 07:12 AM
rc2208
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