How can I plot a figure with multiplying a vector with matrices?

How can I plot the below figure in matlab?
I tried the below source code:
[X,Y] = meshgrid(-6:0.1:6);
Z = [X Y].*[2 1;1 3].*([X Y].') + [1 2].*[X Y].' + 3;
surf(X,Y,Z)
colormap(jet)
colorbar
and
[X,Y] = meshgrid(-6:0.1:6);
Z = [X Y]*[2 1;1 3]*([X Y].') + [1 2]*[X Y].' + 3;
surf(X,Y,Z)
colormap(jet)
colorbar
However, it showed the errors:
Error using .*
Matrix dimensions must agree.
Error in Fig20_3 (line 2)
Z = [X Y].*[2 1;1 3].*([X Y].') + [1 2].*[X Y].' + 3;
and
Error using *
Inner matrix dimensions must agree.
Error in Fig20_3 (line 2)
Z = [X Y]*[2 1;1 3]*([X Y].') + [1 2]*[X Y].' + 3;

답변 (2개)

Walter Roberson
Walter Roberson 2020년 7월 29일

1 개 추천

This is a case where you need the * operator instead of the .* operator

댓글 수: 4

you will also need some reshape operations. I will post a bit later.
TRUNG HOANG
TRUNG HOANG 2020년 7월 29일
편집: TRUNG HOANG 2020년 7월 29일
I used both the * operator and the .* operator but it still showed errors. I think that the multiplication between matrix and vector is problem.
I think it might be easiest to expand the expression:
[X,Y] = meshgrid(-6:0.1:6);
Z = X + 2*Y + X .* (2*X + Y) + Y .* (X + 3*Y) + 3;
surf(X, Y, Z, 'edgecolor', 'none')
TRUNG HAONG comments:
Good.

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

카테고리

도움말 센터File Exchange에서 Line Plots에 대해 자세히 알아보기

질문:

2020년 7월 28일

댓글:

2020년 7월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by