Plotting 3 function using mesh command

조회 수: 11 (최근 30일)
qudsia Bashir
qudsia Bashir 2019년 10월 10일
편집: Alexandra McClernon Ownbey 2019년 10월 13일
I have to plot 3 functions in matlab using mesh command but donot know how to do it please anyone help me?
  댓글 수: 2
Rik
Rik 2019년 10월 10일
What is the full text of your homework assignment and what have you tried to find out so far?
qudsia Bashir
qudsia Bashir 2019년 10월 10일
i solved an equation using 3 different method and now i want to plot the results obtained from these three methods.the function is of form u(x,y)

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

답변 (1개)

Alexandra McClernon Ownbey
Alexandra McClernon Ownbey 2019년 10월 10일
The best way to plot using mesh is to create three 2-D matrices with the same sizes.
x = 0:.1:1;
y = 0:.5:10;
[xq,yq] = meshgrid(x,y);
z = (xq.^2-yq.^2);
figure()
mesh(x,y,z)
Although 'x' and 'y' are different sizes, meshgrid creates a 2-D grid for xq and yq with the m rows and n columns where m equals the length of y and n equals the length of x.
I find the easiest way to think of it is this way:
a 3-D plot needs values for each x, y, and z position. 'xq' is the x coordinates for each point. 'yq' is the y coordinates for each point, and 'z' is the z-coordinates for each respective point. So you create a 2-D grid and give each point some height 'z'.
You do not need to use meshgrid to create your initial 2D matrices, but I find it works well for most cases.
  댓글 수: 4
qudsia Bashir
qudsia Bashir 2019년 10월 12일
i am using the code given below but its giving error that dimmension must agree i have cross check the dimmensions are the same of both functions donot know y this is happening syms x t
for K=1:20
D(1,K)=0 ;
end
for K=1:19
for h=0:19
A(K+1,h+1)=(pi).^(K+2*h);
B(K+1,h+1)=sind(((K+2*h)*180)/2)
D(K+1,h+1)=A(K+1,h+1)*B(K+1,h+1)/(factorial(K)*factorial(h));
end
end
s=0;
for i=1:18
for j=1:18
x=0.2:0.2:0.8;
s=s+D(i,j).*x.^(i-1).*t.^(j-1);
end
end
t=0:0.1:0.5;
sia=subs(s,t);
sia1=eval(subs(s,t));
t=0:0.1:0.5;x=(0.2:0.2:0.8)';
exact1 = bsxfun(@times,sin(pi*x),exp(-(pi)^2*t));
B = reshape(exact1',[],1);
exact=B';
errordtm=abs(exact-sia1);
dtmmatrix = vec2mat(sia1,6);
mesh(x,t,exact1,'edgecolor', 'b');
hold on
mesh(x,t,dtmmatrix,'edgecolor', 'r');
legend({'Numerical','Exact'})
hold off
Alexandra McClernon Ownbey
Alexandra McClernon Ownbey 2019년 10월 13일
편집: Alexandra McClernon Ownbey 2019년 10월 13일
the length of your vector 'x' is 4, the length of your vector 't' is 6. just fix these dimensions to match. I suggest using linspace for t using the length of vector x.
I also would suggest initializing D using zeros.
D = zeros(20,1);

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

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by