Writing code for given general matrix in MATLAB
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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
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)
