正在加载图片...
bx--x-position of point b by--y-position of point b result--Distance between the points Script file:test dist2.m % Purpose: % This program tests function dist2 % Record of revisions: Date Programmer Description of change 12/15/98 S.J.Chapman original code % Define variables: ax--x-position of point a ay--y-position of point a bx --x-position of point b by--y-position of point b result--Distance between the points Get input data. disp('Calculate the distance between two points:) ax input('Enter x value of point a:'); ay input('Enter y value of point a:'); bx input('Enter x value of point b:'); by input('Enter y value of point b:') Evaluate function result dist2 (ax,ay,bx,by); Write out result. fprintf('The distance between points a and b is %fn',result); 直接在命令窗口运行该脚本文件: >>test dist2 Calculate the distance between two points: Enter x value of point a:1 Enter y value of point a:I Enter x value of point b:4 Enter y value of point b:5 The distance between points a and b is 5.000000 >>help dist2 DIST2 Calculate the distance between two points Function DIST2 calculates the distance between two points(xl,yl)and (x2,y2)in a Cartesian coordinate system Calling sequence: res=dist2(xl,y1,x2,y2) 17 % bx -- x-position of point b % by -- y-position of point b % result-- Distance between the points % Script file: test_dist2.m % Purpose: % This program tests function dist2. % Record of revisions: % Date Programmer Description of change % 12/15/98 S. J. Chapman original code % Define variables: % ax -- x-position of point a % ay -- y-position of point a % bx -- x-position of point b % by -- y-position of point b % result-- Distance between the points % Get input data. disp('Calculate the distance between two points:'); ax = input('Enter x value of point a:'); ay = input('Enter y value of point a:'); bx = input('Enter x value of point b:'); by = input('Enter y value of point b:'); % Evaluate function result = dist2 (ax, ay, bx, by); % Write out result. fprintf('The distance between points a and b is %f\n', result); 直接在命令窗口运行该脚本文件: >>test_dist2 Calculate the distance between two points: Enter x value of point a: 1 Enter y value of point a: 1 Enter x value of point b: 4 Enter y value of point b: 5 The distance between points a and b is 5.000000 >>help dist2 DIST2 Calculate the distance between two points Function DIST2 calculates the distance between two points (xl,yl) and (x2,y2) in a Cartesian coordinate system. Calling sequence: res = dist2(xl, y1, x2, y2) ……
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有