The error is: Error using mesh (line 70) Z must be a matrix, not a scalar or vector.
Here is my code, and I do not know how to correct it so this error does not appear. I am trying to plot a mesh plot of the function I have denoted as g with the x and y intervals that are listed below.
%defining an x-interval
x = [0:0.2:2];
%defining an y-interval
y = [0:0.2:2];
%writing the equation
g = ((exp(1*-y)).*(sin(x)+cos(x)));
%attempting to solve the function
z= polyval(g, x, y)
%
%saving values for g
save('datafile1.mat', 'z')
%plotting the equation as a mesh
[i,j]= meshgrid(x,y);
mesh (i, j, z)
grid on;
hold on;
Can someone please help? Please and Thank you!

 채택된 답변

Star Strider
Star Strider 2017년 1월 16일

1 개 추천

Your polyval call is a bit mystifying. You already have your ‘g’ function defined, so just vectorise it an then plot it.
The Code —
%defining an x-interval
x = [0:0.2:2];
%defining an y-interval
y = [0:0.2:2];
%writing the equation
g = @(x,y) ((exp(-y*1)).*(sin(x)+cos(x)));
[i,j]= meshgrid(x,y);
z = g(i,j);
figure(1)
mesh(i, j, z)
grid on

댓글 수: 2

Priyanka Bose
Priyanka Bose 2018년 10월 2일
Thank you!
Star Strider
Star Strider 2018년 10월 2일
As always, my pleasure!

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

추가 답변 (0개)

카테고리

질문:

2017년 1월 16일

댓글:

2018년 10월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by