4
$\begingroup$

I define a function like this:

ϕ[t_,ϕ0_,ϕ1_]:=ϕ0+ϕ1/ArcSin[0.97] ArcSin[0.97 Sin[2Pi f(t-0.25/f)]]/.f->30 

which generate:

$$ \phi (t)=0.754586 \times \text{$\phi $1} \times\sin ^{-1}(0.97 \sin (60 \pi (t-0.00833333)))+\text{$\phi $0}$$

Then I want to generate two function with (ϕ0,ϕ1)=(0,10) and (ϕ0,ϕ1)=(100,200) with Table function like bellow:

Table[ϕ[t], {{ϕ0, ϕ1}, {{0, 10}, {100,200}}}]

But it doesn't work.

How to manage it ?

$\endgroup$
  • 4
    $\begingroup$ ϕ[t, ##] & @@@ {{0, 10}, {100, 200}} should work. Is that what you're looking for? If the syntax is unfamiliar, check out Apply and SlotSequence in the docs. $\endgroup$ – Martin Ender Mar 29 '16 at 15:11
  • 1
    $\begingroup$ If you really want to use Table you can "replace one of the @" in Martin's answer: Table[ϕ[t, ##] & @@ pp, {pp, {{0, 10}, {100, 200}}}] $\endgroup$ – BlacKow Mar 29 '16 at 15:21
  • $\begingroup$ @MartinBüttner Thank you very much. I've learnt a new skill ! $\endgroup$ – PureLine Mar 30 '16 at 1:53
  • $\begingroup$ @unlikely Frankly speaking, this method seems the same with using Rule. $\endgroup$ – PureLine Mar 30 '16 at 1:56
  • $\begingroup$ @BlacKow Thanks for sharing. Your method shares something in common with MikeLimaOscar's . $\endgroup$ – PureLine Mar 30 '16 at 1:58
3
$\begingroup$

Changing your initial function definition slightly makes using Table easier and saves having to mess around with SlotSequence, Function, Apply, etc. For example, I would define ϕ as:

ϕ[t_, {ϕ0_, ϕ1_}] := ϕ0 + ϕ1 / ArcSin[0.97] ArcSin[0.97 Sin[2Pi f(t - 0.25 / f)]] /. f -> 30

Such that the parameters are paired in a single argument. Then you can use:

Table[ϕ[t, ϕ01], {ϕ01, {{0, 10}, {100,200}}}]

which I think is "more natural".

Incidentally, the replacement of f occurs every time the function ϕ is evaluated which is inefficient. It would be better to wrap the RHS of your definition in Evaluate.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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