小木虫 --- 700万学术达人喜爱的学术科研平台

首页 >> 程序语言 >>怎么画三维图呢,求助,万分感谢

怎么画三维图呢,求助,万分感谢

如何用matlab画分段的三维图呢?可以帮我看一下下面这个例子,十分感谢!!!
例子:0<=x<=6;
      0<=y<=4;
当0<=y<=1时,z=x-y;
当1<y<=3时,z=x+2y;
当3<y<=4时,z=x+y;
如何用matlab做出这种分段的三维图呢?  返回小木虫查看更多

今日热帖

用户评论

8楼: Originally posted by chengsi9406 at 2017-12-20 09:23:57
clear;
= meshgrid(linspace(0,6,100),linspace(0,4,100));
z = (x-y).*(y&gt;=0 &amp; y&lt;=1) + (x+2*y).*(y&gt;1 &amp; y&lt;=3) + (x+y).*(y&gt;3 &amp; y&lt;=4);
...
谢谢!

8楼: Originally posted by chengsi9406 at 2017-12-20 09:23:57
clear;
= meshgrid(linspace(0,6,100),linspace(0,4,100));
z = (x-y).*(y&gt;=0 &amp; y&lt;=1) + (x+2*y).*(y&gt;1 &amp; y&lt;=3) + (x+y).*(y&gt;3 &amp; y&lt;=4);
...
你能帮我看看这个问题出在哪了吗,这5段分开画是没问题的,但是按你这种方法合在一起画出来好像有点出入,希望你抽时间帮我看看,谢谢!
0<=x<=6;   0<=t<=0.4;
当0<=t<=0.07;
Fxt='(6.*(-38.59-33.33).*(- 360000./(29.*(29.*x - 210)) - 12000./203)-(6.*(-38.55-33.33).* 285.7143).*(108000000./(29.*(29.*x - 210).^2) - 120000./1421)./2789.1).*0.3-(2.5.*9.81.*6+245).*(108000000./(29.*(29.*x - 210).^2) - 120000./1421)./2789.1+245+2.5.*9.81.*x';
clf
ezsurf(Fxt,)
view()
当0.07<t<=0.12;
Fxt='(6.*(-(-4*pi^2*0.004*2.5.^2*10*(t-0.07).^2./(0.8^2)+pi.^2*0.004*2.5.^2./(10*0.8.^2))*1000-33.33).*(- 360000./(29.*(29.*x - 210)) - 12000./203)-(6.*(-(-4*pi^2*0.004*2.5.^2*10*(t-0.07).^2./(0.8^2)+pi.^2*0.004*2.5.^2./(10*0.8.^2))*1000-33.33).* 285.7143).*(108000000./(29.*(29.*x - 210).^2) - 120000./1421)./2789.1).*0.3-(2.5.*9.81.*6+245).*(108000000./(29.*(29.*x - 210).^2) - 120000./1421)./2789.1+245+2.5.*9.81.*x';
clf
ezsurf(Fxt,)
view()
当0.12<t<=0.28;
Fxt='(6.*((2*pi*0.004*2.5*cos(2*pi*2.5*(0.2-t)./0.8)./0.8)*1000-33.33).*(- 360000./(29.*(29.*x - 210)) - 12000./203)-(6.*((2*pi*0.004*2.5*cos(2*pi*2.5*(0.2-t)./0.8)./0.8)*1000-33.33).* 285.7143).*(108000000./(29.*(29.*x - 210).^2) - 120000./1421)./2789.1).*0.3-(2.5.*9.81.*6+245).*(108000000./(29.*(29.*x - 210).^2) - 120000./1421)./2789.1+245+2.5.*9.81.*x';
clf
ezsurf(Fxt,)
view()

当0.28<t<=0.33;
Fxt='(6.*(-(-4*pi^2*0.004*2.5.^2*10*(t-0.33).^2./(0.8^2)+pi.^2*0.004*2.5.^2./(10*0.8.^2))*1000 -33.33).*(- 360000./(29.*(29.*x - 210)) - 12000./203)-(6.*(-(-4*pi^2*0.004*2.5.^2*10*(t-0.33).^2./(0.8^2)+pi.^2*0.004*2.5.^2./(10*0.8.^2))*1000 -33.33).* 285.7143).*(108000000./(29.*(29.*x - 210).^2) - 120000./1421)./2789.1).*0.3-(2.5.*9.81.*6+245).*(108000000./(29.*(29.*x - 210).^2) - 120000./1421)./2789.1+245+2.5.*9.81.*x';
clf
ezsurf(Fxt,)
view()

