Skip to main content

Posts

Showing posts from September, 2014

list manipulation - How do I split up a curve into chords of equal length?

I have a curve that is defined as f[x] and what I'm attempting to do is to divide the curve into equal straight lengths for a number of segments of my choosing that I've defined as nSeg. I've created a sheet that can work through and determine the (x,y) co-ordinates for each segment, but I'm having to manually manipulate the equations to create a single equation for Mathematica to find the roots for. The straight length of the curve I've defined as; chordL = Table[ Sqrt[(Subscript[x, i + 1] - Subscript[x,i])^2 + (f[Subscript[x, i + 1]] - f[Subscript[x, i]])^2 ], {i, 1, nSeg} ] This creates a list of equations for the length of each segment. What I would like to do is make each part of the list equal to each other so that I can feed this into FindRoot later in the sheet so that if I decide to change the number of segments from 8 to 10, the sheet can be refreshed from a single variable. FindRoot[*combined equations*,

function construction - Another difference between Set and Setdelayed. Evaluation shortcut?

A little while ago I wondered why f[x_] = f[x] gives an infinite iteration. I ended up discovering the following difference in evaluation between Set and SetDelayed with Evaluate . count = 0; ClearAll@a a /; (count++ < 20) = {a} a // OwnValues count = 0; a Output {{{{{{{{{{{{{{{{{{{{{a}}}}}}}}}}}}}}}}}}}}} {HoldPattern[a /; count++ < 20] :> {a}} {a} and count = 0; ClearAll@b b /; (count++ < 20) := Evaluate@{b} b // OwnValues count = 0; b Output {HoldPattern[b /; count++ < 20] :> {b}} {{{{{{{{{{{{{{{{{{{{b}}}}}}}}}}}}}}}}}}}} Can somebody explain the difference? Can we say that there is an evaluation shortcut at work here? Related This is a follow up question: Strange results of definitions using OwnValues Why x = x doesn't cause an infinite loop, but f[x_] := f[x] does? Does Set vs. SetDelayed have any effect after the definition was done? Answer I thought to give a bit more insight into why Update is needed, as pointed out in the other answers. Its documenta

Evaluation of notebook from chosen cell to end

