Writing code for given general matrix in MATLAB

3 次查看(过去 30 天)
How do I write a code for the following matrix of order cM X cM?
Here, where are all known scalars and 's are function handles which I have defined using cell array as h_{i,j}.

采纳的回答

Walter Roberson
Walter Roberson 2022-2-20
c = 3
c = 3
M = 5
M = 5
syms h(T) [c, M]
syms t [c, M]
H = reshape(cellfun(@(C) reshape(C.', 1, []), h(t), 'uniform', 0).',[],1);
H = vertcat(H{:})
H = 
  5 个评论
Walter Roberson
Walter Roberson 2022-2-21
In the below, it is possible to write mappingfun as an anonymous function -- but it was a lot easier to debug as a real function.
The code is a bit clumsy. The challenge is in naming what to subs() . For example for h1_1(t1_1) call, if you try to subs h as a whole, something like subs(H, h, h_) then h is not an array: when gnerated by syms(T) [c,M] then the name h becomes a single symfun that returns an array... and you cannot break apart a symfun that returns an array into its component entries using any supported function.
If you invoke the function with a definite argument then you start getting mismatches for the purpose of substitution. The dummy functions like h2_3(T) exist but no references to those occur in the array: the array has entries such as h2_3(t1_4) and subs() will not pattern-match the (T) to the (t1_4) . So you start having to extract the symbol name and read the indices out of the name and use those...
The code would probably be easier (or cleaner) if it was permitted to generate the array with the function handle calls in place, instead of having to create the array as pure symbolic first, and then substitute in the function handles.
c = 3;
M = 5;
for i = 1:M
H_{i} = @(x) besselj(i, x);
end
for c = 1:c
for i=1:M
h_{c,i} = @(t) H_{i}(t+1-c);
end
end
syms h(T) [c, M]
syms t [c, M]
H = reshape(cellfun(@(C) reshape(C.', 1, []), h(t), 'uniform', 0).',[],1);
H = vertcat(H{:})
H = 
output = mapSymType(H, 'symfun', @(X) mappingfun(X,h_))
output = 
function mapped = mappingfun(F, h)
symfunname = symFunType(F);
idx = sscanf(symfunname, 'h%d_%d');
mapped = h{idx(1), idx(2)}(children(F,1));
end
Saurabh Madankar
Saurabh Madankar 2022-2-22
I haven't really understood the code totally, but I will give some time and see. Thanks for answering.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by