Using anonymous functions with vectors of unknown number of elements and getting the coefficients associated with the variables

3 views (last 30 days)
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 Comments
Ahmed Radhi
Ahmed Radhi on 22 Sep 2022
So basically, through some inputs, the user will declare the dimension of the vector
% n_u = input("input dimension n_u: ");
% n_s = input("state dimension n_s: ");
% n_y = input("output dimension n_y: ");
Based on the inputs, I will have a randomly initialized vector of size (1 x n_s) as shown in the following code:
% Assume n_s = 0
n_s = 2;
u = randi([-9999, 9999], 1, n_s)
u = 1×2
6113 1041
So yah, that is how we initially supply the vector.

Sign in to comment.

Accepted Answer

Torsten
Torsten on 22 Sep 2022
Then
n_s = 2;
u = randi([-9999, 9999], 1, n_s)
u = 1×2
-5089 -4994
c = sym('c',size(u));
kappa = expand((1+u*c.')^2)
kappa = 
coefficients = coeffs(kappa)
coefficients = 
  10 Comments

Sign in to comment.

More Answers (0)

Categories

Find more on Descriptive Statistics 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!