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}.
採用された回答
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 件のコメント
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
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 件)
カテゴリ
ヘルプ センター および File Exchange で Conversion Between Symbolic and Numeric についてさらに検索
参考
2022 年 2 月 20 日
2022 年 2 月 22 日
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
