Save Plot Options of Mathematica into a single variable - plot

How can I save the numerous Plot options in Mathematica into a single variable

As per this answer,
opts = {PlotRange -> All, PlotStyle -> Red};
Plot[x^2, {x, 0, 1}, Evaluate[opts]]

Related

Plotting function of 2D space + time using Plot3D in Mathematica

Is there a simple way of plotting a function f(x,y,t) = Exp[t-x-y] by setting the time t? I've tried several variations of
Plot3D[Evaluate[f[t,x,y],t->0],{x,0,1},{y,0,1},PlotRange -> All]
But I can't get it to work. I want to be able to change t and see how the plot changes, but I'm also using the equation f for a differential equation so I'm taking partials and I need t to be symbolic for other parts of the notebook. Or is there a way to make a plot video that updates with time?
Expanding on the comments.
Interactively manipulate the plot
f[x_, y_, t_] := Sin[t x] Sin[t y]
Manipulate[Plot3D[f[x, y, t], {x, -Pi, 2 Pi}, {y, -Pi, Pi}], {t, 0, 3, 1/8}]
Generate a list of plots
plots = Table[Plot3D[f[x, y, t], {x, -Pi, 2 Pi}, {y, -Pi, Pi}], {t, 0, 3, 1/8}];
Export the plots to an animated GIF
Export["plots.gif", plots]

Colour ListPointPlot3D points by index in Mathematica

