jumpwolf 发表于 2006-4-5 19:18

[求助]曲线求交点?

怎么求两条时间序列曲线的交点???急啊

[ 本帖最后由 eight 于 2007-1-11 14:05 编辑 ]

happy 发表于 2006-4-6 09:50

转自《工程计算可视化与MATLAB实现》尚涛等编著 武汉大学出版社

两直线相交

function =pll(X1,Y1,X2,Y2)

% 直线相交求交点

A1=Y1(1)-Y1(2);
B1=X1(2)-X1(1);
C1=Y1(2)*X1(1)-Y1(1)*X1(2);
A2=Y2(1)-Y2(2);
B2=X2(2)-X2(1);
C2=Y2(2)*X2(1)-Y2(1)*X2(2);
D=det();
X=det([-C1 B1;-C2 B2])/D;
Y=det()/D;

调用格式:

x1=;y1=;x2=;y2=;
=pll(x1,y1,x2,y2);
plot(x1,y1,\'r\');
hold on
plot(x2,y2,\'b\');
plot(x,y,\'ko\');



直线与多条直线相交

xi=;yi=;
plot(xi,yi);hold on
x1=;y1=;line(x1,y1);
x=zeros(size(xi));
y=x;
for i=1:5-1
x2=xi();y2=yi();
=pll(x1,y1,x2,y2);
plot(x,y,\'ro\')
end



直线与曲线相交

x=-8:0.1:8;y=x;=meshgrid(x,y);
R=sqrt(X.^2+Y.^2)+eps;Z=sin(R)./R;
contour(Z,3);hold on
c=contour(Z,3);
x=;y=;
y=(y(2)-y(1))/(x(2)-x(1))*(x-x(1))+y(1);z=;
line(x,y,z);c=c\';
X=c(:,1);Y=c(:,2);
r0=abs(Y-(y(2)-y(1))/(x(2)-x(1))*(X-x(1))+y(1))<=.93;
zz=0;yy=r0.*Y;xx=r0.*X;
plot(xx(r0~=0),yy(r0~=0),\'r\')



曲线与曲线相交

x=0:pi/400:2*pi;
x=x\';
y1=sin(pi*x);y2=cos(pi*x);plot(x,y1,x,y2);hold on
r0=abs(y2-sin(pi*x))<=0.02;
yy=r0.*y1;xx=r0.*x;plot(xx(r0~=0),yy(r0~=0),\'r.\')



直线与曲面相交

x=-8:0.3:8;y=x;=meshgrid(x,y);
Z=X.^2+Y.^2;
mesh(X,Y,Z);hold on
x=[-10 10];y=[-10 3];z=;line(x,y,z);
r0=(abs(Y-y(1)-(y(2)-y(1))/(x(2)-x(1))*(X-x(1)))<=0.45)&...
(abs(Z-z(1)-(z(2)-z(1))/(x(2)-x(1))*(X-x(1)))<0.45)&...
(abs(Y-y(1)-(y(2)-y(1))/(z(2)-z(1))*(Z-z(1)))<=0.45);
zz=r0.*Z;yy=r0.*Y;xx=r0.*X;
plot3(xx(r0~=0),yy(r0~=0),zz(r0~=0),\'r*\');




平面与曲面相交

x=-8:0.1:8;
y=x;
=meshgrid(x,y);
Z1=2*ones(size(X));
Z2=X.^2-Y.^2;
mesh(X,Y,Z1);
hold on
mesh(X,Y,Z2);
r0=(abs(Z1-Z2)<=.65);
zz=r0.*Z1;yy=r0.*Y;xx=r0.*X;
plot3(xx(r0~=0),yy(r0~=0),zz(r0~=0),\'k*\')
clc
disp(\'观察曲面后,按任意键画交线\');
pause
clf
plot3(xx(r0~=0),yy(r0~=0),zz(r0~=0),\'k*\');

%曲面与多个截平面相交
y=-10:0.5:10;
z=y;
=meshgrid(z,y);
X=Z;
X1=0*ones(size(Z));
X2=3*ones(size(Z));
X3=-3*ones(size(Z));
Z4=(X.^2-Y.^2)/10;
mesh(X1,Y,Z);hold on
mesh(X2,Y,Z)
mesh(X3,Y,Z);
mesh(X,Y,Z4);
r1=(abs(X1-X)<0.05);
r2=(abs(X2-X)<0.05);
r3=(abs(X3-X)<0.05);
zz1=r1.*Z4;yy1=r1.*Y;xx1=r1.*X;
zz2=r2.*Z4;yy2=r1.*Y;xx2=r1.*X;
zz3=r3.*Z4;yy3=r1.*Y;xx3=r1.*X;
plot3(xx1(r1~=0),yy1(r1~=0),zz1(r1~=0),\'k*\');
plot3(xx2(r2~=0),yy2(r2~=0),zz2(r2~=0),\'k*\');
plot3(xx3(r3~=0),yy3(r3~=0),zz3(r3~=0),\'k*\');
colormap(hsv)
clc;
disp(\'观察曲面后,按任意键画交线\');
hold off



平面与曲面相交

y=-8:0.4:8;
z=y;
=meshgrid(z,y);
X=Z;
X1=zeros(size(Z));
Z2=zeros(size(Z));
Z3=(X.^2-Y.^2)/10;
mesh(X1,Y,Z);
hold on
mesh(X,Y,Z2);
mesh(X,Y,Z3);
r1=(abs(X1-X)<0.05);
r2=(abs(Z3-Z2)<0.05);
r3=(abs(X1-X)<0.05)&(abs(Z-Z2)<=0.05);
zz1=r1.*Z3;yy1=r1.*Y;xx1=r1.*X;
zz2=r2.*Z3;yy2=r2.*Y;xx2=r2.*X;
zz3=r3.*Z;yy1=r3.*Y;xx1=r3.*X1;

plot3(xx1(r1~=0),yy1(r1~=0),zz1(r1~=0),\'k*\');
plot3(xx2(r2~=0),yy2(r2~=0),zz2(r2~=0),\'k*\');
plot3(xx3(r3~=0),yy3(r3~=0),zz3(r3~=0),\'k*\');

colormap(hsv);



曲面与曲面求交

=meshgrid(-2:.1:2);
z1=x.^2-2*y.^2;
z2=x.^2+y.^2-5;
mesh(x,y,z1);
hold on
mesh(x,y,z2);
r0=(abs(z1-z2)<=.1);
zz=r0.*z1;yy=r0.*y;xx=r0.*x;
plot3(xx(r0~=0),yy(r0~=0),zz(r0~=0),\'k*\')
colormap(cool)
hold off

[ 本帖最后由 happy 于 2006-10-24 20:00 编辑 ]

jumpwolf 发表于 2006-4-6 12:42

非常感谢!仔细研究一下

nianhua77 发表于 2006-7-26 10:40

fzero
fsolve

cozy 发表于 2006-9-14 17:22

这是怎么回事啊~~
X1=;Y1=;
>> plot(X1,Y1,\'r\');
??? plot(X1,Y1,\'r\');
               |
Error: Missing variable or function

happy 发表于 2006-9-14 17:24

plot(X1,Y1,\'r\');改成plot(X1,Y1,'r');

xyzhou1234 发表于 2007-9-13 21:00

回复 #2 happy 的帖子

直线与多条直线相交

xi=;yi=;
plot(xi,yi);hold on
x1=;y1=;line(x1,y1);
x=zeros(size(xi));
y=x;
for i=1:5-1
x2=xi();y2=yi();
=pll(x1,y1,x2,y2);
plot(x,y,\'ro\')
end

请问Pll是什么,MATLAB 无法识别?

eight 发表于 2007-9-13 21:28

本帖最后由 ChaChing 于 2010-8-25 01:02 编辑

请认真看看二楼的程序

xyzhou1234 发表于 2007-9-14 12:30

回复 #13 eight 的帖子

谢谢!我太大意了,竟然没有看到pll是一个自编的函数:@L

gerry 发表于 2007-11-11 14:45

contour可以返回数据点,已知函数也可以solve
如果是 plot 得到的不规则曲线又该怎么做呢?

zhouyang664 发表于 2010-8-24 22:10

真是好东西,辛苦楼主了!

xiaoxiaobeifeng 发表于 2010-9-6 11:26

本帖最后由 xiaoxiaobeifeng 于 2010-9-6 11:29 编辑

两条曲线求交点吧 我觉得可以根据定义来嘛
abs(x(i)-y(i))<=abs(x(i-1)-y(i-1)) $$ abs(x(i)-y(i))<=abs(x(i+1)-y(i+1)) 应该可以吧

土木年华 发表于 2010-9-7 11:24

回复 happy 的帖子
不错,谢谢


   

546267667 发表于 2010-10-17 21:33

{:{02}:}找到答案了!

happy 发表于 2010-10-18 05:37

gerry 发表于 2007-11-11 14:45 static/image/common/back.gif
contour可以返回数据点,已知函数也可以solve
如果是 plot 得到的不规则曲线又该怎么做呢?

没太懂你这个问题的意思?
页: [1] 2
查看完整版本: [求助]曲线求交点?