There is option to evaluate the complete notebook but I wanted to know if its possible to evaluate notebook from some desired cell to end or some other desired cell following? Answer Does this work as you wish? CreatePalette@Button["Evaluate down", With[{nb = InputNotebook[]}, SelectionMove[nb, Previous, Cell]; With[{prevCell = SelectedCells[nb] /. {c_} :> c}, Function[cell, SelectionMove[cell, All, Cell]; SelectionEvaluateCreateCell@nb ]~Scan~ Intersection[ Reverse@TakeWhile[Reverse@Cells[nb], # =!= prevCell &], Cells[nb, CellStyle -> "Input"]]] ] ]

simplifying expressions - Why don't 1. (0. + a) or (0. + 1. a) simplify?

I'm handling some mixed-numeric-analytic expressions, and I feel I'm missing some subtleties of how Mathematica handles simplification of such expressions. In particular, I was initially puzzled by the fact that 0. + a (with a undefined) will not simplify to a , but of course this forgets that 0. and 0 are not the same, and that if, say, one later on sets a=1 then 0+a will return an exact result but 0.+a will return a float. However, if one takes this a bit further, to the expressions 0. + 1. a and 1. (0. + a) then they will still be returned intact. By the criterion above, simplifying them to 1. a and 0.+a would be functionally equivalent, so I feel I'm missing something. Does Plus[0.,expr] only simplify further if expr is a numeric expression? Does Mathematica decide not to delve into the depths of expr , potentially taking some overhead in complicated expressions, to save some complicated analysis? Or are the different expressions not actually equivalent? Or

databaselink - How to update bundled SQLite library (or driver?) in V10 for OS X

I've been using undocumented Database functions with Mathematica V9 to acces my SQLite database, which is a Firefox-generated database that contains cookies. db = Database`OpenDatabase[ "/Users/username/Library/Application Support/Firefox/Profiles/sjk6e588.default/cookies.sqlite"]; Database`QueryDatabase[db, "SELECT sqlite_version();"] {{"3.8.6"}} In order for this to work, I had to manually replace the outdated libsqlite3.dylib , which is located at /Applications/Mathematica9.app/SystemFiles/Kernel/Binaries/MacOSX-x86-64/libsqlite3.dylib otherwise Mathematica could not read the database. Now in V10 the undocumented Database functions no longer work, but instead there are new functions available to work with databases. The new code looks like this: Needs["DatabaseLink`"]; db = OpenSQLConnection[JDBC["SQLite", "/Users/username/Library/Application Support/Firefox/Profiles/sjk6e588.default/cookies.sqlite"]]; SQLExecute[

string manipulation - Convert recursive RegularExpression to StringExpression?

Consider the following expression for matching balanced brackets: StringPosition["[[hello][[hi]][hey]ahoy][]", RegularExpression@"(?P<0>\\[([^\\[\\]]|(?P>0))*\\])"] {{1, 24}, {2, 8}, {9, 14}, {10, 13}, {15, 19}, {25, 26}} It uses features for recursive pattern matching. This answer by WReach explains the general structure using similar example. This comment by Leonid Shifrin states that recursive StringExpression is possible but its performance is worse than StringExpression 's. And this question by Mr.Wizard shows that StringExpression can perform faster than RegularExpression . So I'm eagerly interested if it's possible to build recursive StringExpressions , and if true, then how? What have I tried: bb := "[" ~~ (Except@{"[", "]"} | bb) ... ~~ "]"; StringPosition["[[hello][[hi]][hey]ahoy][]", bb] $RecursionLimit::reclim: Recursion depth of 1024 exceeded. >> Ok, that was wrong, I thin

memory - Plotting large datasets

I have a lot of data (e.g., 64x8192), to plot and it consumes too much memory (more than 2 GB) causing Mathematica to return "no memory available". For example, lst = Table[Sin[x^2 + y^2], {x, 2^7}, {y, 2^13}]; ListDensityPlot[lst] Is there any way to cope with it? Answer Scroll to the end for the latest edit. If you really want all the points in a large data set, I'd use a more basic display method: Let's say the matrix of data is m , then do this (assuming the entries m[[i, j]] are real numbers): Image[Rescale[m]] This will make one pixel for each data point without trying to do any interpolation as is the default in density plots. Edit As suggested in the comment, here is a comparison of the timings: (* A test matrix with random entries between 0 and 1: *) m = RandomReal[1, {300, 300}]; Timing@Image[m] Timing@ListDensityPlot[m, MaxPlotPoints -> 1000] So the ListDensityPlot is several orders of magnitude slower than my Image suggestion. This conclusion seems

plotting - Why does evaluating an integral within a Plot expression take so long?

I want to evaluate Plot[Integrate[Sin[((1 + 1/2) x)] (1/(2 Sin[(x/2)]) - 1/x), {x, 0, t}], {t, 0, 5}] but it takes ages to load on Corei3 computer with Mathematica 9. I'm still a novice when it comes to using Mathematica . Is there a way to get this expression to be evaluated faster? (I'm not used to waiting more than a minute while computing, that's why it feels odd to me). Answer Oska nailed it in the comments before me The trick here is to evaluate the integral only once. In your code it is being evaluated once for every point. You can evaluate the following Integrate[Sin[((1 + 1/2) x)] (1/(2 Sin[(x/2)]) - 1/x), {x, 0, t}] The outcome of this is ConditionalExpression[1/2 (t + 2 Sin[t] - 2 SinIntegral[(3 t)/2]), t \[Element] Reals] You know that t will always be a real number (at least in your plot), so you can just copy paste the first argument of this ConditionalExpression and make a function out of it. func[t_] := 1/2 (t + 2 Sin[t] - 2 SinIntegral[(3 t)/2]) We ca

performance tuning - Fast way to export large amount of data in "Table" format

I have about a million 3D points, say data = Table[{1. x, 1. y, 0.}, {x, 1000}, {y, 10^3}]~Flatten~1; I want to visualize them, but Graphics3D@Point@data or ListPointPlot3D@data are too slow. MeshLab or CloudCompare can do it, but I need to export it in some way to get it there. It can read ".txt" files with the "Table" format that Mathematica produces, but that takes a very long time to write: AbsoluteTiming@Export["test 1mio points.txt", data, "Table"] {23.9979, "test 1mio points.txt"} CSV file writing is not much faster. It doesn't look like there is a general bottleneck in converting numbers to text format, as '.m' is written quite quickly: AbsoluteTiming@Export["test 1mio points.m", data] {1.92666, "test 1mio points.m"} but MeshLab cannot handle it. Any alternatives? Is there a way I can convert a list of points to a GraphicsComplex or Mesh or so and then export that in some format (that might be

Building a sparse array from given lists

Given some lists lstRow1 = {{"C1", "C2", "C3"}, {1, 2, 3}}; lstRow2 = {{"C2", "D1", "D2"}, {4, 5, 6}}; lstRow3 = {{"C1", "D2", "D3"}, {7, 8, 9}}; lstRow4 = {{}, {}}; lstRow5 = {{"D1", "D2", "E1"}, {10, 11, 12}}; lstRow6 = {{}, {}}; lstHead = {{"C1", "H1"}, {"C2", "H1"}, {"C3", "H1"}, {"D1", "H2"}, {"D2", "H2"}, {"D3", "H2"}, {"E1", "H3"}}; how to build a sparse arrary like this: lstSparse = { {"H1", "0", "0", "H2", "0", "0", "H3"}, {"C1", "C2", "C3", "D1", "D2", "D3", "E1"}, {1, 2, 3, 0, 0, 0, 0}, {0, 4, 0, 5, 6, 0, 0}, {7, 0, 0, 0, 8, 9, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0,

functions - How do I override options with my own defaults?

I'm calling a function f from within a function g and would like to pass any valid options for f to g , replacing some (say, optA and optB ) with defaults different from those defined for f . What is the right way to do this? I can get things to (seemingly) work with Options[g] = Join[FilterRules[Options[f], Except[optA | optB]], {optA -> 0, optB -> 0}]; g[x, opts : OptionsPattern[]] := f[x, opts, OptA -> OptionValue[OptA], optB -> OptionValue[optB]] but this looks pretty verbose to me. Is there a better, more idiomatic, way? Answer Here is what I do in such cases ([ edit from 01/10/2020 - apparently, this technique has been exposed on this site earlier, at least partially, in this nice answer by Mr.Wizard - which I definitely read but must have forgotten at the time of posting my answer ]) : ClearAll[g, f]; Options[f] = {optA -> 1, optB -> 1, optC -> 1}; f[x_, opts : OptionsPattern[]] := {OptionValue[optA], OptionValue[optB], OptionValue[optC]} O

modeling - Modelling the effect of a structure on a "tsunami" (hyperbolic wave equation)

So, the hyperbolic wave equation can be quite easily solved in Mathematica like this: L = 5; TMax = 10; tsunamiEqn = u /. NDSolve[{ D[u[t, x, y], t, t] == D[u[t, x, y], x, x] + D[u[t, x, y], y, y], u[0, x, y] == 0.15/E^(x^2 + y^2), Derivative[1, 0, 0][u][0, x, y] == 0, u[t, -L, y] == u[t, L, y], u[t, x, -L] == u[t, x, L]}, u, {t, 0, TMax}, {x, -L, L}, {y, -L, L}][[1]]; One can then plot it or Manipulate it via the following snippet: Manipulate[ Plot3D[ tsunamiEqn[fac TMax, x, y], {x, -L, L}, {y, -L, L}, PlotRange -> {{-L, L}, {-L, L}, {-0.1, 0.2}}, Mesh -> 10, PlotStyle -> {LightBlue, Specularity[White, 50]} ], {fac, 0, 0.9} ] Now my question is : How do I include a structure inside this "pond". I would like to see what happens when the wave interacts with a square block or so. I am drawing a blank right now as to how I would want to include that: A boundary condition? (would seem a little complex) Here are a few s

system - Mathematica 11 with High DPI 4k screen

My laptop has a 17 inch 4k screen, running Windows 10 and Ubuntu 1604. Both systems are set to 2x scaling. But Mathematica 11 (released 2016-08-08) is still blurry like version 10. Is there a simple fix to this problem? Answer The best thing to do, IME, is to set the default notebook zoom level to something higher. This way, the text is rendered crisply and at a reasonable size. You can do that as follows: Go to Preferences -> Advanced -> Open Option Inspector Set Show option values to Global Preferences Go to Notebook Options Go to Display Options Change magnification to whatever works for you. Now, "100%" (default mag) will be rendered at whatever magnification you chose here.

calculus and analysis - 3N-dimensional integral

I'm trying to compute a multidimensional integral with a variable number of dimensions. The integral is as follows: $$ \int d^{3N}\!p~e^{-\frac{\beta}{2m}\vec p^2}. $$ I have tried this Integrate[e^(-a*{p1,p2,p3}^2),{{p1,p2,p3}^N,-Infinity,Infinity}] but it's not working at all. I guess I have to determine the vector before, or? More generally, to what extent can Mathematica compute such integrals for arbitrary $N$ and arbitrary integrands in place of $e^{-\frac{\beta}{2m}\vec p^2}$?

Possible to draw an Item in a Grid with only 3 sides of a Frame?

I'm trying to draw a Grid of characters where some of the characters have Frame lines on 3 sides. For example: + + x | x | x +---+ x x x x x x That's something like a Grid[item = Table[x,{3},{3}]] , except with item[[1,2]] = Item[x,FrameStyle->{{White,Black},{Black,Black}}] , except that produces a complete box around the x for me. When the documentation says: FrameStyle->{{left,right},{bottom,top}} specifies that different sides of a graphics frame should be drawn with different styles. I fear that the "...of a graphics frame..." part means that this will work for a Plot , but not for a Grid . Is there a way to style a frame such that I only draw three edges of it? It doesn't have to be pretty--I'm planning on generating the Grid from some data that I have lying around. Answer How about this? Grid[{{1, 2, 3}, {4, Item[5, Frame -> {{True, True}, {True, False}}], 6}}]

files and directories - How to get the directory of a package?

I have a package that I have placed in the $BaseDirectory\Applications directory so that Needs can find it. I have a logo in the directory that I will return when a function is called. However, when I call NotebookDirectory in the package I get the directory of the notebook (this seems like expected behavior). I've not been able to find a corresponding PackageDirectory function. How do I get the directory of a package so I can load a resource (in this case a .jpg logo) to return to the calling notebook? Update to show package and $InputFileName returns empty string Update to show proper use of $InputFileName in package The package saved as an .m file in $BaseDirectory \Applications is: BeginPackage["MyTest`"]; packageDirectory::usage="Gets the directory of the this package."; packageLogo::usage="Gets the logo of this package."; testfoo::usage="does this work" Begin["`Private`"]; (* $Input only has a value as the package is bei

plotting - How to not include data value outside plot range in the plot

Consider this list plot ls = Table[Sin[t], {t, 0, 100, 0.1}]; p = ListPlot[ls, PlotRange -> {{0., 0.1}, All}, DataRange -> {0, 1}, Joined -> True] If we look at the data in the plot, we see that all the data in ls are included in the plot. ls2 = p[[1, 2, 1, 3, 3, 1]]; Dimensions[ls2] (* {1001, 2} *) ListPlot[ls2, Joined -> True] Sometimes this is really helpful because we can just retrieve the data at a later time from the plots and don't need to regenerate the data again. But sometimes I'm only interested in the range set in the ListPlot , and saving all the data is kindly of wasting of space, especially when I have many plots in a notebook, the notebook size becomes very large and not very responsive. So are there simple ways to tell ListPlot to not include the data outside the plot range, other than manually select the data before plot? P.S. Sometimes, ListPlot does drop the data outside the range, see example here . Answer I think @rasher's comment is c

curated data - Building graph based on the cities connection?

I built a Graph based on the permutations of city's connections from : largUSCities = Select[CityData[{All, "USA"}], CityData[#, "Population"] > 600000 &]; uScityCoords = CityData[#, "Coordinates"] & /@ largUSCities; Graph[#[[1]] -> #[[2]] & /@ Permutations[largUSCities, {2}] , VertexCoordinates -> Reverse[uScityCoords, 2], VertexStyle -> Red, Prolog -> {LightBrown, CountryData["USA", "FullPolygon"]},ImageSize -> 650] It looks like this: My question, is there any way to have the Graph like this? Answer Revised answer This uses the connectivity between states to create the graph, and uses the coordinates of the center of each state rather than the cities. I couldn't find a way to get these easily from Mathematica or from WolframAlpha (I'm no Harry Potter, and failed to discover the correct incantation for the latter). But I found a table somewhere: stateConnections = {{"NV", "

printing - How to print without having newline added automatically at the end?

Print["first part of the result", DateString[]] Print["addition to the result", DateString[]] will add a newline character at the end of line automatically for each Print[] . But I'd like the two strings to be shown on the same line. How can I do this? Answer For Example: WriteString["stdout", "First part of the result: ", DateString[]]; (*Perform some calc*) i = 0; WriteString["stdout", " -- Addition to the result: ", DateString[], "\n"]; First part of the result: Thu 15 Oct 2015 12:58:29 -- Addition to the result: Thu 15 Oct 2015 12:58:29

matrix - How can I compute a Kronecker sum in Mathematica?

There is Kronecker product but there is no Kronecker sum? It seems like a very important features to include. So in the absence of a Kronecker sum function, how can I construct my own Kronecker sum $A\oplus B$ of two arbitrary $n\times n$ matrices $A$ and $B$? Thanks very much! Answer Using the Wikipedia definition of Kronecker sum , it seems that we can define it in terms of the Kronecker products, which is built in: Clear[kroneckersum] kroneckersum[a_, b_ /; Dimensions[a] == Dimensions[b]] := KroneckerProduct[a, IdentityMatrix[Length[a]]] + KroneckerProduct[IdentityMatrix[Length[b]], b] a = RandomInteger[{0, 10}, {5, 5}] b = RandomInteger[{0, 10}, {5, 5}] kroneckersum[a, b] An alternative implementation that has the significant advantage of retaining the use of SparseArrays for large matrices was proposed by Henrik in comments : kroneckersum[a_?SquareMatrixQ, b_?SquareMatrixQ] := KroneckerProduct[a, IdentityMatrix[Length[b], SparseArray]] + KroneckerProduct[IdentityMatrix[L

programming - When should I use Apply (or Function) and when @@ (or &)?

This is a rather general question, which I fail to answer myself. I guess it is mainly due to my insufficient knowledge of the precise terms. If I understand correctly, the following are equivalent: f = Function[u, 3 + u] f = Function[3 + #] f = (3+#) & f[x_]:=3+x In all cases f[a] would yield 3+a . Similarly, f[a] is equivalent to f@@{a} . I have mainly two questions: What is the right term to call the shorter version, i.e. the version where one uses @@ , # , & etc.? When should I prefer the one method and not the other? It seems like many answers given around MA.SE uses the "shorter version". What are the advantages and disadvantages... Bonus question: Note my first question. I hope I could get more fishing rods and less fish. In other words, what is the official term for these two notions? Where are can I find documentation of these differences? The examples I presented in the this questions are merely examples, and I try to understand where can I rigorously st

plotting - Show does not combine the plots

i've the following problem: because it's not possible to plot complex numbers (or is it?) i created my own "function": complexPlot[cn_] := Plot[0, {x, -100, 100}, PlotRange -> {-500, 500}, AspectRatio -> 1, AxesLabel -> {Re, I }, Epilog -> {Background -> None, PointSize[0.03], Point[{{Re[cn[[1]]], Im[cn[[1]]]}, {Re[cn[[2]]], Im[cn[[2]]]}, {Re[cn[[3]]], Im[cn[[3]]]}}]} ] with complexPlot, I can plot my complex Numbers, but i want to have one graphic for all my number pairs. myPlots = Table[ complexPlot[linPolesAll[[n]]], {n, 1, 16}] Show[myPlots] Does not work, it overlays all Plots with the last one (tried it with Show[myPlots[[1]],myPlots[[10]]]) any ideas? Thanks!

image processing - Extract timestamp of specific frames in video

I would like to do the following : I have a set of slides and a video in which those slides are discussed. Now I would like to extract the timestamp when the slide appears in the video. I would suggest to proceed in the following way: Import the video Import[] (How can I import a mp4.file ?) Import the slides as images For all frames in the video, I define the following function: I compare a certain amount of pixels of the frame to all the slides images. When a certain percentage of pixels are the same, I return the slide image and the corresponding timestamp . My questions: How can I extract all timestamps for a video frames ? How can I extract the values of pixels within a certain geometric region of the frame. In my video, a person might stand in fron of the slides, therefor I cannot simply say that I detect a slide in the video, if all pixels of the frame and the slide are the same. Thanks. Here is some material to try: Instead of a video, one can use a gif: One can try to extract

syntax - HoldForm[Operator ##] on some list

Recently in response to this question Mr.Wizard suggested an unusual way to summing numbers. This doesn't seem to be documented. HoldForm[+##] & @@ RandomInteger[100, 2] This works fine for Plus and in case of - it generates -ive of product of list elements. I could not find out how to write a close variation of this for Divide or Subtract or other operations. Can someone please shed some light on this ? Answer From prior comments I know that you are interested in forms such as: a - b - c - d a / b / c / d There is no simple short form for these as there is for Plus . To understand this you must understand how Mathematica parses and displays these expressions. Let's look at the first one: Subtract HoldForm[a - b - c - d] a - b - c - d No surprises. But now FullForm : HoldForm @ FullForm[a - b - c - d] Plus[a, Times[-1, b], Times[-1, c], Times[-1, d]] So our simple expression is not quite so simple in the internal format. Each negative term is actually represented a

plotting - How to assign special colors to the output of DensityPlot?

I have created the following function for plotting plotDynamical[iterMethod_, points_] := DensityPlot[ iterAlgorithm[iterMethod], {t, xxMin, xxMax}, {s, yyMin,yyMax}, PlotRange -> {1,4}, ColorFunction -> {Orange, Blue, Black, Green}, PlotPoints -> points] The possible results of " iterAlgorithm[iterMethod] " are 1 , 2, 3 or 4. I would like to assigning colours to numbers like so: Orange to 1,Blue to 2,Black to 3 and Green to 4. How can I do this? complete my Algorithm is: F = Compile[{{t, _Real}, {s, _Real}}, {t^2 + s^2 - 4, -Exp[t] + s - 1}]; dF = Compile[{{t, _Real}, {s, _Real}}, {{2 t, 2 s}, {-E^t, 1}}]; invdF = Compile[{{t, _Real}, {s, _Real}}, {{1/( 2 E^t s + 2 t), -((2 s)/(2 E^t s + 2 t))}, {E^t/( 2 E^t s + 2 t), (2 t)/(2 E^t s + 2 t)}}]; rootF[1] = {-1.59832066552612835, 1.202235854627582} ; rootF[2] = {0, 2} ; rootPosition = Compile[{{t, _Real}, {s, _Real}}, Which[Norm[{t, s} - rootF[1]] < 10.0^(-10), 3, Norm[{t, s} - rootF[2]]

functions - Strange ::usage behavior in v9

Bug fixed in 9.0.1 Something has gone wrong with usage in Mathematica 9. Would someone tell me how to fix it? I define a function pR with a usage such that there is a line break (see below) pR::usage = "pR[s,m0,m1] is a function that looks like pR(s,m0,m1)=s+m0+m1."; pR[s_, m0_, m1_] := s + m0 + m1 And then, I subsequently call the defined function the next cell (without running it), pR[a,b,c] Then, when I move with the cursor somewhere within the arguments of the pR function, and move it left and right with the arrow keys, I get a bunch of StringMatchQ::strese errors which makes no sense to me. But if I remove the line-break, pR::usage = "pR[s,m0,m1] is a function that looks like pR(s,m0,m1)=s+m0+m1."; pR[s_, m0_, m1_] := s + m0 + m1 and try calling the function and placing my I-beam in the argument, I don't get these strange errors. Can anyone help? Answer Unformatting the usage message cell and changing \n\n to \n\\[IndentingNewLine] will cure i

charts - Display asterisk as it enter in Mathematica v11

In Mathematica v11, entering an asterisk from keyboard would be displayed as a 'times' operator, ie, it is not placed at top right corner of a text (as in Mathematica v9). I notice [Star] and [RawStar] display the same in v11 notebook. I understand SuperStar[text] would do the trick, but is there a way to display asterisk (super star) as it enters from keyboard? Try this in v9 and v11 and you will see the difference. BarChart[{1, 2, 3}, ChartLabels -> {"a*", "b\[RawStar]", "c\[Star]"}] Answer This was not at all easy to figure out. First, I do not see any difference between version 9, 10 and 11 on OS X. But I do see a difference between a Text cell and an Output cell: If you experiment for long enough, you will notice that the difference between the two * characters is not in their position but their font. In certain contexts, Mathematica simply substitutes a different fonts for certain operators, such as * or % . After a lot of digging in

mathematical optimization - Is there any strategy to have a compiled version of FindFit or NonlinearModelFit?

Disclaimer: This is not a precise question with a definite answer. I know that neither FindFit nor NonlinearModelFit is in the list returned by the command: Compile`CompilerFunctions[] // Sort But I am in the middle of refactoring a large Wolfram Language code base which uses FindFit in many places. I need to write compiled versions of each of these functions, so that I may generate C code out of it, which will be built into a DLL and included in our one-step build process for our overall web application. Since FindFit and NonlinearModelFit do not compile, I would like to come up with a substitute strategy. Short of trying to reimplement these functions, is there any way to generate the replacement rules returned by FindFit , or the function generated by NonlinearModelFit so that the code using these functions can be compiled? Answer No, it is not possible. With code converted to a LibraryLink library by way of Compile you are limited to using functions that either can be ex

plotting - Plot3D with inequality restrictions

I am struggling to visualize the following function by using Plot3D A = (2.29 - 2.6 s - 2 s^2 + 2.2 s^3 + c (-1 + s) (-1.3 + 1.1 s^2))/(4.58 - 5.2 s - 4 s^2 + 4.4 s^3) with the following restrictions: -0.665954 < s < 0.826905 && ((-1.1 + s^2) (-0.01 + 2 (-1 + s)^2 (1 + s) + 0.1 (3 - 6 s + 2 s^3)))/(0.01 (7 + s - s^2 (3 + s)) + (-1 + s^2)^2 (-7 + s (-1 + 4 s)) + 0.1 (1 + s) (-8 + s (16 + s (9 + s (2 + s) (-9 + 4 s))))) < c <= -(((-1 + s) (-0.01 + 2 (-1 + s)^2 (1 + s) + 0.1 (3 - 6 s + 2 s^3)))/(-0.02 + (-1 + s)^2 (1 + s) (3 + s) + 0.1 (3 + s (-6 + s (-2 + s (2 + s)))))) I am aware that the restrictions are quite complicated, so I am not sure whether it is possible to plot it at all. I've tried to plot it using RegionFunction, similar to this thread Plotting above desired region , which does not work give me any result. It was possible to create a plot using the second answer in this thread Alternative 2 , but with the given restrictions c cannot b