# How to plot the output of a calculation with a changing variable

The following code successfully manages to plot the cross-section, and give me the maximum depth of a weld pool, for a given set of parameters. What I would ideally like to be able to do is to plot a graph of how the the maximum depth of a weld pool varies with a parameter (ie. v between 0.915 and 1.5). I think I am essentially looking to make a for loop so I can plug many different values for v in, However Do does not seem to work in this case. Any help would be greatly appreciated!

k = 15.75;
α = 5.79*10^-6;
T = 1015;
η = 0.6;
Q = 600;
v = 0.915;
y = 0;

g[x_?NumericQ] :=
Quiet[ FindRoot[T == (η Q)/(2 π k Sqrt[x^2 + y^2 + z^2])*Exp[
(-v (x + Sqrt[x^2 + y^2 + z^2]))/(2 α)],
{z, -0.0001, -0.1, -0.0000001}][[1, 2]]]

p = Plot[ g[x], {x, -0.00001, -0.0037}, Filling -> Axis,
FillingStyle -> Orange, AspectRatio -> Automatic]

FindMinimum[g[x], {x, -0.001}][[1]]

-
Just define your function as a function of the other parameter, for example: g[x_?NumericQ][v_?NumericQ] :=..., then you can express the minimum as a function of v. – Peltio Feb 24 '14 at 13:07
Thanks Pelito, but I am unsure how I can do this as the minimum is the z at a specific x value and the v is required to calculate z and x, so won't I have too many unknowns? – Jack Feb 24 '14 at 13:41

Try this

g[x_?NumericQ][v_?NumericQ] := Quiet[
FindRoot[
T == η Q/(2 π k Sqrt[x^2 + y^2 + z^2]) Exp[-v (x + Sqrt[x^2 + y^2 + z^2])/(2 α)],
{z, -0.0001, -0.1, -0.0000001}
][[1, 2]]
]


This should show how the curve g[x] varies with parameter v

Show[Table[
Plot[g[x][v], {x, -0.00001, -0.0037}, PlotRange -> {0, -.0002}],
{v, .9, 1.5, .1}]
]


While this computes a set of solutions for a range of values of v in the form {v, minimum of g[x][v]} . (If you wish you could create a function of v that computes the minimum of the curve for a given value of the parameter v, I leave that as an exercise to the student :-)) ).

minVals = Table[
{v, FindMinimum[g[x][v], {x, -0.001}][[1]] },
{v, .9, 1.5,.01}]


Once you have your minima, you can plot them with ListPlot

ListPlot[minvals]


Or you could try this

Plot[FindMinimum[g[x][v], {x, -0.001}][[1]], {v, .9, 1.5},
Filling -> Axis, FillingStyle -> Orange]


(Incidentally, the function plotted is the solution of the exercise left to the student :-) ).

-
Thanks Pelito, I think I am now getting closer to what I want (a plot of minimum z against v) by using a modified version of the third bit of code you left (I had to omit [v]). However I couldn't get any of the other bits you suggested to run. Thanks again for getting me back on the right tracks! – Jack Feb 24 '14 at 17:39