1
$\begingroup$

I have the function

myfun[a1_, a2_, a3_, b_, θ_, ϕ_] =
   a1 + 2 a2 + 3 a3 + b Cos[θ] + (a1 Cos[ϕ] + a2 Sin[ϕ]) Sin[θ];

The parameters satisfy $\sqrt{a1^2+a2^2+a3^2} + |b| \le 1$. I want to plot myfun with respect to $\theta$ and $\phi$. However, I want to do this for "various" combinations of the parameters $a1$,$a2$,$a3$ and $b$, satisfying above condition. Doing this by hand is very hard. Can we do this by Mathematica?

$\endgroup$

1 Answer 1

2
$\begingroup$

This may be what you mean:

First, initialize (I use := instead of your = )

Clear[myfun, plotfn]
myfun[a1_, a2_, a3_, b_, \[Theta]_, \[Phi]_] := a1 + 2 a2 + 3 a3 + b Cos[\[Theta]] + (a1 Cos[\[Phi]] + a2 Sin[\[Phi]]) Sin[\[Theta]]

Then, a plot function which plots what you ask for if the condition that you define is satisfied. Otherwise, it prints the result of the condition

plotfn[a1_, a2_, a3_, b_] /; (Sqrt[a1^2 + a2^2 + a3^2] + Abs[b] <= 1) := 
ContourPlot[
myfun[a1, a2, a3, 
b, \[Tau], \[Phi]], {\[Tau], -\[Pi], \[Pi]}, {\[Phi], -\[Pi], \
\[Pi]}];
plotfn[a1_, a2_, a3_, b_] := 
"Sqrt[\!\(\*SuperscriptBox[\(a1\), \
\(2\)]\)+\!\(\*SuperscriptBox[\(a2\), \
\(2\)]\)+\!\(\*SuperscriptBox[\(a3\), \(2\)]\)]+|b|" -> 
N[Sqrt[a1^2 + a2^2 + a3^2] + Abs@b]

A Manipulate allows to vary a bit

Manipulate[
plotfn[\[Alpha]1, \[Alpha]2, \[Alpha]3, \[Beta]], {{\[Alpha]1, .1}, \
-1, 1}, {{\[Alpha]2, .1}, -1, 1}, {{\[Alpha]3, .1}, -1, 
1}, {{\[Beta], .1}, -1, 1}]

edit: forgot the Abs around b in the condition

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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