TransWikia.com

How to have DiscretePlot of a domain with different criteria for different subdomains?

Mathematica Asked on April 6, 2021

If I have three criteria for the domain of $min{1,2,3,4,5,6,…,22}$ as

$$f(m)= cos left(frac{pi ^5 m}{4}right)quad for quad m=3,6,12,15,21$$
$$g(m)=frac{1}{sin left(frac{pi m}{3}right)}quad for quad m=1,2,4,5,7,8,10,11,13,14,16,17,19,20,22$$
$$h(m)=10quad for quad m=9,18$$

then how can I have one DiscretePlot for all $min{1,2,3,4,5,6,…,22}$, and then join the adjacent numbers.

f[m_] = Cos[(m ([Pi]^5) )/4] for m = 3, 6, 12, 15, 21

g[m_] = Sin[(m [Pi] )/3]^-1   for    m = 
  1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20, 22

h[m_] = 10 for m = 9, 18

2 Answers

{domf, domg, domh} = {{3, 6, 12, 15, 21}, {1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16,
     17, 19, 20, 22}, {9, 18}};

pw[m_] := Piecewise[{{Cos[(m (π^5))/4], MemberQ[m]@domf},
     {Sin[(m π)/3]^-1, MemberQ[m]@domg},
     {10, MemberQ[m]@domh}}]

DiscretePlot[pw[m], {m, Range[22]}, PlotRange -> All]

enter image description here

Alternatively,

fgh[m : Alternatives @@ domf] := Cos[(m (π^5))/4]
fgh[m : Alternatives @@ domg] := Sin[(m π)/3]^-1
fgh[m : Alternatives @@ domh] := 10

DiscretePlot[fgh[m], {m, Range[22]}, PlotRange -> All]
same picture

Correct answer by kglr on April 6, 2021

list1 = {3, 6, 12, 15, 21};
list2 = {1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20, 22};
list3 = {9, 18};
list = Union[list1, list2, list3];
f[m_ /; MemberQ[list1, m]] = Cos[(π^5 m)/4];
g[m_ /; MemberQ[list2, m]] = 1/Sin[(π m)/3];
h[m_ /; MemberQ[list3, m]] = 10;
DiscretePlot[{f[m], g[m], h[m]}, {m, list}, 
 PlotStyle -> {Red, Green, Blue}, PlotRange -> All]

enter image description here

Answered by cvgmt on April 6, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP