matrix product in function handle

3 次查看(过去 30 天)
Koen
Koen 2014-11-7
编辑: Adam 2014-11-7
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

回答(1 个)

Adam
Adam 2014-11-7
编辑:Adam 2014-11-7
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

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by