Using anonymous functions with vectors of unknown number of elements and getting the coefficients associated with the variables
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello everyone,
I hope that everyone is doing good.
I am aware that the description or summary of my question is quite not clear, so I will explain here what I mean exactly by the title, and feel free to ask any question if you feel things are still not clear.
So I have the following example, from the book (Kernel Adaptive Filtering: A Comprehensive Introduction):
and basically, what I am trying to implement (1.29), such that u will be a (1 x n) vector given by the user, and then c will be (1 x n) arbitrary vector with the values [c1 c2 c3 c4 ... cn]. So obviously, I do not know the number of elements in c unless I know the number of elements of the given vector, u.
So that is my first concern, how I can identify a function with a vector of unknown variables, such that the number of variables is equal to the number of elements in the given vector.
Second, after implementing this function, I want to find the coefficients of c1, c2, c1c2, such that Ii put the coefficients in an array.
Can anyone help me with this? I have been looking for some helpful functions in matlab, but I did not find any.
Thank you
Ahmed AR
2 commentaires
Réponse acceptée
Torsten
le 22 Sep 2022
Then
n_s = 2;
u = randi([-9999, 9999], 1, n_s)
c = sym('c',size(u));
kappa = expand((1+u*c.')^2)
coefficients = coeffs(kappa)
10 commentaires
Torsten
le 23 Sep 2022
I don't see the rule of the ordering - neither in your vectors phi(u) and phi(c) nor in the MATLAB ordering.
But I think you cannot inluence it. If it were the case, it should be mentionned in the documentation of "coeffs".
Look it up.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Matrix Indexing 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!