开发者

Matlab - input argument is not defined

I have this very simple function in matlab.

function [f]=f1(a, xx)
xx
f = -exp(-a(1)*(xx(1)-1)^2 - a(2)*(xx(2)-1)^2) - exp(-a(1)*(xx(1)+1)^2 -a(2)*(xx(2)+1)^2);

I开发者_JAVA百科t does print the value of xx, and then complains "Input argument "xx" is undefined". How is this possible? What's going on?

I call the function with feval Here is another example that doesn't use feval. I get the error Input argument "xxx" is undefined. Please help me, I have no idea what's going on and I'm stuck.

I have: function [ ans ] = f2( xxx ) xxx %f2 is 1/(1+xxx^2), the function for problem 2 ans = 1 / (1+xxx^2); end

one file is neville.m

Q = neville(x,xi,f2) %NEVILLE implements Neville method for polynomial interpolation

nplus1 = max(size(xi)); Q = zeros(nplus1); Q(:,1) =f2(xi);

for i = 2 : nplus1 for j = 2 : i Q(i, j) = ((x - xi(i-j)) * Q(i, j-1) - (x - x(i))*Q(i-1, j-1)) / (x(i) - x(i-j)); end; end;

The other file is neville_driver.m N = 6; aux = [0:6]; xi = -5 + 10*aux/N;

Q = neville(4, xi, f2)


Looks like you're passing a function f2 into neville.m. Try using Q=neville(x,xi,@f2); Also, if xi is a vector, you should use element wise multiplication (and raising it to the nth power) using a dot (.) before the operation, else it will give an error. i.e., 1/(1+xxx.^2).


Is xx a function? Because the syntax xx(2) is a function call. Did you mean xx*2 ?

Edit: your first example code works fine for me:

feval(@f1,[2,2],[10,10]);

Prints xx and then the result.

Edit2: and the code for f1:

function [f]=f1(a, xx)
xx
f = -exp(-a(1)*(xx(1)-1)^2-a(2)*(xx(2)-1)^2)-exp(-a(1)*(xx(1)+1)^2-a(2)*(xx(2)+1)^2);
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