MATLAB Answers

Koen
0

matrix product in function handle

Asked by Koen
on 7 Nov 2014
Latest activity Edited by Adam
on 7 Nov 2014
hello,
I have 2 functions defined:
trig = @(y) a(1)/2 + a(2:6)*cos((1:5).'*y) + b(2:6)*sin((1:5).'*y) (with given vectors a and b)
f = @(y) (y.^(2:-1:0))*[0; 0; 1]
If I want to calculate trig([0 1]) it does give me the answer but if I do f([0 1]) I get the error 'Matrix dimensions must agree' . In both functions you multiple a 'vector with symbolics' with a given numeric vector, but why i get an error in the second case and the answer i expect in the first one?
thanks in advance

  0 Comments

Sign in to comment.

1 Answer

Answer by Adam
on 7 Nov 2014
Edited by Adam
on 7 Nov 2014

Try just typing:
[0,1].^(2:-1:0)
on the command line and you will see you get the same error. It isn't a function handle-related problem, just the usual problem with mis-matched dimensions. You should be able to use bsxfun to achieve the result you want, depending what you expect the result of that operation to be.
bsxfun( @power, y, (2:-1:0)' )
should work I think in your f = @(y) function

  0 Comments

Sign in to comment.