I'm pretty new to MATLAB and I have the following code:
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);
If I try to run it, I get the following error message:
??? Error: File: code.m Line: 20 Column: 1 Function definitions are not permitted in this context.
I guess I cannot declare and use functions in the same .m file. Can someone help me solve this problem?
vx1,vy1etc. That won't work.