Message Boards Message Boards

GROUPS:

Change the value of variable in a list

Posted 5 months ago
588 Views
|
2 Replies
|
1 Total Likes
|

How to evaluate an expression with a list of numbers:

Base4={x^2 Cos[x], Cos[x] Sin[x]}

(I want to know if the base is equal to 0 at points x=0 and x=Pi. So I do as following)

x=0; 

Base4

x=Pi; 

Base4

Clear[x]

(is there any way to do this in a single line?)

2 Replies
Anonymous User
Anonymous User
Posted 5 months ago

Two ways to do it "with one line" (there are more ways btw)

In[901]:= Map[{#^2 Cos[#], Cos[#] Sin[#]} &, {1, 2}]

Out[901]= {{Cos[1], Cos[1] Sin[1]}, {4 Cos[2], Cos[2] Sin[2]}}

In[893]:= f[x_] := {x^2 Cos[x], Cos[x] Sin[x]};

In[894]:= SetOptions[f[x], Listable]

Out[894]= SetOptions[{x^2 Cos[x], Cos[x] Sin[x]}, Listable]

In[896]:= f[{1, 2}]

Out[896]= {{Cos[1], 4 Cos[2]}, {Cos[1] Sin[1], Cos[2] Sin[2]}}
POSTED BY: Anonymous User
Answer
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract