matlab如何改错,[问题] 程序改错

icon1.gif 程序改错

在MATLAB中输入niehe(1,31,91)然后回车就可以看到效果了。四个文件必须在同一文件夹。

niehe.mfunction [ output_args ] =niehe( m,z1,z2 )

%UNTITLED1 Summary of this function goes here

% Detailed explanation goes here

hold on

axis equal

grid on

[x1 y1]=chilunlunkuo2(m,z1);

[x2 y2]=chilunlunkuo2(m,z2);

d=m*(z1+z2)/2;

r1=m*z1/2;

r2=m*z2/2;

rb1=r1*cos(pi/9);

rb2=r2*cos(pi/9);

xq1=-rb1*sin(pi/9);

yq1=rb1*cos(pi/9);

xq2=rb2*sin(pi/9);

yq2=d-rb2*cos(pi/9);

xq=[xq1 xq2];

yq=[yq1 yq2];

xxq=[-xq1 -xq2];

yyq=[yq1 yq2];

axis([-4*m 4*m r1-4*m r1+4*m]);

first =0;

last = 2*pi;

n=100;

distant=(last-first)/n;

sita=first:distant:last;

rb1x=r1.*cos(sita);

rb1y=r1.*sin(sita);

rb2x=r2.*cos(sita);

rb2y=r2.*sin(sita)+d;

% plot(rb1x,rb1y,'k-');

% plot(rb2x,rb2y,'k-');

ds1=pi/2/z1;

%ds1=0;

xx1=x1*cos(ds1)-y1*sin(ds1);

yy1=x1*sin(ds1)+y1*cos(ds1);

ds2=pi-3*pi/2/z2;

xx2=x2*cos(ds2)-y2*sin(ds2);

yy2=x2*sin(ds2)+y2*cos(ds2)+d;

plot(xx1,yy1,'k');

plot(xx2,yy2,'r');

plot(xxq,yyq,'b-');

pause(5);

n=0;

while n<2000

hold off;

si1=ds1+0.001*n;

xx1=x1*cos(si1)-y1*sin(si1);

yy1=x1*sin(si1)+y1*cos(si1);

si2=ds2-0.001*n*(z1/z2);

xx2=x2*cos(si2)-y2*sin(si2);

yy2=x2*sin(si2)+y2*cos(si2)+d;

plot(xq,yq,'b-');

hold on;

plot(xxq,yyq,'b-');

plot(xx1,yy1,'k');

plot(xx2,yy2,'r');

axis([-4*m 4*m r1-4*m r1+4*m]);

grid on

pause(0.01);

n=n+1;

end

chikuoqizhi.mfunction [ jfirstsita jlastsita gfirstsita glastsita] = chikuoqizhi( m,z )

%UNTITLED1 Summary of this function goes here

% Detailed explanation goes here [ jfirstsita jlastsita gfirstsita

% glastsita] = chikuoqizhi( m,z ),该函数返回齿轮轮廓渐开线段和过渡线段参数方程中参数的起止值

r = m*z/2;

ra = r + m;

rf = r - 1.25*m;

rb = r * cos(pi/9);

precise = 1e-7;

%%%%%%%%%%渐开线最上面的点

start = -1.5*pi/z;

last = 3*pi/z;

theone = start;

[x,y] = jiankaixian2(m,z,theone,0);

t = (x^2+y^2)^0.5 -ra;

count = 0;

count1 = 0;

count2 = 0;

while abs(t) > precise && count < 100000

if t > 0

start = theone;

theone = (theone + last)/2;

count1 = count1+1;

end

if t < 0

last = theone;

theone = (theone + start)/2;

count2 = count2+1;

end

count = count +1;

[x,y] = jiankaixian2(m,z,theone,0);

t = (x^2+y^2)^0.5 -ra;

end

jfirstsita = theone;

%%%%%%%%过渡线最下面的点

start = -1.5*pi/z;

last = 3*pi/z;

dd = 10;

ddo =0;

count = 0;

while dd > precise && count < 10000

count = count+1;

s1 =start*2/3+last/3;

s2 =start/3+last*2/3;

[x1 y1]=guoduquxian2(m,z,s1);

[x2 y2]=guoduquxian2(m,z,s2);

d1 = (x1^2+y1^2)^0.5;

d2 = (x2^2+y2^2)^0.5;

if d1>d2

start = s1;

dd = (d2-rf);

end

if d1<=d2

last = s2;

dd = (d1-rf);

end

dd =abs(dd);

if abs(ddo-dd)<1e-8

break;

end

ddo = dd;

end

gfirstsita = (s1+s2)/2;

% theone = start;

% ydao = gydao(m,z,theone);

%

% while abs(ydao) > precise && count < 10000

% if ydao < 0

% start = theone;

% theone = (theone + last)/2;

% count1 = count1+1;

% end

% if ydao > 0

% last = theone;

% theone = (theone + start)/2;

% count2 = count2+1;

% end

% count = count +1;

% ydao = gydao(m,z,theone);

% end

%gfirstsita = theone

%%%%%%%渐开线与过渡线的交点

start = -1.5*pi/z;

last = 3*pi/z;

theone = start;

[gx,gy] = guoduquxian2(m,z,theone);

[jx,jy] = jiankaixian2(m,z,theone,0);

t = gy-jy;

while abs(t) > precise && count < 10000

if t < 0

start = theone;

theone = (theone + last)/2;

count1 = count1+1;

end

if t > 0

last = theone;

theone = (theone + start)/2;

count2 = count2+1;

end

count = count +1;

[gx,gy] = guoduquxian2(m,z,theone);

[jx,jy] = jiankaixian2(m,z,theone,0);

t = gy-jy;

end

jlastsita = theone;

glastsita = theone;

chilunlunkuo2.m

function [ x2 y2] = chilunlunkuo2( m,z )

[ jfirstsita jlastsita gfirstsita glastsita] = chikuoqizhi( m,z );

first =jfirstsita;

last = jlastsita;

n = 100;

distant = (last - first)/n;

sita = first:distant:last;

r = m*z/2;

ra = r + m;

rf = r-1.25*m;

% grid on

% axis equal

% hold on

%渐开线段点坐标值%%%%%%%%%%%%%%%%%

xm = pi*m/4;

ym = r;

x = ((cos(sita)+tan(pi/9).*sin(sita)).*(xm-r.*sita+ym*tan(pi/9))+(sin(sita)-tan(pi/9).*cos(sita)).*r)/((tan(pi/9))^2+1);

y = ((cos(sita)+tan(pi/9).*sin(sita)).*r-(sin(sita)-tan(pi/9).*cos(sita)).*(xm-r.*sita+ym*tan(pi/9)))/((tan(pi/9))^2+1);

% plot(x,y,'m');

% plot(-x,y,'m');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%过渡线段点坐标值%%%%%%%%%%%%%%%%%%%%%%%%%

first =gfirstsita;

last = glastsita;

distant = (last - first)/n;

sita = first:distant:last;

R = 0.38*m;

a = pi*m/4+m*tan(pi/9)+0.38*m*cos(pi/9);

b = R*sin(pi/9)+r-m;

l1 = b.*sin(sita)+(a-r.*sita).*cos(sita);

l2 = (r-b).*cos(sita)+(a-r.*sita).*sin(sita);

l3 = b.*cos(sita)-(a-r.*sita).*sin(sita);

l4 = (r-b).*sin(sita)-(a-r.*sita).*cos(sita);

%yg = l3 - R.*((l2.*l2).^0.5)./((l2.^2+l4.^2).^0.5);

%xg = l1 - R.*((l4.*l4).^0.5)./((l2.^2+l4.^2).^0.5);

xg = l1 - R.*(l4)./((l2.^2+l4.^2).^0.5);

yg = l3 - R.*(l2)./((l2.^2+l4.^2).^0.5);

%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%渐开线与过渡线的准确点%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%绘过渡线与渐开线

