Mathematica: If statment for lists

  • Context: Mathematica 
  • Thread starter Thread starter Sarah rob
  • Start date Start date
  • Tags Tags
    Mathematica
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 4K views
Sarah rob
Messages
16
Reaction score
0
I want to create an If statement that states; if the elements in, list1>0 , true subtract list2, false keep value from list1 so that i
end up with ans: {0,2,5,4}
list1 = {0, 2, 8, 9}
list2 = {1, 0, 3, 5}
I don't know how to represent the elements in the lists so that my If statement works
 
Physics news on Phys.org
Excellent example showing input and output. That makes it much easier to provide correct help.

In[12]:=list1={0,2,8,9};list2={1,0,3,5};
f[x_,y_]:=If[x>0,x-y,x];
MapThread[f,{list1,list2}]

Out[15]={0,2,5,4}