matrix product in function handle
1 view (last 30 days)
Show older comments
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
Answers (1)
Adam
on 7 Nov 2014
Edited: 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
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!