## How to Set Text Format by User-Defined Function with Input as String

I have simple but annoying problem here. I guess it occurs to many Mathematica users.

The thing is that I wish to define a function to format the text in Mathematica. Yet, I don’t know whether it is possible.

Say if I want to make a plot with FrameLabel set, like the following script:

Show[
Plot[x^2, {x, 0, 1}, PlotRange -> {{0, 1}, {0, 1}}], Frame -> True, AspectRatio -> 0.8,
FrameLabel -> {Style[ToExpression["x", TeXForm, HoldForm], 18,FontFamily -> Times, Bold],
Style[ToExpression["x^2", TeXForm, HoldForm], 18, FontFamily -> Times, Bold]},
RotateLabel -> False
]


which generate this plot

The thing is I have type this bothering format setting script again and again if I need to plot a lot, though the format I set every time is the very same.

Style[ToExpression["x^2", TeXForm, HoldForm], 18, FontFamily -> Times, Bold]}


Therefore, I am wondering if I can define a function to overpass such prolix script. For example,

SetStyle[input_] := Style[ToExpression[ToString[input, InputForm], TeXForm, HoldForm],18,FontFamily -> Times];


It works for superscript, but it fail in the most of the Latex input, like \theta or \frac{x}{2} and even just the subscript like x_0

anyone know how I can fix my code?

Thanks for your kind and generous suggestion.

## manipulate – RegionPlot Calling User-Defined Function Not Working

This is following up on this post: Function not evaluating as expected

I am trying to make a RegionPlot with Manipulate in which some user-defined function is called. It’s not working, and I don’t know why. Here is the code:

U(x__?NumericQ, p__?NumericQ) := RegionMeasure(ImplicitRegion(
(v - p - x >= 0 && 0 <= v <= 1 ) , {v}))

q(p_?NumericQ) := (x /. FindRoot(x - U(x, p) == 0, {x, 0.5, 0, 1}))

Manipulate(
RegionPlot({
(v - p - x >  0 ) /. {x -> q(p)}
}, {v, 0.000000001, 1}, {c, 0.001, 1} (*
Just to see it as a 2D RegionPlot *),
FrameLabel -> Automatic), {p, .001, 1})


Here, c is just a variable not in the model, so that I can visualize a 2D plot. I am expecting a vertical band of blue over the range of v that satisfies the inequality (so for all c, the inequality holds for that range of v). However, I get an error: Throw::sysexc: Uncaught SystemException returned to top level.

What is the issue here?

I should mention that this code here works:

Plot(x /. {x -> q(p)}, {p, 0, 1})


So it’s something about the Manipulate, RegionPlot, or interaction between the two that is causing the issue.

## dpkg – How to injecting user-defined fields in binary package control files

It’s possible to add user-defined fields in the debian/control file using the XBS- method, as defined in the Policy Manual.

Something like this before calling dpkg-buildpackage will work to inject a new field into both the Source and Binary packages. But some packages don’t contain debian/control as they generate it (kernel etc) so this not always reliable.

sed -i "0,/^s*$/s//XBS-Git-Branch:${CI_COMMIT_BRANCH}n/" debian/control
dpkg-buildpackage


It’s possible to inject the user-defined field into the generated source package using options passed to dpkg-source:

dpkg-buildpackage --source-option=-DGit-Branch=\${CI_COMMIT_BRANCH}


However that will only inject the field into the generated source package, not the generated binary packages. Is there an option to inject fields into the binary packages?

## Generate replacement rule from user-defined pattern

