matrix product in function handle
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Adam
le 7 Nov 2014
Modifié(e) : Adam
le 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 commentaires
Voir également
Catégories
En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!