Create Blockdiagonal using Cell Array with entries being Function handles

I'm trying to build a Blockdiagonal Matrix A out of a cell array with its entries being function handles. Thus A consists of the identity on each diagonal block with values scaled by the function lambda, which is a function of s, while the x is a known vector - I use it as input to the function.
How can I create the blockdiagonal matrix A out of the 4x1 cell array I have with function handles?
-Using cell2mat() prompts the error: Nonscalar arrays of function handles are not allowed; use cell arrays instead.
- Using blkdiag() does not change anything.
I need a matrix because I will do further multiplication with other 4x4 matrices while the variable s has to be preserved for optimization purposes.
Help is much appreciated, thanks :)
%vector x
x1 = x(1);
x2 = x(2);
%cell array lambda
lambda1 = cell(4,1);
lambda1{1} = @(s)((x1 + 1)^s + (x1-1)^s) / ((x1 + 1)^s - (x1-1)^s);
lambda1{2} = lambda1{1};
lambda1{3} = @(s)((x2 + 1)^s + (x2-1)^s) / ((x2 + 1)^s - (x2-1)^s);
lambda1{4} = lambda1{3};
%..matrix A = blkdiag(lambda1)..?

 採用された回答

Oliver
Oliver 2022 年 12 月 3 日

0 投票

primitive but works:
@(s)[((x1 + 1)^s + (x1-1)^s) / ((x1 + 1)^s - (x1-1)^s), 0, 0, 0;
0, ((x1 + 1)^s + (x1-1)^s) / ((x1 + 1)^s - (x1-1)^s), 0, 0;
0, 0,((x2 + 1)^s + (x2-1)^s) / ((x2 + 1)^s - (x2-1)^s), 0;
0, 0, 0, ((x2 + 1)^s + (x2-1)^s) / ((x2 + 1)^s - (x2-1)^s)];

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

製品

質問済み:

2022 年 12 月 2 日

回答済み:

2022 年 12 月 3 日

Community Treasure Hunt

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

Start Hunting!

Translated by