声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 18794|回复: 18

[绘图技巧] 隐函数如何用Matlab来画出曲线?

[复制链接]
发表于 2005-10-9 14:42 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
怎么画?别说只能先求解阿

[ 本帖最后由 lxq 于 2007-5-2 23:55 编辑 ]
回复
分享到:

使用道具 举报

发表于 2005-10-9 15:37 | 显示全部楼层
这个在matlab的书籍里面倒是没确切地看到,
mathmatica里面倒是有。:)
发表于 2005-10-9 22:01 | 显示全部楼层
Mathematica中绘制隐函数的命令是ImplicitPlot
Matlab我曾经见人写过一个绘制隐函数的代码,一时找不到了,我在找找看

  1. function implot(fun,rangexy,ngrid)
  2. % Implicit plot function
  3. % function implot(fun,rangexy,ngrid)
  4. % fun is 'inline' function f(x,y)=0 (Note function written as equal to zero)
  5. % rangexy =[xmin,xmax,ymin,ymax] range over which x and y is ploted default(-2*pi,2*pi)
  6. % ngrid is the number of grid points used to calculate the plot,
  7. % Start with course grid (ngrid =20) and then use finer grid if necessary
  8. % default ngrid=50
  9. %
  10. % Example
  11. % Plot y^3+exp(y)-tanh(x)=0
  12. %
  13. % write function f as an 'inline' function of x and y-- right hand side
  14. % equal to zero
  15. %
  16. % f=inline('y^3+exp(y)-tanh(x)','x','y')
  17. % implot(f,[-3 3 -2 1])

  18. %       A.Jutan UWO 2-2-98  <a href="mailto:ajutan@julian.uwo.ca" target="_blank">ajutan@julian.uwo.ca</a>

  19. if nargin == 1  ;% grid value and ranges not specified calculate default
  20.         rangexy=[-2*pi,2*pi,-2*pi,2*pi];
  21.    ngrid=50;
  22. end

  23. if nargin == 2;  % grid value not specified
  24.    ngrid=50;
  25. end

  26. % get 2-D grid for x and y

  27. xm=linspace(rangexy(1),rangexy(2),ngrid);
  28. ym=linspace(rangexy(3),rangexy(4),ngrid);
  29. [x,y]=meshgrid(xm,ym);
  30. fvector=vectorize(fun);% vectorize the inline function to handle vectors of x y
  31. fvalues=feval(fvector,x,y); %calculate with feval-this works if fvector is an m file too
  32. %fvalues=fvector(x,y); % can also calculate directly from the vectorized inline function
  33. contour(x,y,fvalues,[0,0],'b-');% plot single contour at f(x,y)=0, blue lines
  34. xlabel('x');ylabel('y'); grid
复制代码


[ 本帖最后由 ChaChing 于 2010-7-2 14:53 编辑 ]

评分

1

查看全部评分

发表于 2005-10-10 16:13 | 显示全部楼层
谢谢分享,收下,^_^
发表于 2005-10-10 23:44 | 显示全部楼层
matlab7中有直接绘制隐函数曲线的命令
其调用格式:ezplot(隐函数表达式)
如要绘制f(x,y)=y^3+exp(y)-tanh(x)的曲线,命令为:
  1. ezplot('y^3+exp(y)-tanh(x)')
复制代码

上面的语句将自动选择x轴的范围[-6,6],要自己定义绘制区间,如在[-10,10]绘制.可用下面语句:
  1. ezplot('y^3+exp(y)-tanh(x)',[-10,10])
复制代码

评分

1

查看全部评分

发表于 2005-10-16 12:57 | 显示全部楼层
如果是f(x,y,z)=0
能用ezplot畫嗎?
发表于 2005-10-16 15:54 | 显示全部楼层
  1. 如果是f(x,y,z)=0
  2. 能用ezplot畫嗎?
复制代码

用ezplot3
发表于 2005-10-18 17:36 | 显示全部楼层
在matlab6.5中能用ezplot3直接画隐函数曲线吗?
发表于 2005-10-18 18:02 | 显示全部楼层
在matlab6.5中能用ezplot3直接画隐函数曲线吗?

6.5不行,7.0我没试过,不过如果ezplot可以画二维隐函数曲线,那ezplot3应该也行
发表于 2005-10-18 18:27 | 显示全部楼层
三维画圆问题
是可以用ezplot3,问题是y和z都已经表示成了x的函数!
如果是隐函数怎么办呢?
上面的那个程序只能画二维的!
发表于 2005-10-19 09:28 | 显示全部楼层
是可以用ezplot3,问题是y和z都已经表示成了x的函数!
如果是隐函数怎么办呢?
上面的那个程序只能画二维的!

一个三维隐函数绘图的例子

  1. % draw3varf.m
  2. % surface of constant value plot.
  3. % draw3varf(X,Y,Z,CONST) draws a surface of constant value
  4. % for a function of three variables: F(X,Y,Z) = CONST .
  5. % The color of each patch is determined by its
  6. % orientation with respect to a specified direction.
  7. % F must be an M-by-N-by-P volume array.
  8. % x=1:0.1:10;y=1:0.1:10;z=0:0.1:10;
  9. % [x,y,z]=meshgrid(x,y,z);
  10. % f=(x+y+z).*(x.*y+x.*z+y.*z)-10*x.*y.*z-a;
  11. % Li wenyong 2004.2.25 copyright
  12. const=0;
  13. x=1:0.1:10;y=1:0.1:10;z=0:0.1:10;
  14. [x,y,z]=meshgrid(x,y,z);
  15. f=(x+y+z).*(x.*y+x.*z+y.*z)-10*x.*y.*z-const;
  16. p=patch(isosurface(x,y,z,f,0));
  17. set(p, 'FaceColor', 'red', 'EdgeColor', 'none');
  18. daspect([1 1 1])
  19. view(3)
  20. camlight; lighting phong
复制代码

评分

1

查看全部评分

发表于 2006-3-25 12:39 | 显示全部楼层
我是6.5
输入ezplot3
提示错误怎么办?
发表于 2006-3-25 17:15 | 显示全部楼层
用3楼的那个函数来画

[ 本帖最后由 happy 于 2007-4-14 19:56 编辑 ]
发表于 2006-8-11 14:34 | 显示全部楼层
我有个问题:
遗传算法中假设产生出种群为某个隐函数的系数。是可以画出图形。
但关键是怎样能够求出解来啊?
如果你自己一个个代进去可以,但这不但速度慢麻烦而且好象失去了遗传算法的某些本质!
我的问题是怎样才能求种群产生后隐函数一系列的解!
期待能够解决!!???
发表于 2006-12-7 20:29 | 显示全部楼层
复数呢?比如z^10-1=0可以吗?她提示我??? Undefined function or variable 'z'.
那要怎莫设呢?
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-5-3 06:26 , Processed in 0.218404 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表