I have defined a really basic function in matlab. It takes no input and returns an array of 10 floating point numbers. The problem I have is that when I run the function to return the array I want I get incorrect values, however when I substitute in a value and simply print out the value from within the function I get the correct answer?! I've posted samples from the code below:
% Calculate the terms in our expression
FirstTerm = sin(Alpha)*(atan(x+d)-atan(x-d));
SecondTerm = cos(Alpha)*0.5*log(((x+d).^2+h.^2)/((x-d).^2+h.^2));
% Combine and return result
Result = 2 * (FirstTerm - SecondTerm)
FirstTermTemp = sin(Alpha)*(atan(-8+d)-atan(-8-d));
SecondTermTemp = cos(Alpha)*0.5*log(((-8+d).^2+h.^2)/((-8-d).^2+h.^2));
ResultTemp = 2 * (FirstTermTemp - SecondTermTemp)
The array I want to calculate for starts at -8 so the results should match. Does anyone have any idea why they wouldn't? Cheers Jack
You have left off a .
before your /
% //Calculate the terms in our expression
FirstTerm = sin(Alpha)*(atan(x+d)-atan(x-d));
SecondTerm = cos(Alpha)*0.5*log(((x+d).^2+h.^2)./((x-d).^2+h.^2));
% //Combine and return result
Result = 2 * (FirstTerm - SecondTerm)
Result =
Columns 1 through 7:
0.097944 0.133866 0.208270 0.425797 0.692904 -0.140347 -0.124798
Columns 8 and 9:
-0.095581 -0.076166