Writing code for given general matrix in MATLAB
显示 更早的评论
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}.
采纳的回答
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 个评论
This does give me the required matrix but how do I replace
's from your code to my predefined function handles? This is how I have defined the function handles-
for c = 1:3
for i=1:5
h_{c,i} = @(t) H_{i}(t+1-c);
end
end
for c = 1:3
for i=1:5
h_{c,i} = @(t) H_{i}(t+1-c);
end
end
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 =

subs(H, num2cell(h), h_)
Undefined variable H_.
Error in solution (line 3)
h_{c,i} = @(t) H_{i}(t+1-c);
Error in sym>funchandle2ref (line 1601)
S = x(S{:});
Error in sym>tomupad (line 1514)
x = funchandle2ref(x);
Error in sym (line 332)
S.s = tomupad(x);
Error in sym/subs>@(x)sym(x) (line 217)
Y = cellfun(@(x)sym(x),Y,'UniformOutput',false);
Error in sym/subs>normalize (line 217)
Y = cellfun(@(x)sym(x),Y,'UniformOutput',false);
Error in sym/subs>mupadsubs (line 165)
[X2,Y2,symX,symY] = normalize(X,Y); %#ok
Error in sym/subs (line 153)
G = mupadsubs(F,X,Y);
This is the error I am getting-
Error using sym/subs>normalize (line 239)
Entries in second argument must be scalar.
Error in sym/subs>mupadsubs (line 165)
[X2,Y2,symX,symY] = normalize(X,Y); %#ok
Error in sym/subs (line 153)
G = mupadsubs(F,X,Y);
Error in Extended (line 34)
subs(H, num2cell(h), h_)
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
I haven't really understood the code totally, but I will give some time and see. Thanks for answering.
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Conversion Between Symbolic and Numeric 的更多信息
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
