Exiting CrossSlidingDiscontinuity in NDSolve to follow equilibrium curve

I am trying to figure out how to get the solution curve to an NDSolve to slide along once it reaches a boundary and then to exit the CrossSlidingDiscontinuity once it reaches an equilbrium curve and follow the equilibrium curve back within a set boundary.

If the x[t] solution curve reaches the boundary edge on this interval [0,1] I needed it to slide along this boundary, hence I used CrossSlidingDiscontinuity. However once, the solution reaches the yellow equilibrium sine curve, I need it to exit the sliding discontinuity and follow the equilibrium curve. I tried using EventLocator (in the code below). It manages to fall back within [0,1] but does not follow the equilibrium sine curve. I attached the image of the plot below.

I also tried using two WhenEvents (one for when x[t] reaches 1 triggering the sliding and one where x[t] reaches the sine curve triggering to follow the sine curve) but only the sliding WhenEvent was triggered.

Here is my code:

normalDE2[x_, t_] := -(x + 1/2)*(x - 1/2)*(x - (1 + .1*Sin[t]));  testDE3[x_?NumberQ, t_] :=  If[0 < x < 1, normalDE2[x, t], -1*normalDE2[x, t]];  sol4 = NDSolve[{x'[t] == testDE3[x[t], t], x[0] == .75,  WhenEvent[{x[t] == 1, x[t] == 0},  {Print[t],"CrossSlidingDiscontinuity"}]},  x, {t, 0, 10}, Method -> {"EventLocator", "Event" -> {x[t] - (1 +.1*Sin[t])}, "EventAction" :> {{x[t] -> (1 + .1*Sin[t])}}}];  Plot[{x[t] /. sol4, (1 + .1*Sin[t])}, {t, 0, 10},  Frame -> True, GridLines -> Automatic]  

Plot ImagePlot Image

why ODE Fitting is not producing a flattened curve?

I have fitted parameter of an ODE with experimental data. Though the fit is very good in the start (up to {10, 0.004048}) but then it does not flatten as the experimental data does. Could you please suggest if I need to do anything to get a better fit.

sddata = {{0, 0.017622}, {1, 0.016368}, {2, 0.014476}, {3, 0.012254}, {4, 0.008536}, {5, 0.006996}, {10, 0.004048}, {20, 0.003454}, {40, 0.003432}, {60, 0.003234}}; eqns = {sd'[t] == -k1 sd[t]}; aa[t_] = DSolveValue[{eqns, sd[0] == 0.017622}, {sd[t]}, t] model[k1_] := Sum[(aa[sddata[[i, 1]]] - sddata[[i, 2]])^2, {i, Length@sddata}] NMinimize[model[k1], {k1}] 

enter image description here

How can I get Graph edge labels to parallel an edge line or or follow an edge curve?

Edge labels are always rendered horizontally. I would like the label for any straight line edge to be rotated so the bottom of the label’s bounding box is coincident with the edge.

There was an older post (Comfortable Edge Labeling of Undirected Graph) that did this using EdgeRenderingFunction, but that has been superseded by EdgeShapeFunction in v12. EdgeShapeFunction does not have access to the label like EdgeRenderingFunction did.

Labels following a curved edge would be a bonus, but just paralleling a tangent somewhere on the edge would suffice.

how to plot this curve against the original function?

Clear["Global`*"]  pts = {{1, 0}, {2, -1 + 2/E}, {3, -1 + 3/E^2}, {4, -1 + 4/E^3}};  p[x_] = a (x^3) + b (x^2) + c (x) + d;  print["p[x]=", p[x]];  eq1 = p[1] == 0;  eq2 = p[2] == -1 + 2/E;  eq3 = p[3] == -1 + 3/E^2;  eq4 = p[4] == -1 + 4/E^3;  eqns = {eq1, eq2, eq3, eq4};  vars = {a, b, c, d};  solset = Solve[eqns, vars];  Print[TableForm[eqns]];  Print["Solve and get"];  Print[solset];  p[x];  ReplaceAll[p[x],solset[[1]]]; (*Note this is solset subscript [[1]] but I didnt know how to write it onto here*)  p3[x_]=ReplaceAll[p[x],solset[[1]]];(*Note this is solset subscript [[1]] but I didnt know how to write it onto here, it is also p subscript 3*)  Needs["Graphics`Colors`"];  dots = ListPlot[pts, PlotStyle -> {Red,  PointSize[0.02]},    DisplayFunction -> Identity] gr = Plot[[p3][x], {x, 1.0, 10.0}, PlotStyle -> Blue, DisplayFunction -> Identity]; (Note it is also p subscript 3)  graph1 = Show[gr, dots, PlotRange -> {{0, 10}, {-10, 3}},    Ticks -> {Range[0, 3, 1], Range[0, 3, 1]},    DisplayFunction -> $  DisplayFunction] 

I am getting an error and the need function as well as there being an issue with posting my curve against the original functions curve. For now, I do see the curve plotted using the show function above but when I try to add the function before the beziur curve, it messes up.

Using Marching Squares to connect curve ends in adjoining squares

I’m learning Marching squares for a graphic program I’m working on and, while I understand how to connect points along an edge of a single square depending on the vertex values, I am unclear about how to connect two curves belonging to adjoining squares.

The part I’m trying to understand is this:

Marching square image

Say I’m linearly interpolating along edge (a, b) of Square X and there is a zero crossing somewhere after the midpoint c – let the zero crossing be at 0.75 along edge ab. This is point f.
To get rid of the ambiguity, I divide square Y into four squares – Y1 through Y4. Now say while I interpolate along the smaller edge ca, I encounter a zero crossing before the midpoint of ca – let the zero crossing be at 0.25 of edge ca. This is point g.

  1. How should I resolve the vertex values (0 or 1) of the squares?
  2. How can I connect the two curve ends (in green)?

Ubuntu has extra hidden gamma curve? (weird stuff…)

As soon as i loaded my test image i noticed the gradient was no longer smooth but it contained some vertical artifacts. I should point out that the gamma is set to default in Ubuntu: xgamma gamma 1.0

I also have Windblows 10 and OSX and there the gradient is smooth. However in Ubuntu it is brighter and contains vertical artifacts. And each time i take a screenshot, test image becomes brighter. This is driving me crazy.

So here is a test image: https://i.imgur.com/TflxhEi.png

When i open it on Win and OSX it is smooth and contains proper black. Here is a screenshot from Win10: https://i.imgur.com/uInvTgS.png

Here is a screenshot from Ubuntu (notice vertical artifact, less blacks, make sure to zoom in): https://i.imgur.com/9ZVoxnN.png

Here is a screenshot of a screenshot: https://i.imgur.com/avmdSmK.png

Here is a screenshot of a screenshot of a screenshot: https://i.imgur.com/kC8EF8a.png

The test image in the last example has become stupidly bright indicating there is another layer of gamma control present in the display settings that is just hidden from access.

Please keep in mind before you mention i should change gamma, this is all happening at gamma 1.0.