Is it possible to colour points based on list index value? E.g. suppose I have a set of coordinates
l1 := {{20.729858261394142, -11.014787072072988, 20.910738872021085}, {26.754953134772755, 12.795549555413617, 12.35084230079088}, {-26.240583655553486, 14.046344120397391, 4.267648394595125}, {-28.350142916856896, -15.381100510373342, 2.203525286738756}}
I then use this Mathematica command
ListPointPlot3D[l1, PlotStyle -> {Blue, PointSize[0.025]}]
I want to be able to specify the first point as red, the second a green, the third as blue, etc.
I'd rather not use Show[...] with multiple ListPointPlot3D commands...
I found this related question, but this colours based on (x, y, z) coordinate values.
another way:
Graphics3D[{PointSize[0.05],
MapIndexed[ { Blend[{Red, Green, Blue, Yellow},
(1/Length#l1) First##2], Point[#]} &, l1]}]
In this form you can readily switch Point to Sphere which looks a bit nicer.
I worked it out. We can use, for example,
Graphics3D[{PointSize[0.05], Point[l1,
VertexColors -> (Blend[{Red, Green, Blue, Yellow}, #] & /# Rescale#Range#Length[l1])]},
BoxRatios -> {1, 1, 1}, Axes -> False]
Another way, using ListPointPlot3D, is just to put extra curly brackets for each point,
ListPointPlot3D[{{{1, 0.5, 1}}, {{1, 1, 1}}, {{1, 1.5, 1}}},
PlotStyle -> {
Directive[{Red, PointSize[0.03]}],
Directive[{Blue, PointSize[0.04]}],
Directive[{Black, PointSize[0.03]}]
}
]

Real-life application of sinc-in-time data or sinc(t) function?

I found that my customers' response time on an application is varying in a Sinc-in-time fashion. i.e. Sinc(t) across time. Can this information be applied to obtain any relevant system other than just for a fun observation?
If you customers' response is following a diminishing oscillatory response as plotted below, you could apply measurements to create a PID controller.
Plot[{2, -2 Sinc[x] + 2}, {x, 0, 6 Pi},
PlotRange -> {Automatic, {0, 3}},
PlotStyle -> {Dashed, Automatic},
Epilog -> {
Inset[Style["Initiation", 14], {3, 0.2}],
Inset[Style["Response", 14], {14, 2.2}]}]
With variation in the terms you can modify the response to follow a path such as shown below.
Ref: PID controller theory
There is also a relevant Mathematica demonstration: PID Control of a Tank Level

Dynamic is not working properly

I'm having some troubles with the Dynamic command in Mathematica, the next code shows an interactive graphic of the function f(x) = 1 - x^2. The graphic's title also shows the current area under the curve (definite integral) which is modified using the slider.
Manipulate[Show[Plot[1 - x^2, {x, 0, 1}, PlotLabel -> Integrate[1 - x^2, {x, 0, Limite - 0.000000000001}]],
Plot[-x^2 + 1, {x, 0, Limite}, PlotRange -> {0, 1}, Filling -> Axis] ], {Limite, 0.000000000001, 1}, LocalizeVariables -> False]
I would like to show the current area using this command:
Integrate[1 - x^2, {x, 0, Dynamic[Limite]}]
but the result is not what i expected. Mathematica evaluates this like
0.529 - (0.529)^3 / 3
which is correct but i don't understand why it displays an expression instead of a single number. The //FullSimplify and//N commands just don't solve the problem.
Is there a better way to obtain the result?
Am I using the Dynamic command correctly?
Thanks!
With your example the Integrate command is performed once with a symbolic upper limit. When the value of that upper limit changes the integral is not recomputed. You will get your desired result if you move the Dynamic[] wrapper from the iterator specification and wrap it around the Integrate command, which will cause the integral to be recomputed whenever Limite changes.
Dynamic[Integrate[1 - x^2, {x, 0, Limite}]]

Sketching solution curves for differential equations

I have a few differential equations that I'd like to draw solutions for, for a variety of start values N_0
Here are the equations:
dN\dt= bN^2 - aN
dN\dt = bN^2 (1 - N\K) - aN
How would I go about it?
I don't really care about the language is used. In terms of dedicated math I have mathematica and matlab on my computer. I've got access to maple. I have to do more of this stuff, and I'd like to have examples from any language, as it'll help me figure out which one I want to use and learn it.
I'll pretend the first one cannot be solved analytically so as to show how one would go about playing with a general ODE in mathematica.
Define
p1[n0_, a_, b_, uplim_: 10] :=(n /. First#NDSolve[
{n'[t] == b*n[t]^2 - a*n[t], n[0] == n0},n, {t, 0, uplim}]
which returns the solution of the ODE, i.e., a = p1[.1, 2., 3.] and then e.g. a[.3] tells you n(.3). One can then do something like
Show[Table[ans = p1[n0, 1, 1];
Plot[ans[t], {t, 0, 10}, PlotRange \[Rule] Full],
{n0, 0, 1, .05}], PlotRange \[Rule] {{0, 5}, {0, 1}}]
which plots a few solutions with different initial values:
or, to gain some insight into the solutions, one can interactively manipulate the values of a, b and n0:
Manipulate[
ans = p1[n0, a, b];
Plot[ans[t], {t, 0, 10},PlotRange -> {0, 1}],
{{n0, .1}, 0, 1},
{{a, 1}, 0, 2},
{{b, 1}, 0, 2}]
which gives something like
with the controls active (i.e. you move them and the plot changes; try it live to see what I mean; note that you can set parameters for which the initial conditions gives diverging solutions).
Of course this can be made arbitrarily more complicated. Also in this particular case this ODE is easy enough to integrate analytically, but this numerical approach can be applied to generic ODEs (and many PDEs, too).
Adding to the several good answers, if you just want a quick sketch of an ODE's solutions for many starting values, for guidance, you can always do a one-line StreamPlot. Suppose a==1 and b==1, and dy/dx == x^2 - x.
StreamPlot[{1, x^2 - x}, {x, -3, 3}, {y, -3, 3}]
StreamStyle -> "Line" will give you just lines, no arrows.
In Mathematica you use NDSolve (unless it can be solved analytically, in which case you use DSolve. So for your first equation I tried:
b = 1.1; a = 2;
s = NDSolve[{n'[t] == b n[t]^2 - a n[t], n[0] == 1}, n, {t, 0, 10}];
Plot[Evaluate[n[t] /. s], {t, 1, 10}, PlotRange -> All]
I didn't know what to use for a, b or N0, but I got this result:
If you're happy to solve the equations numerically, MATLAB has a set of ODE solvers that might be useful. Check out the documentation for the ode45 function here.
The general approach is to define an "ode function" that describes the right-hand-side of the differential equations. You then pass this function, along with initial conditions and an integration range to the ode solvers.
One attractive feature of this type of approach is that it extends in a straight-forward way to complex systems of coupled ODE's.
Hope this helps.

Resources