0
votes

I have a function f = x^2-2xy+y^2, this is the result of 3 2 by 2 matrices after I calculated that by hand. I know how to contour plot with a given function like f. If I have multiple n by m matrices, how do plot them in matlab without calculating them to get f.

Such as, A = [1 0;-1 1; 0 -1]; D = [1 0 0;0 2 0; 0 0 4]; then I will have f = [x y]^TA^TDA[x y]. The only way I know is f=@(x,y) [x,y].'A^TDA[x,y], but this gives me an error since the dimensions don't agree.

Is there a way to do this? Thanks

1
It's not clear what you want. - user1543042
@user1543042 I want to contour plot f = [x,y]^T ADA[x,y] where A, D,x are matrices - Simple
What is T? Give an example x, T, and D. With an example f. - user1543042
T is the transpose, x,y are variable, D = [1 0 0; 0 4 0; 0 0 8], f = [x;y]^T*D*[x;y] - Simple
Please include a MCVE - codeaviator

1 Answers

1
votes

Based on your description, which you need to do a better job describing.

[X, Y] = meshgrid(0:0.1:10, 0:0.1:10);
f =@(x,y) cellfun(@(c) c*A'*D*A*c', num2cell([x,y],2));
colormap(jet);
contourf(X, Y, reshape(f(X(:), Y(:)), size(X)),20,'LineStyle','none')