I am trying to graph a surface with a diagonal matrix, the equation I am trying graph is f = x^TDx, x is a 2 by 1 vector and D is a 2 by 2 matrix.
Here is what have so far, but I keep getting error.
x = linspace(-10,10);
y = linspace(-10,10);
[X,Y] = meshgrid(x,y);
D = [2 1; 1 2];
f = @(x,y) [x,y]*D*[x,y].'; % [x,y] is 1 by 2
contour (X,Y,f(X,Y))
I know that would give me an erros since the dimension of [x,y] and D not macth, I know that if D is a identity matrix, I could use eye(2*numel(x)) to create a 200x200 matrix to match [x,y].
I don't know how to do it with a random and a given diagonal symmetric matrix. Can someone show me how do it? Thanks.

답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2016년 4월 2일

0 개 추천

댓글 수: 4

konoha
konoha 2016년 4월 2일
Thanks. how about for a given matrix, such as [1,2;2,1]
Azzi Abdelmalek
Azzi Abdelmalek 2016년 4월 2일
about what?
konoha
konoha 2016년 4월 2일
to apply f = x^T*D*x
Azzi Abdelmalek
Azzi Abdelmalek 2016년 4월 2일
The sizes must match

댓글을 달려면 로그인하십시오.

카테고리

질문:

2016년 4월 2일

댓글:

2016년 4월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by