I'm new to Mathematica and am trying to implement some simple noise functions in it in hopes of eventually finding an integral for them. This is the interesting part of the code:
PRNTable = Import["C:/Users/alemariusnexus/noisetest/prntable.csv"];
PermTable = Flatten[Import["C:/Users/alemariusnexus/noisetest/permtable.csv"]];
latticeidx[{x_}] := PermTable[[Mod[x, Length[PermTable]] + 1]];
lnoise[ip_] := PRNTable[[latticeidx[ip] + 1, 1]];
crBaseMatrix = Transpose[{
{0, 1, 0, 0},
{-0.5, 0, 0.5, 0},
{1, -2.5, 2, -0.5},
{-0.5, 1.5, -1.5, 0.5}
}];
crspline[t_, cps_List] := Module[{n, globalT, baseIdx, localT},
n = Length[cps];
globalT = t*(n - 3);
baseIdx = Clip[Floor[globalT], {0, n - 4}];
localT = Clip[globalT - baseIdx, {0, 1}];
Transpose[
Table[cps[[
baseIdx + x + 1]], {x, {0, 1, 2, 3}}]] . (crBaseMatrix . {1,
localT, localT*localT, localT*localT*localT})
];
vnoisebase[{x_Real}, {axis_List}, offset_List] := crspline[
x - Floor[x],
Table[
{lnoise[(Floor[x] + w) * axis + offset]},
{w, -1, 2}
]
];
Evaluate[Integrate[vnoisebase[{x}, {{1}}, {0}], x], Assumptions -> x \[Element] Reals]
With this code, Mathematica just tells me
$$ \text{Sequence}\left[\int \text{vnoisebase}\left(\{x\},\left( \begin{array}{c} 1 \\ \end{array} \right),\{0\}\right) \, dx,\text{Assumptions}\to x\in \mathbb{R}\right] $$
Which does not really help much. I tried around a bit and found that when I change the first line in the definition of vnoisebase to
vnoisebase[{x_}, {axis_List}, offset_List] := crspline[
i.e. changing "x_Real" to just "x_", it outputs at least something (the amount of random numbers in which makes me think it might be wrong though). But I declared x to be a real number in the Assumptions of Integrate[], so why did this not work with the type suffix?
Also, I'm getting lots of warnings (errors?) like the following:
Part::pkspec1: "The expression 1+Mod[-1+Floor[x],256] cannot be used as a part specification."
Which seems to come from the list indexing in latticeidx[]. Why can't this expression be used as an index?
vnoisebase[{x_Real}, {axis_List}, offset_List]
means that you have restrictedvnoisebase
to evaluating only whenx
is an inexact number (which is what theReal
head means). If you want it to work with nonnumeric arguments, it would seem that you've already figured out what you're supposed to do. $\endgroup$f[x_Real] := x^2
as an example.f[0.5]
will work, but notf[1/2]
orf[2]
. You'll want to use a pattern likef[x_?NumericQ]
if you want it to evaluate at a number. $\endgroup$