Matrix of functions of two variables

3 vues (au cours des 30 derniers jours)
Arijit De
Arijit De le 9 Mai 2013
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 commentaires
James Kristoff
James Kristoff le 9 Mai 2013
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?
Arijit De
Arijit De le 9 Mai 2013
Modifié(e) : Arijit De le 9 Mai 2013
Thanks for your comment! Let me clarify: Here I know a function f(t). Say, t1 = t2 = 1, 2, 3. So, I want to construct the matrix: F = [f(t1)f(t2)] = [f(1)f(1) f(2)f(1) f(3)f(1); f(1)f(2) f(2)f(2) f(3)f(2); f(1)f(3) f(2)f(3) f(3)f(3)]

Connectez-vous pour commenter.

Réponse acceptée

James Kristoff
James Kristoff le 9 Mai 2013
Modifié(e) : James Kristoff le 9 Mai 2013
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 commentaire
Arijit De
Arijit De le 10 Mai 2013
great! thanks a lot!

Connectez-vous pour commenter.

Plus de réponses (1)

Sean de Wolski
Sean de Wolski le 9 Mai 2013
F = bsxfun(@times,t1,t2)
And for more info:
doc bsxfun
  2 commentaires
Arijit De
Arijit De le 9 Mai 2013
Modifié(e) : Sean de Wolski le 9 Mai 2013
Thanks for the answer; but I am not doing pairwise (binary) multiplication; let me clarify: Here I know a function f(t). Say, t1 = t2 = 1, 2, 3. So, I want to construct the matrix:
F = [f(t1)f(t2)] = [f(1)f(1) f(2)f(1) f(3)f(1); f(1)f(2) f(2)f(2) f(3)f(2); f(1)f(3) f(2)f(3) f(3)f(3)]
Sean de Wolski
Sean de Wolski le 9 Mai 2013
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...

Connectez-vous pour commenter.

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by