I am new to Mathematica, and using a Module to perform a procedure, then return a value. However, Mathematica seems to be evaluating and returning symbolic values instead of the numerical value I want.
Questions I have are: When don't you use semicolons? And when do you use Return[value] instead of just writing "value"?
DumpVar[x_] := Print[ToString[HoldForm[x]], ":", x];
SetAttributes[DumpVar, {Listable, HoldAll}]
width = 1;
interval = width/2;
panelCoeff = 2;
lightAngle = Pi/3;
(*Panel and light equations*)
panel[x_] = Abs[panelCoeff x];(*panelCoeff ((x)^2);*)
light[x_] = Tan[lightAngle]*x;
getAngleAttack[offset_] :=
Module[{bounce1x, l1a, lightSlope, panelSlope},
light[x_] = light'[x] (x - offset) + panel[interval];
DumpVar[offset];
lightSlope = N[light'[offset]];
u1S = light'[offset];
u1[x_] = (u1S (x - offset)) + panel[interval];
bounce1x =
x /. N[NSolve[u1[x] == panel[x] && x < interval && x > -interval,
x]];
u1r[x_] = panel'[bounce1x] (x - bounce1x) + panel[bounce1x];
If[Length[bounce1x] > 0,
bounce1x = bounce1x[[1]];,
bounce1x = offset;
]
If[bounce1x > -interval && bounce1x < interval,
lightSlope = N[u1'[bounce1x]];
If[x <= 0,
panelSlope := N[panelCoeff],
panelSlope := -N[panelCoeff]];
DumpVar[lightSlope];
DumpVar[panelSlope];
l1a =
N[ArcTan[(lightSlope -
panelSlope)/(1 + (panelSlope lightSlope))]];
DumpVar[l1a];
l1a
Return[l1a]
]
Return[l1a];
];
myint = getAngleAttack[0];
(*myint = N[f[10]];*)
DumpVar[myint];
Plot[{panel[x], light[x]}, {x, -.6, .6}]
myint = getAngleAttack[.5];
DumpVar[myint];
My goal is to be able to graph and integrate this function.