我对 MATLAB 很陌生,我有以下代码:
a=500;
PI=3.14159265;
radconvert=PI/180;
degconvert=180/PI;
% values at t=9, t=10 and t=11 respectively
alpha=[54.80 54.06 53.34];
beta=[65.59 64.59 63.62];
% converting degrees to radians
for i = 1:3
alpha(i) = alpha(i)*radconvert;
end
for i = 1:3
beta(i) = beta(i)*radconvert;
end
% declaring x and y functions
function x(a, alpha, beta)
(a*tan(beta))/(tan(beta)-tan(alpha));
function y(a, alpha, beta)
(a*tan(alpha)*tan(beta))/(tan(beta)-tan(alpha));
% doing the calculations
vx1=x(a, alpha(2), beta(2)) - x(a, alpha(1), beta(1));
vy1=y(a, alpha(2), beta(2)) - y(a, alpha(1), beta(1));
vf1=sqrt(vx1^2 + vy1^2);
vx2=x(a, alpha(3), beta(3)) - x(a, alpha(2), beta(2));
vy2=y(a, alpha(3), beta(3)) - y(a, alpha(2), beta(2));
vf2=sqrt(vx2^2 + vy2^2);
vf=(vf1+vf2)/2;
vxavg=(vx1+vx2)/2;
vyavg=(vy1+vy2)/2;
theta = atan(vyavg/vxavg)*degconvert;
% printing the values
sprintf('Velocity at t=10 is: %.2f\n', vf);
sprintf('Climb angle theta is: %.2f\n', theta);
如果我尝试运行它,我会收到以下错误消息:
???错误:文件:code.m 行:20 列:1 在此上下文中不允许函数定义。
我想我不能在同一个 .m 文件中声明和使用函数。有人可以帮我解决这个问题吗?