# Plotting 3 function using mesh command

2 ビュー (過去 30 日間)
qudsia Bashir 2019 年 10 月 10 日

I have to plot 3 functions in matlab using mesh command but donot know how to do it please anyone help me?
##### 2 件のコメント1 件の古いコメントを表示1 件の古いコメントを非表示
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 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 件のコメント3 件の古いコメントを表示3 件の古いコメントを非表示
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 Center および File ExchangeSurface and Mesh Plots についてさらに検索

### Community Treasure Hunt

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

Start Hunting!