Writing code for given general matrix in MATLAB
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Saurabh Madankar
am 20 Feb. 2022
Kommentiert: Saurabh Madankar
am 22 Feb. 2022
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}.
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 20 Feb. 2022
c = 3
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{:})
5 Kommentare
Walter Roberson
am 21 Feb. 2022
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{:})
output = mapSymType(H, 'symfun', @(X) mappingfun(X,h_))
function mapped = mappingfun(F, h)
symfunname = symFunType(F);
idx = sscanf(symfunname, 'h%d_%d');
mapped = h{idx(1), idx(2)}(children(F,1));
end
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Conversion Between Symbolic and Numeric finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



