Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Mathematica Help!!!

  • 22-02-2011 1:03pm
    #1
    Registered Users, Registered Users 2 Posts: 249 ✭✭


    Hi guys,

    I am learning (slowly) how to use Mathematica. I'm completely flumped on something tho.

    I have an equation where all the variables will change in certain increments.

    Rather than putting in the values one by one and pressing shift and enter to get the result each time, is there a way to specify the increments for each variable and output all the results into a table so that i can plot them?

    I really need help with this, Ive been trying to use the array command all morning.

    I'll be permanently indebted to anyone who can help!

    Cheers


Comments

  • Registered Users, Registered Users 2 Posts: 2,481 ✭✭✭Fremen


    Try running a FOR loop inside a BLOCK statement.

    I don't have a copy of mathematica anymore, so that's about all I can say.


  • Registered Users, Registered Users 2 Posts: 2,149 ✭✭✭ZorbaTehZ


    The easiest way is to use table
    Say your function is x + 2y +z/5 and x goes in steps of 2, y in steps of 3 and z in steps of 7 (this is what you mean?) then
    Table[x+2y+z/5,{x,1,100,2},{y,1,100,3},{z,1,100,7}]
    


  • Registered Users, Registered Users 2 Posts: 249 ✭✭tonsiltickler


    LongRad[douter_, TransRad_, r_]:= 1/2 *((douter2 + (TransRad-r)2)/(TransRad-r));

    Hi Zorba,
    This is one of the formulas. Ill have ten different values of TransRad and the douter and r stay constant. I used a table to get the values for TransRad, I just dont know how to evaluate the formula for the different values! Is it a Do or For Loop( as Fremen said?)


  • Registered Users, Registered Users 2 Posts: 3,745 ✭✭✭Eliot Rosewater


    I think you should use Map.

    The problem with map though is that it only works with functions of one variable. So I would define a new function Transrad2, which has one variable.
    LongRad[douter_, TransRad_, r_] := 
      1/2*((douter + (TransRad - r) 2)/(TransRad - r));
    
    LongRad2[Transrad_] := LongRad[a, Transrad, b]
    

    In the second line a and b are your constants for douter and r respectively. Then use Map on LongRad2:
    values = {1, 22, 4, 5, 6, 3, 89, 4, 90, 3}
    Map[LongRad2, values]
    


  • Registered Users, Registered Users 2 Posts: 249 ✭✭tonsiltickler


    I will try that, thanks to all of you for your responses


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 2,149 ✭✭✭ZorbaTehZ


    You can use more than one variable for map but you need to use the shorthand version. I don't have a copy on this pc so I can't check it, but something like
    LongRad[#1,#2,#3]&/@List2
    
    But then list would need to contain 3-tuples so a rough-ready approach would be
    List2=Transpose[Table[a,Length@List],List,Table[b,Length@List]
    
    You should avoid using procedural statements in Mathematica because it is very inefficient and bad practice really, Mathematica is and should be a functional language.


  • Registered Users, Registered Users 2 Posts: 3,745 ✭✭✭Eliot Rosewater


    ZorbaTehZ wrote: »
    You should avoid using procedural statements in Mathematica because it is very inefficient and bad practice really, Mathematica is and should be a functional language.

    I emphatically second this! One time I did a thing in For loops and it crawled; but once I converted it to proper Mathematica stuff it raced through it.


Advertisement