On 101130 03:56 PM, Kimonas Fountoulakis wrote:
> I have a function like this:
>
> A_k = @(x_k)
> A0+A1*x_k(1)+A2*x_k(2)+x_k(1)*x_k(1)*K11+x_k(1)*x_k(2)*K12+x_k(2)*x_k(1)*K21+x_k(2)*x_k(2)*K22;
>
>
> where A's and K's are matrices and x_k are the variables.
>
> Then function always has a specific pattern and I would like the user to
> provide the A and K matrices and then the function will be implemented
> automatically.
>
> In particular, I need something like sum ( A_i * x_k(i)).
>
> Is there any way to implement such a summation? any help appreciated!
function funhandle = buildfun(a0, a1, a2, k11, k12, k21, k22)
funhandle = @(x_k) a0 + a1*x_k(1) + a2*x_k(2) + x_k(1) * x_k(1) * K11 +
x_k(2)*K12 + x_k(2)*x_k(1)*K21 + x_k(2)*x_k(2)*K22;
end
Then call buildfun with the appropriate matrices for the A_k you are assigning
the handle to.
By the way, please consider using cell arrays rather than individual variables.
