繁体   English   中英

使用MatLab积分绘制2变量函数

[英]Plotting 2-variable Function with integration using MatLab

有没有人举过一个例子,说明如何在MatLab中(不使用MuPAD)在集成中绘制2变量函数?

这是我所拥有的:

clear all;

%define a, p and w

a=1;
p=1;
w=5;

%calculate xmin and xmax

xmin=a-p/2
xmax=a+p/2

%define the coordinates 


x=linspace(xmin,xmax);
y=linspace(0,1);

%define the coordinates along x-y plane

[x,y]=meshgrid(x,y);

%define and compute the given function along the x-y coordinates

z=w-(1/p)*int((x.-y)^2, x, xamin, xmax) ;

figure
surf(y,x,z)
title ('a=1 and p=1');
xlabel('w')
ylabel('t')
zlabel('x')
axis tight
shading interp
colorbar

显然,我的函数z出了点问题。 该功能是

z = w-(1 / p)* int(xt)^ 2dx,其中x从ap / 2到a + p / 2

非常感谢!

您的职能

z=w-(1/p)*int((x.-y)^2, x, xamin, xmax) ;

不依赖于x,因为

 >> syms x y xmin xmax
 >> func = int((x-y)^2,x,xmin,xmax)

 func =

 xmax*(y^2 + xmax*(xmax/3 - y)) - xmin*(y^2 + xmin*(xmin/3 - y))

因此不需要进行表面绘图,简单的绘图就足够了。 你可以这样做

z = xmax*(y.^2 + xmax*(xmax/3 - y)) - xmin*(y.^2 + xmin*(xmin/3 - y));
plot (y ,z);

在通过meshgrid将x和y转换为网格之前:

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM