matlab练习之函数文件

Posted on 2020-03-11 01:24  薛向峰  阅读(399)  评论(0编辑  收藏  举报

function y=fun(x)
y=1./((x-2).^2+0.1)+1./((x-3).^4+0.01);
end
-----------------------------------------
fun(a)

ans =

    0.9716    0.0023
  100.9091    1.2340
----------------------------------------
函数句柄

ff=@(x)1./((x-2).^2+0.1)+1./((x-3).^4+0.01);
ff(a)

ans =

0.9716 0.0023
100.9091 1.2340

  注意[A,B]=meshgrid(a,b); 

x=-pi/2:0.001:pi/2;
y1=sqrt(cos(x));
a=-2:0.1:2;
b=-4:0.1:4;
[A,B]=meshgrid(a,b); 
y2=(A.^2)/4+(B.^2)/16;
subplot(2,2,2);
plot(x,y1);
subplot(2,2,3);
mesh(A,B,y2);

  

 

Copyright © 2024 薛向峰
Powered by .NET 8.0 on Kubernetes