Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am fairly new to Mathematica and am trying to write a function for the equation:

xx = [x/(Sqrt[h^2 + d^2 + y^2]))*(Sqrt[h^2 + (d + yy)^2])

where h, d are known and x, y and yy are functions that give lists of numbers of equal list length. Is there a way to write a function that encompasses all the variables x, y, yy? I'm assuming it would start with

xx[x_, y_, yy_] := .........

or is the best method to create a loop?

share|improve this question
2  
Welcome to Mathematica.SE! I formatted your code for you. See this page to learn how that is done. By the way, your brackets don't match. The first one should be a round parenthesis. You should check out the answers to this question and the links from this part of the documentation. –  Verbeia Jan 29 '13 at 0:38
add comment

1 Answer

up vote 2 down vote accepted

No loop construct is necessary. Assuming that h, and d are constants defined at toplevel, and that you have the functions x, y and yy defined, you could proceed as follows:

hsq = h^2

xlist = x[...]

ylist = y[...]

yylist = yy[...]

xx[x_, y_, yy_] := x/(Sqrt[hsq + d^2 + y^2])*(Sqrt[hsq + (d + yy)^2])

xxlist = MapThread[xx, {xlist, ylist, yylist}]

The MapThread function will pluck successive items from xlist, ylist, and yylist, pass them to xx and gather up the computed values in a list which it returns.

This isn't the most sophisticated way to solve your problem with Mathematica, but at this point of your Mathematica experience, it may be the quickest and easiest way for you to do the calculations you want to carry out.

Your expression for xx isn't syntactically correct. I made a guess about where the parentheses go. Another interpretation I could have made is

xx[x_, y_, yy_] := x/((Sqrt[hsq + d^2 + y^2])*(Sqrt[hsq + (d + yy)^2]))

Use whichever is correct.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.