Matrix of functions of two variables
조회 수: 31 (최근 30일)
이전 댓글 표시
I want to generate a matrix whose elements are functions of two variables, say F=f(t1).*f(t2), where t1 varies along row and t2 along column. How to construct such a matrix? Thanks.
댓글 수: 2
James Kristoff
2013년 5월 9일
Could you please clarify what you are trying to do?
I am not sure if you are trying to make a matrix which contains functions that have two inputs e.g.
[ f1_1(x,y), f1_2(x,y), f1_3(x,y);...
f2_1(x,y), f2_2(x,y), f2_3(x,y);...
f3_1(x,y), f3_2(x,y), f3_3(x,y) ]
or if you have two functions, one for column vectors and one for row vectors, and you would like to multiply the output of these two functions to create a matrix,
or do you have some matrix,
T = [ t1_1, t1_2, t1_3;...
t2_1, t2_2, t2_3;...
t3_1, t3_2, t3_3 ]
and you would like to apply one function to the rows of T and another to the columns of T,
or is it something else?
채택된 답변
James Kristoff
2013년 5월 9일
편집: James Kristoff
2013년 5월 9일
If the function f(t) is linear with respect to t (e.g. f(t) = t.*4 + log(5)) then you can simply multiply your inputs and pass the result to f:
t1 = 1:3;
t2 = 1:3;
T = t1'*t2; % this creates a matrix T
F = f(T); % or F = f(t1'*t2);
If the function f(t) is non-linear with respect to t (e.g. f(t) = t.^2) then you could do the following:
t1 = 1:3;
t2 = 1:3;
f1 = f(t1);
f2 = f(t2);
F = f1'*f2; % or F = f(t1)'*f(t2);
This should also work for if f(t) is linear.
Both of these methods require the function f(t) to be written to allow for element-wise mathematics (i.e. using .* in place of * and .^ in place of ^ etc.)
추가 답변 (1개)
Sean de Wolski
2013년 5월 9일
F = bsxfun(@times,t1,t2)
And for more info:
doc bsxfun
댓글 수: 2
Sean de Wolski
2013년 5월 9일
if f is a scalar function then use
bsxfun(@f,t1,t2)
or construct f on the fly
bsxfun(@(x,y)f(x).*f(y),t1,t2)
It's really not quite clear what f is otherwise...
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!