43

I'm one of the developers behind this functionality, so I might be biased, but in my opinion this does provide a huge new feature set to Mathematica users. What practical use do these new functions have for those who don't have the full SystemModeler? The new functions provide a sophisticated analysis environment for system modeling. They do that stand-...


27

Here I will attempt to provide a basic implementation of the random forest algorithm for classification. This is by no means fast and doesn't scale very well but otherwise is a nice classifier. I recommend reading Breiman and Cutler's page for information about random forests. The following are some helper functions that allow us to compute entropy and ...


27

This kind of backtest is often performed using approximations, for instance with normal distributions, which may not be always valid. An exact test would be very nice to have. The probability distribution that is necessary to describe this process is the so-called Poisson Binomial distribution. It describes the sum of independent Bernoulli experiments ...


23

Similar to previous answers, only I don't make the instantaneous absorption assumption since it isn't really necessary. The equation can be found here on page three, where ka and ke are the rates of absorption and elimination, respectively, D is the initial dose (in ng), V/F is the Volume of Distribution. The range of apparent volumes of distribution I've ...


20

Modified Newton Cooling Law implementation and reduced FEA cell length Clear["Global`*"] len = 1;(*length of domain*) end = 5;(*end time*) h = 2;(*convection coefficient*) cpmR = 9;(*heat capacity/mass ratio*) Tinit = 0;(*initial temperature of the bar*) T0init = 100;(*initial temperature of the fluid*) (*Tsol=temperature in the bar,T0sol=temperature on ...


16

I think the simple answer is, there isn't one, but you could always just use UML itself, particularly for behavioral diagrams, even if the code isn't object oriented. You wouldn't use class or object diagrams, but there is nothing to stop you from using, say, a component diagram. You may find the tutorial and white paper on building large software systems ...


15

Disclaimer: This is not an implementation of the Random Forest Algorithm. Also, while I have on occasion used random florists, until today I had not heard of the Random Forest Algorithm. I poked around a bit on the Net and learned that these take subsamples of data, subsampling the variables as well, and form decision trees for the subsetted subsamples. ...


15

First let me observe that your coding style makes debugging difficult, I highly recommend breaking giant expressions into manageable pieces. Second, in the code below I have used a different definition for the segments. Your version: $y=(x-x_1)^{curvature}\frac{y_2-y_1}{x_2-x_1}+y_1$ does not give an amplitude of $y_2$ at $x=x_2$ if $curvature\neq1$. I ...


14

I first create the plot with GridLines -> Automatic: plot = Plot[-Sin[x], {x, -10, 0}, PlotRange -> {{-10, 1}, {-1.1, 1.1}}, ImageSize -> {500, 100}, Axes -> False, GridLines -> Automatic] Then I combine your graphics object with plot using Inset: Manipulate[ Graphics[{Circle[], PointSize[0.012], Point[{Cos[t], Sin[t]}], ...


14

In the scalar approximation, the obstacle could be modeled by an abrupt change in the wave speed $c$. This speed is unity in your original calculation, and I'm just going to insert its inverse square as a prefactor in front of the second time derivative. The spatial shape is defined as an elongated box using Boole: tsunamiEqn = u /. NDSolve[{(1/(1 - 0....


14

Assuming the simplest kinetic model for elimination (and making the simplifying assumption of "instant absorption" to peak concentration): conc = {{0, 0}, {.25, 1}, {.5, 7}, {1, 26}, {1.5, 40}, {2, 45}, {2.5, 45}, {3, 44}, {3.5, 44}, {4, 43}, {4.5, 41}, {5, 39}, {6, 38}, {7, 37}, {8, 35}, {9, 33}, {10, 32}, {11, 29}, {12, 24}, {24, 13}, {48, ...


12

Consider a model where the nonlinearity is in $x'(t)$ and not in the highest derivative $x''(t)$. eq1 = {x''[t] + Sin[ x'[t]] + x[t] == u[t]}; Choose the first state as $x(t)$ (call it $\bar{x}_1(t)$) and the second state as $x'(t)$ (call it $\bar{x}_2(t)$) and we get the following equations. $$ \bar{x}_1'(t)=\bar{x}_2(t)$$ $$ \bar{x}_2'(t)+\sin \left(\...


12

Mimicking the examples in FindFit >> Applications >> DifferentialEquations NonlinearModelFit >> Generalizations and Extensions ClearAll[x, y, b, β, model] b0 = .7; sol = First[y /. NDSolve[{y''[x] + Sin[y[x]] + b0 y'[x] == 0, y[0] == 1.5, y'[0] == 0}, y, {x, 0, 3 Pi}]]; xvals = N[Range[0, 3 Pi, 3 Pi/100]]; data = Transpose[{xvals, sol[xvals] + ...


12

First question. I'm pretty sure that the difference is due to what happens with machine underflow. As of V11.3, underflow goes to machine zero instead of to arbitrary-precision numbers (as it does in versions < 11.3). See (94996), (169361), (174587). Try SetSystemOptions["CatchMachineUnderflow" -> False] in versions < 11.3 to see if it will prevent ...


11

Standard errors and confidence intervals from linear and nonlinear regressions are obtained from the covariance matrix. Details about the covariance matrix can be obtained here. Briefly, the square root of the diagonal elements of the covariance matrix gives us the standard errors: se = Sqrt[nlm["CovarianceMatrix"]] // Diagonal (* {1.10159, 0.600123} *) ...


11

The following code simulates the Biham-Middleton-Levin traffic model for 1000 iterations using explicit rules. According to Wikipedia the blue and red cars take turns to move, which means each step is simpler than what you implemented, however. Simulating cellular automata with better performance has been dealt with here and here. (I've contributed to both.)...


11

You have to use ColorNegate and other image processing functions to make the area that you want to sample is white, while the rest is black. After that you can use ImageMesh and RandomPoint like this: img = Import["https://i.stack.imgur.com/J2JQK.png"]; mesh = ImageMesh[ColorNegate[img]]; pts = RandomPoint[mesh, 500]; Show[mesh,ListPlot[pts, PlotStyle -&...


10

As of version 10.0 there is a built in implementation of Random Forests which is accessible through the Classify function. trainingset = {1 -> "A", 2 -> "A", 3.5 -> "B", 4 -> "B"}; classifier = Classify[trainingset, Method->"RandomForest"];


10

I'm going to be bold and attempt to edit the Ross code so that it is (a) a little easier to understand and (b) takes the same form of argument as LinearModelFit and other Mathematica prediction creators. I've also added some annotations to the critical code. My variable names are now far longer than the Ross names but perhaps for informative. So far in my ...


10

My guess is to be able to have the same internal representations as for linear systems. It is not possible to represent a system using A,B,C,D state space standard matrices without the system being linear. For example, say the ODE was not linear, as in $x''(t)+x^2(t)=1$. Convert to state space. Let $x_1=x,x_2=x'$. Taking derivatives gives $x_1'(t)=x_2,x_2'=...


10

Looks like a little three-species food web model -- a perfect excuse to use my new EcoEvo package. First, install the package (one-time only): PacletInstall["https://github.com/cklausme/EcoEvo/releases/download/v1.0.1/EcoEvo-1.0.1.paclet"] Then load the package and set the model for analysis with SetModel: << EcoEvo` SetModel[{ Pop[x] -> {...


9

The answer to the more general question of how necessary "software architecturizationing" is in Mathematica is, in short: Not that necessary. The reason is basically 1) lists 2) dynamic typing and 3) lists + dynamic typing. For example, Mathematica doesn't need classes/OO because lists allow you to represent a huge swath of data structures. You would gain ...


9

Since you don't sem to have any explicit forward-looking / rational expectations elements in your system (the equation for Pie depends only on lags), I don't know why you are expressing your time subscripts as $T+2$ rather than $t$, $t-1$, $t-2$. Your system is essentially linear, so I would suggest that you define your system as a vector state variable ...


9

You may use NMinimize[] on the results of ParametricNDSolve[] like this: g = 9.81; m = 10; rho = 1.225; Cd = 0.5; A = 0.1; rcd = rho Cd A; vMax = 40; EndTime[theta_] := (2 vMax Sin[theta])/g + 5; sol[Ux_, Uy_, Uz_] := Quiet@ParametricNDSolve[{ m z''[t] == -m g - Tanh[z'[t]] 1/2 rcd (z'[t] - Uz)^2, z[0] == 0, z'[0] == v Cos[theta], m x''...


9

I have no experience with what you are trying to do so this is entirely guesswork but maybe you want something like this? cmaxd = Interpolation[dmethyl1, InterpolationOrder -> 1]; f1[t_?NumericQ] := If[0 <= t <= 72, cmaxd[t], 0] f2[t_] := Sum[f1[t - i], {i, 0, t, 12}] Plot[f2[i], {i, 0, 120}, AxesLabel -> {"hour", "concentration"}]


9

Add the option PlotRange (say PlotRange -> {{0, .006}, {0, 90}}), and use data2 as Epilog: Plot[Evaluate[F[x] /. FindFit[data2, F[x], {k, n}, x]], {x, 0, .006}, PlotRange -> {{0, .006}, {0, 90}}, Epilog -> {Red, PointSize[Large], Point@data2}] Alternatively, use Plot first in Show: Show[Plot[Evaluate[F[x] /. FindFit[data2, F[x], {k, n}, x]],...


8

I haven't thought about this for delay differential equations, but for initial value problems, you can just think of the perturbation as a new initial value problem, then the only issue is stitching together the interpolating functions with Witch. Since you mention predator-prey systems lets use logistic growth as the example: sol1 = First@With[{r = 0.5, k =...


8

Yes you can, for example: thrust[t_, t0_: 1000] := 34020.000 UnitStep[t0 - t] end = 10000 soln = Table[ NDSolve[{ x''[t] == -((G M x[t])/Norm[{x[t], y[t], z[t]}]^3), y''[t] == -((G M y[t])/Norm[{x[t], y[t], z[t]}]^3) + 0.25 thrust[t, t0]/m, z''[t] == -((G M z[t])/Norm[{x[t], y[t], z[t]}]^3) + 0.75 thrust[t, ...


8

Pure GammaDistribution does not seem at all like a good fit even visually. You need probably a MixtureDistribution. You could BTW skip NonlinearModelFit and start playing with FindDistributionParameters. But I think you are better of trying out latest WL function FindDistribution. In automated regime it finds almost what you need: dis = FindDistribution[...


8

A curve that is a multiple of a gamma distribution seems to fit: r0 = Max[data[[All, 1]]] + 0.0001; nlm = NonlinearModelFit[data, r1 E^(-((r0 - x)/r2)) r2^-r3 (r0 - x)^(-1 + r3), {{r1, 0.004}, {r2, 6}, {r3, 1}}, x] Show[ListPlot[data, PlotStyle -> {{Yellow, PointSize[0.02]}}], Plot[nlm[x], {x, 60, 90}, PlotStyle -> {{Thin, Red}}]] area = ...


Only top voted, non community-wiki answers of a minimum length are eligible