Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X
On seeing an expression of the form ln(x+a)^2 I would assume that to evaluate it (x+a) is first squared and then the log of the result is found. I was surprised to find that in Mathcad the log is evaluated first and then the result is squared. This seems to apply to other functions. It took me a while to figure out this as the cause of the error in some calculations. Has anyone else been caught out by this or am I being naive?
Solved! Go to Solution.
Brian Earthrowl wrote:
On seeing an expression of the form ln(x+a)^2 I would assume that to evaluate it (x+a) is first squared and then the log of the result is found. I was surprised to find that in Mathcad the log is evaluated first and then the result is squared. This seems to apply to other functions. It took me a while to figure out this as the cause of the error in some calculations. Has anyone else been caught out by this or am I being naive?
If you choose a function from the function menu you will notice that in all cases it is inserted into the worksheet with a name and a pair of brackets, thus: ln(#) or sin(#) or mod(#,#) ...etc. (where the # is a rectangular black placeholder in Mathcad). Thus the function includes the brackets, so ln(#)^2 raises the whole function to the power 2. This also holds if you type the function in by hand. You need to write ln((x+a)^2) if you want to square the argument before activating the function.
Alan
I always say to my students: use not 2+2*2 but 2+(2*2), not log(2) but log(2, 10) Etc and no problem
... and a correct sine - without brackets:
Brian Earthrowl wrote:
On seeing an expression of the form ln(x+a)^2 I would assume that to evaluate it (x+a) is first squared and then the log of the result is found. I was surprised to find that in Mathcad the log is evaluated first and then the result is squared. This seems to apply to other functions. It took me a while to figure out this as the cause of the error in some calculations. Has anyone else been caught out by this or am I being naive?
If you choose a function from the function menu you will notice that in all cases it is inserted into the worksheet with a name and a pair of brackets, thus: ln(#) or sin(#) or mod(#,#) ...etc. (where the # is a rectangular black placeholder in Mathcad). Thus the function includes the brackets, so ln(#)^2 raises the whole function to the power 2. This also holds if you type the function in by hand. You need to write ln((x+a)^2) if you want to square the argument before activating the function.
Alan
Thanks Alan. I had copied formulae verbatim from a text book and did not use the function menu. The way Mathcad deals with functions as you describe is logical but caught me unaware at first. I had already fixed the problem with additional pairs of brackets.
Brian