% plot(xg,yg,'k');

% plot(-xg,yg,'k');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%齿顶圆与基圆%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

n2=20;

ra = r + m;

first = atan(y(1)/x(1));

last = pi-atan(y(1)/x(1));

distant = (last - first)/n2;

t = first:distant:last;

raxx = ra.*cos(pi-t);

rayy = ra.*sin(t);

last = pi-atan(yg(1)/xg(1))-2*pi/z;

first= atan(yg(1)/xg(1));

distant = (last - first)/n2;

t = first:distant:last;

rfxx = rf.*cos(t);

rfyy = rf.*sin(t);

% plot(raxx,rayy,'g');

% plot(rfxx,rfyy,'g-');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

i=1;

xgg=xg;

ygg=yg;

xx=x;

yy=y;

while i

xgg(n+2-i)=xg(i);

ygg(n+2-i)=yg(i);

xx(n+2-i) =-x(i);

yy(n+2-i) = y(i);

i = i+1;

end

x1 = [-xg xx raxx x xgg rfxx];

y1 = [yg yy rayy y ygg rfyy];

%plot(x1,y1,'k');

%%%%

x1(n*4+4+n2*2+2)=x1(n*4+4+n2*2+1);

y1(n*4+4+n2*2+2)=y1(n*4+4+n2*2+1);

xt=x1;

yt=y1;

i= 1;

xi = -2*pi/z;

while(i

xix = xi*i;

i = i+1;

x2=x1*cos(xix)-y1*sin(xix);

y2=x1*sin(xix)+y1*cos(xix);

xt=[xt x2];

yt=[yt y2];

end

%%%%

x2=xt;

y2=yt;

%%%%%%%%文件输出%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%k = indexge - indexgs;

%fid = fopen('test.txt','wt');

%for i = 1:j

% chikuox(i) = xx(i);

% chikuoy(i) = yy(i);

% fprintf(fid,'%f %f\n',xx(i),yy(i));

%end

%for i = 0:k-1

% chikuox(i+j+1) = xxg(k-i);

% chikuoy(i+j+1) = yyg(k-i);

% fprintf(fid,'%f %f\n',xxg(k-i),yyg(k-i));

%end

%fclose(fid);

guoduquxian2.m

function [x,y] = guoduquxian2(m,z,sita)

r = m*z/2;

ra = r + m;

rf = r-1.25*m;

%过度线段点坐标值%%%%%%%%%%%%%%%%%

R = 0.38*m;

a = pi*m/4+m*tan(pi/9)+0.38*m*cos(pi/9);

b = R*sin(pi/9)+r-m;

jiankaixian2.m

function [x,y] = jiankaixian2(m,z,sita,n);

r = m*z/2;

ra = r + m;

rf = r-1.25*m;

%grid on

%axis equal

%hold on

%渐开线段点坐标值%%%%%%%%%%%%%%%%%

xm = pi*m/4;

ym = r;

x1 = ((cos(sita)+tan(pi/9)*sin(sita))*(xm-r*sita+ym*tan(pi/9))+(sin(sita)-tan(pi/9)*cos(sita))*r)/((tan(pi/9))^2+1);

y1 = ((cos(sita)+tan(pi/9)*sin(sita))*r-(sin(sita)-tan(pi/9)*cos(sita))*(xm-r*sita+ym*tan(pi/9)))/((tan(pi/9))^2+1);

result = R(2*n*pi/z)*[x1;y1;1];

x = result(1,1);

y = result(2,1);

l1 = b*sin(sita)+(a-r*sita)*cos(sita);

l2 = (r-b)*cos(sita)+(a-r*sita)*sin(sita);

l3 = b*cos(sita)-(a-r*sita)*sin(sita);

l4 = (r-b)*sin(sita)-(a-r*sita)*cos(sita);

y = l3 - R*((l2))/((l2^2+l4^2)^0.5);

x = l1 - R*((l4))/((l2^2+l4^2)^0.5);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值