当0.33<t<=0.4;
Fxt='(6.*(-38.59-33.33).*(- 360000./(29.*(29.*x - 210)) - 12000./203)-(6.*(-38.55-33.33).* 285.7143).*(108000000./(29.*(29.*x - 210).^2) - 120000./1421)./2789.1).*0.3-(2.5.*9.81.*6+245).*(108000000./(29.*(29.*x - 210).^2) - 120000./1421)./2789.1+245+2.5.*9.81.*x';
clf
ezsurf(Fxt,)
view()
下面是合在一起的程序
clear;
=meshgrid(linspace(0,6,100),linspace(0,0.4,100));
f=(6.*(-38.59-33.33).*(- 360000./(29.*(29.*x - 210)) - 12000./203)-(6.*(-38.55-33.33).* 285.7143).*(108000000./...
    (29.*(29.*x - 210).^2) - 120000./1421)./2789.1).*0.3-(2.5.*9.81.*6+245).*(108000000./(29.*(29.*x - 210).^2) - ...
    120000./1421)./2789.1+245+2.5.*9.81.*x.*(t>=0&t<=0.07)+(6.*(-(-4*pi^2*0.004*2.5.^2*10*(t-0.07).^2./(0.8^2)+pi.^2*0.004*2.5.^2./(10*0.8.^2))...
    *1000-33.33).*(- 360000./(29.*(29.*x - 210)) - 12000./203)-(6.*(-(-4*pi^2*0.004*2.5.^2*10*(t-0.07).^2./(0.8^2)+pi.^2*0.004*2.5.^2./...
    (10*0.8.^2))*1000-33.33).* 285.7143).*(108000000./(29.*(29.*x - 210).^2) - 120000./1421)./2789.1).*...
    0.3-(2.5.*9.81.*6+245).*(108000000./(29.*(29.*x - 210).^2) - 120000./1421)./2789.1+245+2.5.*9.81.*x.*(t>0.07&t<=0.12)+...
    (6.*((2*pi*0.004*2.5*cos(2*pi*2.5*(0.2-t)./0.8)./0.8)*1000-33.33).*(- 360000./(29.*(29.*x - 210)) - 12000./203)-...
    (6.*((2*pi*0.004*2.5*cos(2*pi*2.5*(0.2-t)./0.8)./0.8)*1000-33.33).* 285.7143).*(108000000./(29.*(29.*x - 210).^2) - 120000./1421)./2789.1).*...
    0.3-(2.5.*9.81.*6+245).*(108000000./(29.*(29.*x - 210).^2) - 120000./1421)./2789.1+245+2.5.*9.81.*x.*(t>0.12&t<=0.28)+...
    (6.*(-(-4*pi^2*0.004*2.5.^2*10*(t-0.33).^2./(0.8^2)+pi.^2*0.004*2.5.^2./(10*0.8.^2))*1000 -33.33).*(- 360000./(29.*(29.*x - 210))...
    - 12000./203)-(6.*(-(-4*pi^2*0.004*2.5.^2*10*(t-0.33).^2./(0.8^2)+pi.^2*0.004*2.5.^2./(10*0.8.^2))*1000 -33.33).* 285.7143).*...
    (108000000./(29.*(29.*x - 210).^2) - 120000./1421)./2789.1).*0.3-(2.5.*9.81.*6+245).*(108000000./(29.*(29.*x - 210).^2)...
    - 120000./1421)./2789.1+245+2.5.*9.81.*x.*(t>0.28&t<=0.33)+(6.*(-38.59-33.33).*(- 360000./(29.*(29.*x - 210)) - 12000./203)-...
    (6.*(-38.55-33.33).* 285.7143).*(108000000./(29.*(29.*x - 210).^2) - 120000./1421)./2789.1).*0.3-(2.5.*9.81.*6+245).*...
    (108000000./(29.*(29.*x - 210).^2) - 120000./1421)./2789.1+245+2.5.*9.81.*x.*(t>0.33&t<=0.4);
clf
mesh(x,t,f)
可能有点乱!!麻烦了,

