Can't figure out why my function wont evaluate my input? Any suggestions? Thanks

3 views (last 30 days)
I have a list of guess and a function
guess=[4,4;4,5;5,4]
fun=@(x,y)(1.5-x+x*y)^2+(2.25-x+x*(y^2))^2+(2.65-x+x*(y^3))^2
fun(guess(1,:))
I believe what I asking matlab is evaluate this function for row1 and all its columns which I believe is (4 4) but matlab outputs not enough input arguments please help!! Am I not grabbing position (4,4).
I tried this inputs just to see matlab output
guess(1,:)
output=[4 4]
Therefore I am totally confused as to why it does not work? Thanks for any assistance!! :)

Answers (1)

Walter Roberson
Walter Roberson on 19 Nov 2013
You defined your anonymous function as requiring two arguments, x and y. You are, instead, passing in a single argument that is a row with two columns. You need to rewrite in those terms
fun=@(x)(1.5 - x(:,1) + x(:,1).*x(:,2)).^2 + (2.25 - x(:,1) + x(:,1) .* (x(:,2).^2)).^2 + (2.65 - x(:,1) + x(:,1) .* (x(:,2).^3)).^2

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!