5
$\begingroup$

I want to create a loop in Mathematica such that it creats multiple graphs for me. For example, I have a command of the form:

Plot3D[new[α, χ, τ] - old[τ], {α, 0, 2 π}, {χ, 0, π}, MaxRecursion -> 0, 
 AxesLabel -> Automatic] $$.

I can make a 3D graph for, say, τ = 0.1. What if I want to make multiple graphs for multiple values of τ -- say, for τ = 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9 and 1.0. That is, for 10 different vales of τ.

How would one going about this problem?

Edit: I couldn't find an appropriate tag for 'loops.'

$\endgroup$

1 Answer 1

10
$\begingroup$

Use Table

old[τ_] := Sin[τ]
new[α_, χ_, τ_] := Sin[α τ]^2 + Cos[χ τ]^2

result = Table[Plot3D[ new[α, χ, τ] - old[τ], {α, 0, 2 π}, {χ, 0, π}, 
   MaxRecursion -> 0, AxesLabel -> Automatic] , {τ, 1/10, 1, 1/10}]
Export["result.gif", result]

enter image description here

enter image description here

Or use Animate

Animate[Plot3D[ new[α, χ, τ] - old[τ], {α, 0, 2 π}, {χ, 0, π}, 
 MaxRecursion -> 0, AxesLabel -> Automatic] , {τ, 1/10, 1, 1/10}]

For one graph use:

f = Table[new[α, χ, τ] - old[τ], {τ, 1/10, 1, 1/10}]
cd = Table[ColorData[97, c], {c, 10}]

Plot3D[Evaluate@f, {α, 0, 2 π}, {χ, 0, π}, 
 MaxRecursion -> 0, AxesLabel -> Automatic, PlotStyle -> cd] 

enter image description here

$\endgroup$
3
  • $\begingroup$ Actually, I want them on separate graphs -- and not one. $\endgroup$ Commented Jul 22, 2016 at 20:09
  • $\begingroup$ @JunaidAftab Updated $\endgroup$
    – Young
    Commented Jul 22, 2016 at 20:12
  • 1
    $\begingroup$ This seems a flag in the wind $\endgroup$
    – LCarvalho
    Commented Nov 19, 2016 at 16:38

Your Answer

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

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