I want to generate a replacement rule from a user-defined pattern. For example, the user provides a list of patterns {A[i_][j_], BB[k_]} and a user-defined function F, and I hope to generate {A[i_][j_]:>F[A[i][j], B[k_]:>F[B[k]}.

I wonder how to achieve this?

## mariadb – MySQL query to select a record from each group that meets a user-defined criterion

I am looking for a query that selects a record from each group that meets a user-defined criterion. I can explain with the following illustrative table:

CREATE TABLE sample_table
(
id INT UNSIGNED AUTO_INCREMENT,
categoryID INT,
weight INT,

PRIMARY KEY(id)
);


The table is populated as follows:

INSERT INTO sample_table(categoryID, weight) VALUES(1, 3), (1, 5), (1, 2), (2, 5), (2, 3), (2, 9), (3, 5), (3, 3), (3, 3);


A simple GROUP BY categoryID query returns the first record in each group, as shown below:

SELECT * FROM sample_table GROUP BY categoryID;
+----+------------+--------+
| id | categoryID | weight |
+----+------------+--------+
|  1 |          1 |      3 |
|  4 |          2 |      5 |
|  7 |          3 |      5 |
+----+------------+--------+


To return the last record in each group we can use the approach suggested here:

SELECT * FROM sample_table WHERE id IN (SELECT MAX(id) FROM sample_table GROUP BY categoryID);
+----+------------+--------+
| id | categoryID | weight |
+----+------------+--------+
|  3 |          1 |      2 |
|  6 |          2 |      9 |
|  9 |          3 |      3 |
+----+------------+--------+


However, what I want to do is to select the record which the highest value for the weight field in each group. My output, therefore, should be:

+----+------------+--------+
| id | categoryID | weight |
+----+------------+--------+
|  2 |          1 |      5 |
|  6 |          2 |      9 |
|  7 |          3 |      3 |
+----+------------+--------+


Kindly suggest the GROUP BY categoryID query which will yield the above output.

## Whether the User-Defined Algorithm on PAI is supported in Alibaba Cloud

I am in the development of Machine learning/Deep learning applications in the PAI service of Alibaba Cloud, Now I have to create a user-defined Algorithm in the PAI of AlibabaCloud.I have to know whether the user-defined Algorithm is supported in Alibaba Cloud and if supported I which all regions it is supported

## MySQL CASE WHEN is not working as expected with user-defined variables?

i need help please with the following query. I am pulling zip codes (plz) along with user id (uid) from DB and ORDER them by zip (plz) and uid. Also I use a user-defined variable @prev to check if previous plz is different from current plz. In this CASE column rownum should decrease starting user-defined variable @row by 1.

Here is my query for this ..

SELECT
@prev as previous, @prev := u.plz as current,
CASE
WHEN @prev is null THEN @row := @row -1
WHEN @prev <> u.plz THEN @row := @row -1
ELSE @row END AS rownum,
uid

FROM
(SELECT @prev := NULL, @row := 1001) as r, user as u

LEFT JOIN
geodb_locations ON u.plz = geodb_locations.id
WHERE
u.plz IN(29386,30013,29271,30406) AND
ORDER BY
FIELD(u.plz,29386,30013,29271,30406),
uid DESC


Output

+----------+---------+--------+-------+
| previous | current | rownum | uid   |
+----------+---------+--------+-------+
| NULL     |   29386 |   1001 | 92014 | <-- @prev <> u.plz why NOT decreasing rownum
| 29386    |   29386 |   1001 | 87223 |
| 29386    |   29386 |   1001 | 83160 |
| 29386    |   29386 |   1001 | 81322 |
| 29386    |   29386 |   1001 | 81293 |
| 29386    |   29386 |   1001 |  3152 |
| 29386    |   29386 |   1001 |  1939 |
| 29386    |   30013 |   1001 | 65193 | <-- @prev <> u.plz why NOT decreasing rownum
| 30013    |   29384 |   1001 | 12883 |
| 29384    |   29385 |   1001 | 32667 |
| 29385    |   29232 |   1001 | 86641 |
| 29232    |   29481 |   1001 | 94521 |
| 29481    |   29481 |   1001 | 33950 |
| 29481    |   29481 |   1001 | 33926 |
| 29481    |   29667 |   1001 | 16027 |
| 29667    |   29667 |   1001 |   496 |
| 29667    |   29355 |   1001 | 96013 |
+----------+---------+--------+-------+


Expected output

+----------+---------+--------+-------+
| previous | current | rownum | uid   |
+----------+---------+--------+-------+
| NULL     |   29386 |   1000 | 92014 | <-- decrease @row rownum by one
| 29386    |   29386 |   1000 | 87223 |
| 29386    |   29386 |   1000 | 83160 |
| 29386    |   29386 |   1000 | 81322 |
| 29386    |   29386 |   1000 | 81293 |
| 29386    |   29386 |   1000 |  3152 |
| 29386    |   29386 |   1000 |  1939 |
| 29386    |   30013 |    999 | 65193 | <-- decrease @row rownum by one
| 30013    |   29384 |    998 | 12883 |
| 29384    |   29385 |    997 | 32667 |
| 29385    |   29232 |    996 | 86641 |
| 29232    |   29481 |    995 | 94521 |
| 29481    |   29481 |    995 | 33950 |
| 29481    |   29481 |    995 | 33926 |
| 29481    |   29667 |    994 | 16027 |
| 29667    |   29667 |    994 |   496 |
| 29667    |   29355 |    993 | 96013 |
+----------+---------+--------+-------+


Why is CASE WHEN not working like expected? Where is my mistake in thinking?

## t sql – User-defined function returns first character only although RETURN VARCHAR(10) is defined?

Everyone,

I cannot figure out what is missing in the below user-defined function:

CREATE OR ALTER FUNCTION ufn_GetSalaryLevel(@Salary money)
RETURNS VARCHAR(10)
AS
BEGIN
IF (@Salary < 30000) RETURN 'Low';
ELSE IF (@Salary <= 50000) RETURN 'Average';
ELSE RETURN 'High';
RETURN '';
END;

SELECT dbo.ufn_GetSalaryLevel(100440)


The output is including only the first character of the ‘Low’/’Average’/’High’ return values:

-----------------------------------------------------------------------
H

(1 row affected)


Why is MS SQL Server Management Studio not taking the VARCHAR(10) into account?

P.s. Please find my output below – I cannot figure out why it does not work as expected?

## design patterns – Preventing name collision between user-defined modules within a framework

I’m a contributor to a framework that’s designed for producing synthetic data. The system allows the end-user to create custom data generators and load them into the framework. Currently we store the available generators in a dictionary. We then look-up the generator by name, and return the value generated by that to the user.

There are also a few generators that come ‘out-of-the-box’ with the framework. I’ve run into a problem, however: how can I prevent the end-user from overloading a method in the framework? Given that we are using a dictionary, overloading would be done simply by calling the generator the same thing. What are some options that I could explore here to prevent this name collision?

## vba – User-defined function for estimating coefficient of performance

I am using hourly weather data to estimate performance of commercial refrigeration systems under various parameters. The formula for estimating co-efficient of performance (COP) of these systems is repeated for each hour.

I defined a formula to do this calculation:

Public Function estimatedCOP(dischargeTemp As Double, suctionTemp As Double)

Dim a As Double, b As Double, c As Double, d As Double, e As Double, f As Double

a = 9.12808037
b = 0.15059952
c = 0.00043975
d = -0.09029313
e = 0.00024061
f = -0.00099278

estimatedCOP = a + b * suctionTemp + c * suctionTemp * suctionTemp + _
d * dischargeTemp + e * dischargeTemp * dischargeTemp + _
f * suctionTemp * dischargeTemp

End Function


This gives the expected result, but takes a long time to calculate and update (as it’s repeated ~10,000 times). How can I improve the performance of this function?