Here is some code that will let you vary the shape you are rendering fairly easily but does not use Manipulate
. It might be useful to you in the short term. I will put more work in this problem, and try to build a useful interactive version with Manipulate
. I will update this answer when I have such code.
With[{n = 100},
z = Subdivide[0, 2 Pi, n];
x = .5 (1 + Cos[#]) & /@ z;
{xl, xu} = TakeDrop[x, n/2];]
With[{n1 = .5, n2 = 1.}, class[x_] := x^n1 (1 - x)^n2]
shape[w_, x_] :=
With[{n = Length[w]}, Sum[BernsteinBasis[n - 1, j - 1, x] w[[j]], {j, n}]]
y[w_, x_, dz_] := class[x] shape[w, x] + x dz
cst[wl_, wu_, dz_] := Transpose[{x, Flatten[{y[wl, xl, -dz], y[wu, xu, dz]}]}]
Note that the above code simplifies and speeds up the computation of x
, xu
and xl
.
I recommend expressing the plot within a With
expression that assigns the parameters.
With[
{dz = 0.0002,
wup = {.19, .20, .29, .27, .31, .16},
wlo = {-.12, -.13, -.14, -.16, -.15, .1}},
ListPlot[cst[wlo, wup, dz]]]
Using With
makes it easy to specify a new design by simply editing the parameter definitions. For example,
With[
{dz = 0.0005,
wup = {.19, .21, .29, .27, .3, .2, .1},
wlo = {-.12, -.13, -.14, -.16, -.15, -.2, -.1}},
ListPlot[cst[wlo, wup, dz]]]
This is not too bad a way to explore the design space, even if it is not as sexy as interactive manipulation.
Update
Here is an interactive version. It's pretty simple but I think it is usable. I decided that inputs fields would be an easy and simple way to get the user's inputs. Input fields are something everyone can be expected to understand, but have the disadvantage of being hard to make bullet-proof. I implemented only a minimum of input checking — just enough to give a hint of how it might done. I think implementing elaborate input checking is out of scope for this question. I leave it as an exercise to the reader.
I only show the new code. Everything else is as it was before.
test = List[RepeatedNull[_Real?(Between[#, {-1., 1.}] &)]];
badParamMsg =
"one of the inputs, w-upper, w-lower or dz, is invalid";
okMsg = Invisible[
"one of the inputs, w-upper, w-lower or dz, is invalid"];
Manipulate[
If[MatchQ[wlo, test] && MatchQ[wup, test] && MatchQ[dz, _Real],
pts = cst[wlo, wup, dz]; msg = okMsg,
pts = {}; msg = badParamMsg];
Column[
{ListPlot[pts, Frame -> True, ImageSize -> {500, Automatic}],
Style[Row[{"Message ", Framed[msg]}], "SR", 11]},
Center],
{{wup, {.19, .21, .29, .27, .3, .2, .1}, "w-upper"},
InputField, ImageSize -> {500, Automatic}},
{{wlo, {-.12, -.13, -.14, -.16, -.15, -.2, -.1}, "w-lower"},
InputField, ImageSize -> {500, Automatic}},
{{dz, .0002, "dz"}, InputField, ImageSize -> {50, Automatic}},
{{pts, {}}, None},
{{msg, okMsg}, None},
TrackedSymbols :> {wlo, wup, dz},
SaveDefinitions -> True]
To get a edit to an input field recognized, you must Tab out of the field. Do not press Return — that will result in a new Manipulate
panel being generated.
cst
anywhere. $\endgroup$x
andz
have fixed lengthsn + 1
, son
must be specified, but you don't do that. You giveFor
three arguments, but it requires four. Until you correct these simple errors, I don't think there is much we do to help you build your interactive code. $\endgroup$Manipulate
might work. Meanwhile, I will post an interim answer that will let look at shape variations fairly easily without usingManipulate
. $\endgroup$