10楼: Originally posted by UZippo at 2017-12-20 21:13:47
你能帮我看看这个问题出在哪了吗,这5段分开画是没问题的,但是按你这种方法合在一起画出来好像有点出入,希望你抽时间帮我看看,谢谢!
0&lt;=x&lt;=6;   0&lt;=t&lt;=0.4;
当0&lt;=t&lt ...
你要把表达式用括号括起来,然后再点乘取值范围。就好像 z = (x-y).*(y>=0 & y<=1) + (x+2*y).*(y>1 & y<=3) + (x+y).*(y>3 & y<=4); 里面 x-y是表达式 后面点乘的是范围,后面同理。
我把你的程序稍微改了改,写在下面,附上图。顺便说一句点乘这种运算如果是数字就不需要用。
clear;
x = linspace(0,6,100);
t = linspace(0,0.4,100);
= meshgrid(x,t);
F1=(6.*(-38.59-33.33).*(- 360000./(29.*(29.*x - 210)) - 12000./203)-(6.*(-38.55-33.33).* 285.7143).*(108000000./(29.*(29.*x - 210).^2) ...
    - 120000./1421)./2789.1).*0.3-(2.5.*9.81.*6+245).*(108000000./(29.*(29.*x - 210).^2) - 120000./1421)./2789.1+245+2.5.*9.81.*x;
F2=(6.*(-(-4*pi^2*0.004*2.5.^2*10*(t-0.07).^2./(0.8^2)+pi.^2*0.004*2.5.^2./(10*0.8.^2))*1000-33.33).*(- 360000./(29.*(29.*x - 210)) ...
    - 12000./203)-(6.*(-(-4*pi^2*0.004*2.5.^2*10*(t-0.07).^2./(0.8^2)+pi.^2*0.004*2.5.^2./(10*0.8.^2))*1000-33.33).* 285.7143)...
    .*(108000000./(29.*(29.*x - 210).^2) - 120000./1421)./2789.1).*0.3-(2.5.*9.81.*6+245).*(108000000./(29.*(29.*x - 210).^2) - 120000./1421)./2789.1+245+2.5.*9.81.*x;
F3=(6.*((2*pi*0.004*2.5*cos(2*pi*2.5*(0.2-t)./0.8)./0.8)*1000-33.33).*(- 360000./(29.*(29.*x - 210)) - 12000./203)...
    -(6.*((2*pi*0.004*2.5*cos(2*pi*2.5*(0.2-t)./0.8)./0.8)*1000-33.33).* 285.7143).*(108000000./(29.*(29.*x - 210).^2) - 120000./1421)./2789.1)...
    .*0.3-(2.5.*9.81.*6+245).*(108000000./(29.*(29.*x - 210).^2) - 120000./1421)./2789.1+245+2.5.*9.81.*x;
F4=(6.*(-(-4*pi^2*0.004*2.5.^2*10*(t-0.33).^2./(0.8^2)+pi.^2*0.004*2.5.^2./(10*0.8.^2))*1000 -33.33).*(- 360000./(29.*(29.*x - 210)) ...
    - 12000./203)-(6.*(-(-4*pi^2*0.004*2.5.^2*10*(t-0.33).^2./(0.8^2)+pi.^2*0.004*2.5.^2./(10*0.8.^2))*1000 -33.33).* 285.7143)...
    .*(108000000./(29.*(29.*x - 210).^2) - 120000./1421)./2789.1).*0.3-(2.5.*9.81.*6+245).*(108000000./(29.*(29.*x - 210).^2) - 120000./1421)./2789.1+245+2.5.*9.81.*x;
F5=(6.*(-38.59-33.33).*(- 360000./(29.*(29.*x - 210)) - 12000./203)-(6.*(-38.55-33.33).* 285.7143).*(108000000./(29.*(29.*x - 210).^2) ...
    - 120000./1421)./2789.1).*0.3-(2.5.*9.81.*6+245).*(108000000./(29.*(29.*x - 210).^2) - 120000./1421)./2789.1+245+2.5.*9.81.*x;
f=F1.*(t<=0.07)+F2.*(0.07<t & t<=0.12)+F3.*(0.12<t & t<=0.28)+F4.*(0.28<t & t<=0.33)+F5.*(0.33<t & t<=0.4);
mesh(x,t,f)

untitled.jpg

11楼: Originally posted by chengsi9406 at 2017-12-20 21:34:33
你要把表达式用括号括起来,然后再点乘取值范围。就好像 z = (x-y).*(y&gt;=0 &amp; y&lt;=1) + (x+2*y).*(y&gt;1 &amp; y&lt;=3) + (x+y).*(y&gt;3 &amp; y&lt;=4); 里面 x- ...
嗯嗯,这个图对着呢,十分感谢!!!

猜你喜欢

学术必备
与600万学术达人在线互动!


扫描下载送金币